Going Static Part 2
Information Flaneur 2023-05-21
Summary:
For the second in my series on migrating this blog to Eleventy, I'm going to take you through creating my RSS feed, and what I learned about RSS and Atom. Regular readers will know I'm a big fan of RSS, but I must admit I didn't really understand how it works until I decided to write my own RSS file. RSS is both both simpler and weirder than I realised. Eleventy actually has an RSS plugin, but I decided to roll my own. This was partially because I would have had to fiddle with some code anyway, since the plugin is written in the Liquid templating language instead of Handlebars, but mostly because I wanted to actually understand how an RSS file is constructed and how it works. This post outlines some of the things I learned, but the usual caveat applies: I'm not an expert, and I've probably got some things wrong. If there are any serious mistakes, feel free to let me know on Mastodon or Twitter.
A (very) brief history
The first thing we need to get out of the way is that the term 'RSS' is often used to refer to all the various flavours of RSS and the Atom Protocol which was an attempt to modernise and replace RSS. Confusing things more, at one point there was effectively a fork in the development of RSS, with competing groups releasing different interpretations of RSS with, in one case, competing version numbering. I'm going to write a bit about Atom, but primarily this post is about the RSS protocol.
RSS developed in a fairly free-form way compared to most more recent web protocols. It was originally created at Netscape in 1999, bringing together ideas that had been floating around for a few years, but referring to no broader standards body. Ultimately this looseness is what led to the creation of Atom, but RSS 2.0 is still in very widespread use. Being a librarian, I'm persuaded by the argument that Atom is the better choice - with clear rules, every element properly explained, full namespacing, and adherence to other standards - but I ended up using RSS 2.0 for my feed. The reason for this was simple: my existing feed from when I was using Ghost is RSS 2.0 and used a permalink of /rss, so I wanted to ensure I didn't break anything currently using my feed.
But what exactly is RSS?
The key to understanding the nature of RSS (or Atom for that matter) is to understand that the acronym 'RSS' has stood for three different things over time, and you need to know all of them to get the full picture. Originally it was referred to as RDF Site Summary. The creators of version 0.91 called it Rich Site Summary. Most people, however, know the third term1 - Really Simple Syndication. If you understand that it is all of these things at the same time, then you can understand how RSS works. An RSS file is, essentially, just a summary of a website. It summarises the site using XML and the Resource Description Framework, enabling a rich ecosystem of independent software applications to parse each RSS file in a standardised way. And by providing the site summary in RDF via an XML file at a permanent URI, web content that is updated frequently can be syndicated. This last one is the thing that confused me for a while. 'Syndication' suggests that the content is pushed out somehow, but that's not how RSS works. An RSS file is simply a static XML document stored at a permanent address. The way RSS feeds are 'syndicated' is that applications periodically send a request to the file's URL, and check to see if it has changed in a particular way since it was last checked.
Writing an RSS feed
As I noted above, an RSS feed is simply an XML file. The RSS 2.0 specification outlines the requirements:
- conforms to the XML 1.0 specification
- has a top-level
rsselement specifying aversionof 2.0 - has a single
channelelement with compulsory sub-elements oftitle,linkanddescription - within the channel element has one or more
itemelements - within each
itemelement there must be at least one oftitleordescription
And that's it. A very simple RSS file might look like this:
<rss version="2.0">
<channel>
<title>