Back to the homepage

A human-readable RSS feed with Jekyll

Screenshot of my RSS XML feed page formatted to be readable in a browser

I refactored my RSS feed using Jekyll functionalities, applying XSLT for presentation to render a human-readable XML feed.

Skills

Objectives

I recently stumbled on an article,1 where two things caught my eye: styled OPML blogrolls that can be directly imported into an RSS reader, and styled RSS feeds. I had forgotten about XSLT with its potential applications, so the above examples inspired me. Also, I wasn't aware that OPML, which I’ve been using for years to import and export RSS feeds, could be styled. This prompted me to refactor my RSS feed, and give a human readable format to it, consistent with the website.

Approach

I created a loop that could exploit the layout type rather than the content type, because I tend to add and remove collections to my site, and this is a more flexible solution. The loop iterates 20 times (my configuration value for posts_limit) through the resulting variable.

{% assign blog = site.documents | where:"layout", "post" | sort: 'date' | reverse %}
{% for post in blog limit:site.posts_limit %}
  <item>
    [code here]
  </item>
{% endfor %}

Then, I created an XSL file to style the feed page into a human readable format. Since I was rewriting the RSS feed from scratch, I added a few features:

Before

RSS feed before refactor

After

RSS feed after refactor

Results

It was surprisingly easy, and I wonder why didn't I do it sooner. Since my main motivation for leaving WordPress was to take full control over my code, I should have managed the feed myself rather than relying on a Jekyll plug-in. The source code for the RSS XML feed and the XLS file are available on Github.

View it in action →

Footnotes