Adding An RSS Feed to a Jekyll Site
Adding an RSS 2.0 feed to a Jekyll site is actually pretty simple.
First the required header and footer:
Don’t forget to add a name, url and description to your configuration file.
We’ve got our XML boilerplate and then in the channel
we need to add a title
, a link
and a description
. The channel
elements also has a few optional elements, which I haven’t included here.
The next step is to add the item
’s. We iterate over the 20 latest posts and add them. Each item
has a title
, a link
a guid
(globally unique identifier), a pupDate
and a description
. The guid
can be any string, here I just set it to the link of the post. isPermaLink="true"
tells feed readers that they can assume the guid
is a permalink.
Actually non of these are required, it’s the most minimal approach that makes sense in my opinion. To quote the spec:
An item may also be complete in itself, if so, the description contains the text (entity-encoded HTML is allowed), and the link and title may be omitted. All elements of an item are optional, however at least one of title or description must be present.
We use the date_to_rfc822
and xml_escape
filters Jekyll adds to Liquid to comply with the specification.
After we add the YAML front-matter, so Liquid will process our file, the end result looks like this:
See the RSS 2.0 specification for all of the details and optional elements and validate your feed when you’re done. Using the method above should produce a valid feed without warnings.