Jekyll Atom Feed

Reading time:
2 minutes

I read a twitter post today about the lack of rss feeds on blogs. Then I realized this one was missing it too. Google is your friend and pretty fast I found an example. When I tried to throw it at the W3C feed validation service it gave some errors. Guess what? They mixed rss and atom code together. Those are two different specifications and you can’t make up your own. Well, actually you can, but then you should use a different xml namespace.

For this to work you need to update your default template e.g. /_layouts/default.html and add the line listed below.

<!doctype html>
<html lang="en">
    <!-- Other head stuff here -->
    <link rel="alternate" type="application/atom+xml" title="News Feed" href="{{ site.url }}/site/feed.xml" />
    <!-- Content -->

Place the feed.xml file somewhere in your path. Mine is located in /sites/feed.xml. If you place it somewhere else make sure you change the line you just added to default.html accordingly as well as line 9 in feed.xml.

layout: none
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="" xml:lang="en-US">
    <title>{{ | xml_escape }}</title>
    <subtitle type="text">{{ site.description | xml_escape }}</subtitle>
    <updated>{{ site.time | date_to_xmlschema }}</updated>
    <link type="application/atom+xml" href="{{ site.url | uri_escape }}/site/feed.xml" rel="self" />
    <link type="text/html" href="{{ site.url | uri_escape }}" rel="alternate"/>
    <id>{{ site.url | uri_escape }}/</id>
    <generator uri="">Jekyll</generator>
    <rights>Copyright (c) {{ site.time | date: "%Y" }} Geert Eltink. All Rights Reserved.</rights>
    {% for post in site.posts limit:10 %}
        <title type="html"><![CDATA[{{ post.title }}]]></title>
        <link href="{{ site.url | uri_escape }}{{ post.url | uri_escape }}" />
        <id>{{ site.url | uri_escape }}{{ post.url | uri_escape }}</id>
        <published>{{ | date_to_xmlschema }}</published>
        <updated>{{ | date_to_xmlschema }}</updated>
            <name>Geert Eltink</name>
            <uri>{{ site.url | uri_escape }}</uri>
        <summary type="html"><![CDATA[{{ post.summary }}]]></summary>
    {% endfor %}

And here you have the result: