RSS Feed

I added an RSS feed to the blog and this is how I did it.

This website is of a completely static Web 1.0 design, mostly cobbled together with make and shell scripts. Everything is stored in a Git repository. The website is updated with “make” and deployed with “git push”. I would say, guiding principles have been KISS and YAGNI. It’s very UNIXy as far as my understanding goes.

Writing a post consists of creating a Markdown file and an associated meta data file. The meta data file defines some shell script variables that are used to build the front page and the topic index files. There’s also support for writing documents in Emacs Org mode. Such an Org file also has an associated meta data file with the same structure. So index generation (and RSS file generation) is agnostic to the source documentation format.

It was immediately apparent to me that RSS generation would be based on the meta data files, just as the existing index file generation. The RSS format is pretty simple, but I was not sure the RSS file could easily be generated with shell scripts. I soon threw in the towel on keeping the website pure to its roots and wrote a RSS generator in the Go programming language.

The first problem I faced was how to parse the meta data files from a Go program. I was not eager to put a lot of time into this. The meta data files have a simple format and I could have written a parser myself, but technically they are shell scripts. I soon found a Go shell parser package that could be used to read the meta data variables. It really is preposterous to run shell scripts only to access these variable. However, this is a one man show, so there are no real security or safety issues here.

Example meta data file:

title="RSS Feed"
description="I added an [RSS](https://en.wikipedia.org/wiki/RSS) feed to the blog and this is how I did it."
topics="Documentation Programming"
lang=en
css_class="column ch-sep"
published="2024-06-09"
revised=""

The description field was added for the RSS item description. I opted to define it as Markdown, and render it using a Go markdown package. This way, longer RSS descriptions could be formatted with paragraphs and titles and such.

Apart from the per document meta data files, there’s also a site data file that defines some website parameters. In this case I opted to communicate these parameters via environment variables. A wrapper shell script simply source the site.bash file and then executes the RSS generator program described herein. Remember, the major theme here is that existing data is in a shell script centric format and the RSS generator needs to fit into that world.

Example site data file:

site_link="https://bitmaster.se"
site_title="Bitmaster(se)"
site_description="Hobbies and ramblings of mine"
site_lang=en
site_webmaster=""

All other needed functionality such as encoding XML files, sorting RSS items is provided by the Go standard library. The RSS generator source code can be found in bitmaster-rss-feed-src.tar.gz. Albeit hacky, it could perhaps provide a useful starting point for someone wanting to do something similar.

The RSS feed is available at https://bitmaster.se/rss.xml.


Published: 2024-06-09