Serving RSS (Atom) and JSON Feeds
I now serve Atom and JSON feeds, a simple feature that I took too long to provide, here's how I did it.
published this page on
What took me so long to do this?
Serving an RSS feed for my website was in my TO-DO list for far too long, I was just waiting for the right push.
I always thought that nobody reads my blog posts.
About a month ago, I received 3 XMPP messages and an E-mail asking me for a feed to subscribe to, maybe they are the only people reading my blogs, who knows? Not me!
Anyway, I decided to add an Atom feed first instead of RSS, may be the name ticked me off a bit. Looking at the way I structured the project, it looked simple enough, so I managed to do it within an hour with just a few lines. Optimizing the logic, fixing bugs, and adding small features to it took a bit longer, so I did those over a few weeks whenever I got some spare time.
I now feel that it is good enough to be official, I now serve Feeds! I also have a special page to show you different feeds you can add to your feed reader.
How did I generate a Feed?
The way you generate the feed depends on how you host your website and serve it, do you just have some HTML files bundled in some folder that's being served? You probably have to do it manually or write a script to copy the contents to the feed file, this might also be the simplest approach one could take compared to what I did.
To serve a feed, I need to know what a feed requires. For a list of blogs, we will need:
date. I also took
last modified date, a
content of the blog.
In my project, all this information except the actual content is stored in a small JSON file, which I might move to an SQLite DB soon. The content is rendered to the page using the rust implementation of handlebars and rocket (a rust framework to build websites).
It was a bit tricky to figure out how to get the content to render as properly in the browser, but I after a lot of debugging, I found that I had it right the first time. The problem was a Firefox bug that caused the content to not render as HTML when I style it using an XSL file.
But it is not the end of the world, the feed still contains the complete content, it's just that I don't show it to you if you access the XML from a browser. A feed reader will be able to get the complete content without issues, you can also do a curl and see it for yourself
curl -s https://codingotaku.com/blogs/atom.xml | less
The next issue was the banner, I did not have a banner for all the blogs, and only a couple of projects have them. So I created a default banner which helps me add a banner image for every feed item but I only have it for the JSON feed at the moment.
Making the JSON feed was much easier as I already prepared everything for the atom feed, I just had to create a proper structure for it and bam! The JSON feed is ready to be consumed.