Skip to content

Instantly share code, notes, and snippets.

@alexandru
Last active April 30, 2022 20:11
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexandru/ccabd60d52ad53027a7deb2ef01f5137 to your computer and use it in GitHub Desktop.
Save alexandru/ccabd60d52ad53027a7deb2ef01f5137 to your computer and use it in GitHub Desktop.

How to add a Web Feed (RSS/Atom) to your Jekyll website

If you're generating your website with Jekyll or another static website generator, don't forget to also expose a web feed for us old timer using RSS readers. The format we'll be preferring here is Atom.

Some reasons to expose a web feed:

  1. people using RSS readers regularly are pretty loyal, RSS/Atom subscribers being like a mailing list for some of us
  2. tooling knows RSS/Atom — e.g. the easiest way to build a mailing list is to give Mailchimp your RSS feed

If you're looking for a recommendation on online RSS readers, I personally like Newsblur.

Automated via plugins

You can usually find a plugin that takes care of everything for you, with a little configuration, like this one:

jekyll-feed

Manual

Generating an atom.xml file is super easy. Something like this:

---
layout: null
---

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 <id>{{ site.url }}</id>
 <title>{{ site.title }}</title>

 <link type="application/atom+xml" href="{{ site.url }}/atom.xml" rel="self"/>
 <link type="text/html" href="{{ site.url }}" rel="alternate"/>

 <updated>{{ site.time | date_to_xmlschema }}</updated>
 <author>
   <name>{{ site.author.name }}</name>
   <email>{{ site.author.email }}</email>
   <url>{{ site.author.url }}</url>
 </author>

 {% for post in site.posts %}
 <entry>
   <title>{{ post.title }}</title>
   <link href="{{ site.url }}{{ post.url }}"/>
   <updated>{{ post.date | date_to_xmlschema }}</updated>
   <id>{{ site.url }}{{ post.id }}</id>
   

   <author>
     <name>{{ site.author.name }}</name>
     <uri>{{ site.author.url }}</uri>
   </author>

   <rights type="text">
     Copyright {{ site.time | date: '%y' }} {{ site.author.name }}.
     Some rights reserved (CC BY-NC 3.0)
     License: http://creativecommons.org/licenses/by-nc/3.0/
   </rights>   
   
   {% for category in post.categories %}
   <category><![CDATA[{{ category }}]]></category>
   {% endfor %}
   
   <content type="html"><![CDATA[
   {{ post.excerpt }}
   <p><a rel="full-article" href="{{ site.url }}{{ post.url }}?utm_source=RSS_Feed&utm_medium=RSS&utm_campaign=RSS_Syndication">
     <b>Read This Article &raquo;</b>
   </a></p>
   ]]></content>
 </entry>
 {% endfor %}
</feed>

Then don't forget to add this meta-tag in the <head> of every HTML page, for discovery:

<head>
  <!-- ... -->
  <link rel="alternate" href="/atom.xml" title="Atom feed" type="application/atom+xml">
</head>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment