Samir Parikh / Blog


Originally published on 01 December 2019

Background

When I first created this web site, my main focus was on just getting a primitive infrastructure up and running and publishing the occasional post. I wasn't sure how long I'd be able to keep something like it up as I've started a few blogs in the past that never lived beyond a few months. I was also fairly certain that my readership would be zero to negligible.1 Therefore, providing an RSS feed was never a high priority. And besides, since most of this blog is hand-assembled, I didn't have an easy or automated way to provide readers with a feed.2

Instead of creating an RSS feed, I've been trying to post updates to both my Mastodon account and to the Telegram group for this site anytime I post an entry -- kind of like a poor man's RSS. But again, this doesn't really promote readership or make it easier to access as:

So after reading Kev Quirk's post "Please Add RSS Support To Your Site", I started doing a little research on how I might add one to mine. Initially, I was kind of put off with the amount of work I thought it would require so I only got as far as bookmarking some sites I had found that I thought it would be useful. A few days ago, after publishing a post on shopping for electronics on the internet, I got a response to my toot publicizing the post from Mastodon user srinicame asking whether I could add an RSS feed to my site. When I responded that I would like to but didn't know how to, Chris Were helpfully chimed back with a hand-crafted version of a feed for one of his sites. After taking a closer look at what Chris had provided, I thought that I might be able to cobble something together after all.

Pulling together an RSS feed, which is really nothing more than an XML file, turned out to be much easier than I was expecting. That's mainly because XML is a fairly human readable format which makes it easier to construct than say coding a C program. The structure itself is fairly simple, almost like an hierarchical outline.

Getting Started

I'm going to walk through the steps to define a simple RSS feed for my site but which can be customized for virtually any static blog such as this one. I would highly recommend keeping the w3schools RSS tutorial open in another browser tab as it served as a really good reference for me. To begin, start by defining the high level control statements for the RSS feed:

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
</rss>

These statements define the RSS feed as an XML version 1.0 file encoded using UTF-8. It also specifies that we are using version 2.0 of the RSS format.3

Next, we add the <channel> tags for the RSS feed. There is one set of <channel> elements per file which describe RSS feed:

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
  <channel>
  </channel>
</rss>

Within the <channel> tags, we can specify the title of the feed, or blog site, as well as provide a link to the site's home page and a brief description of the overall site. We do this via the <title>, <link>, and <description> elements respectively.

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
  <channel>
    <title>Samir Parikh</title>
    <link>https://samirparikh.com</link>
    <description>Internet Home of Samir Parikh</description>
  </channel>
</rss>

At this point, and at periodic intervals as we further define our RSS feed, it's a good idea to run our feed syntax through the W3C Feed Validation Service to ensure everything checks out. Because we haven't yet hosted our XML file anywhere, we can just copy and paste our code directly into the direct input text box to validate our syntax. Upon doing so, we should receive a congratulatory message indicating that we have submitted a valid RSS feed.4

Now we can finally begin inserting the entries that correspond to our individual blog posts. These are specified via the <item> element:

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
  <channel>
    <title>Samir Parikh</title>
    <link>https://samirparikh.com</link>
    <description>Internet Home of Samir Parikh</description>
    <item>
    </item>
  </channel>
</rss>

While the RSS Version 2.0 specification only requires either a <title> or a <description> tag, we will use both, as well as the <link> tag:

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
  <channel>
    <title>Samir Parikh</title>
    <link>https://samirparikh.com</link>
    <description>Internet Home of Samir Parikh</description>
    <item>
      <title>Shopping on the Internet (for Electronics) is Hard</title>
      <link>https://samirparikh.com/blog/shopping-on-the-internet-is-hard.html</link>
      <description>In a discovery that will be news to no one, shopping for trivial electronic items on the internet can be surprisingly difficult...</description>
    </item>
  </channel>
</rss>

We can then add additional <item> entries for each post we publish by just adding it to the RSS XML file:

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
  <channel>
    <title>Samir Parikh</title>
    <link>https://samirparikh.com</link>
    <description>Internet Home of Samir Parikh</description>
    <item>
      <title>Shopping on the Internet (for Electronics) is Hard</title>
      <link>https://samirparikh.com/blog/shopping-on-the-internet-is-hard.html</link>
      <description>In a discovery that will be news to no one, shopping for trivial electronic items on the internet can be surprisingly difficult...</description>
    </item>
    <item>
      <title>What I Look for in a Hotel Room</title>
      <link>https://samirparikh.com/blog/hotels.html</link>
      <description>On my last trip, I started to reflect on what I really need in a hotel while I'm traveling for business. I was surprised that I could only come up with four things which to me are nonnegotiable...</description>
    </item>
    <item>
      <title>dlang Regex</title>
      <link>https://samirparikh.com/blog/dlang-regex.html</link>
      <description>Using Regular Expressions in dlang to solve Advent of Code problems...</description>
    </item>
  </channel>
</rss>

As stated above, it's a good idea to periodically check your RSS syntax against the Feed Validation Service, especially if you've made substantive changes. Running the above feed syntax should result in a valid syntax verification with a few recommended changes provided as well. At this point, you should have a fully functioning feed which you can name something like rss.xml or feed.xml and then publish on your server. For example, mine is located at https://samirparikh.com/blog/rss.xml.

If you look closely at the actual RSS feed I put together for my own site, I've included some additional elements under both the <channel> and <item> tags that, in theory, should help feed readers process my entries a bit more efficiently. Because I just established an RSS feed a few days ago, the jury is still out but these are some tips I picked up in my research.

<channel> Elements

<item> Elements


  1. As it probably still is!

  2. There are a few services out there that claim to create a feed for sites that do not provide one but in my experience, they never worked reliably for me.

  3. Web syndication technology, like many other aspects of modern computing, has a really rich but also convoluted history. While out of scope for the purposes of this article, I encourage you to spend a few minutes perusing both the Wikipedia page on the history of RSS as well as the Mozilla Developer Network's page on the evolution of the various versions of the RSS format. At several points in RSS's history, there were multiple versions of the format available at the same time. And that does not even include the introduction of Atom Syndication Format!

  4. If you submitted an RSS feed similar to the example given above, the Feed Validation Service may have also recommended that you provide a self reference to your feed URL. The Feed Validator Documentation page gives instructions on how to do this.