Adding RSS
What's the first thing you do after writing a blog? Adding an RSS feed of course.
Well, maybe that's not as obvious as I make it out to be. But I truly believe RSS is a wonderful idea, I've written about that in the past. And I got a helpful nudge from a friend.
So in the end I set off on a mission — to add a feed to this site, by hand of course.
RSS or Atom?
If, like me, you start diving into the world of figuring out the relevant specs, you'll quickly come across the fact that there are actually two competing ways you can add a feed to your website that someone can subscribe to. RSS and Atom.
Which do you choose? On one hand, I like Atom better, it's clearly intended to address specific shortcomings of RSS in a way that I prefer. On the other, RSS seems to have a more mature body of documentation.
Though both enjoy relatively widespread adoption, I get the sense that of the two, the more likely to be dropped one day would be Atom. So I set out to stick with RSS.
Well Write an RSS Feed Then
Decision made, now all that's left is writing the feed. Easy peasy. Ish.
RSS feeds are XML documents. Though largely dunked on in the Software Developer community today, I don't have any particular dislike for XML. I mean, I am literally sitting here writing out HTML tag for tag. XML is about the same really.
The first part is simple, you start the document with the appropriate doctype header, open a <rss> tag, and fill in the body (See also: Draw a circle, draw the rest of the owl).
The body is composed of two things (Well they're really one thing, you'll see). A <channel> element, containing metadata about your “channel” (A concept presumably born out of the idea that RSS would be used for news services). And nested inside of it, an arbitrary number of <item>'s each describing a... well... item? in your channel.
To get a bit more concrete in this case, each post on my blog.
The RSS Specification is surprisingly good at spelling out what you need to fill in.
The Two Wrinkles
It's a bit of a norm these days, that you might want the “item” to contain the full text of a blog post, especially if it's fairly short. The spec sets you up by default to send out descriptions, with the presumed intent that the reader then clicks through to your site for the full story.
I wanted to offer full text though, easy right? You just paste the full post into the <description> and off you go!
Not quite. You see, my HTML markup contains tags that aren't valid in RSS. I imagine this is because RSS predates HTML5, which added a number of the tags I use.
But there is a way. XML offers a way to annotate the embedded HTML as text, so that it isn't parsed as part of the actual XML of the feed. With that in place, we can paste the full text of my webpage into the RSS item description, rendering the full post in an RSS reader without having to click through to my site.
The second wrinkle? It's considered good practice for the feed document to point to itself, so that anyone who happens to have a copy of the document, can load the authoritative source. RSS doesn't have a built-in mechanism to do this. So they recommend you use Atom for that part. I just thought that was cute.
If you're curious, you can check out the full document at feed.xml.