
RSS reimplemented
Bootstrap Studio has a new blog feature, but no native implementation for RSS. How I learned to use the standard and how PowerShell saves the day.
Two confessions
Admittedly, I have never dealt with RSS before. For me, it was always a side effect of the Internet in the early 2000s to 2010s, when you could still place these gadgets on the desktop in Windows 7. There was a small RSS reader that you could feed with addresses. Most recently, I discovered RSS at work so that I could receive the latest and most important news directly in Outlook. However, the importance of RSS for me has faded again.
The second confession? I can't do frontend. To build my sites, I use Bootstrap Studio, a WYSIWYG builder similar to Jimdo or Wix. For me, it's a quick way to build prototypes, polish them and then deliver them quickly without having to pay for hosting. The software itself costs something, but I get the license from the GitHub Student Developer Pack.
Bootstrap Studio (I'll call it BSS from now on) has recently released a new feature: the blog implementer. For the first time, this makes the export kinda dynamic. Elements are now automatically filled with content during export without me having to worry about it. A really cool feature without backend shenanigans. And yet the inclined reader may say: “Yes, nice, but does it generate a RSS feed?” Which brings me to today's blog post. Unfortunately, the nice developers from Bulgaria don't have an implementation for it yet. Understandably, they want to focus on the important things and make BSS better instead of serving niche products. Is RSS a niche product? I'm not going to discuss that today.
A masterplan
So I sat down in front of w3schools.com and gave myself the full dose of RSS. The format is actually relatively simple. An RSS feed is basically an XML file. In the image below, I have generously taken the example from my colleagues at W3S. A channel element initially comprises a title and a link to the general page. This is followed by a description that summarizes the channel in general. This is followed by the item elements. Each item stands for an article, which again consists of a title, a link and a description.
Now this construct is to be generated automatically. In this case, PowerShell is my weapon of choice. I'm not particularly good at PowerShell, but it's a native way to achieve my goal. BSS allows you to run a script on an export. So far, I've only used it to push the changes to a private Git repo so that Cloudflare Pages can build a static page from it.
So I just have to add a new line that calls another script. The reader will also notice that a script is already being executed. BSS overwrites files during an export, but does not delete those that are no longer present in an export. I therefore check for all files that are older than 20 seconds after the export. Everything that is found in that check gets deleted. The rest is almost self-explanatory: I fetch the active branch once and push the changes. Everything else is done by a GitHub action from Cloudflare.
Me and you and PS1 (two??)
The plan: Go through the folders after the export, read out information with regular expressions, build an XML and ship the fun into the Git repo. I solved this with this script.
Looks like a lot, doesn't it? It's actually not as bad as you might think. First, I define the channels with their properties. This allows me to adapt the script without much effort if additional sub-blogs or the like are added. Then nested loops lead us to success. I get all the files from each folder and the attributes from each file with regular expressions. I then write them into objects and move them generously into a list. Furthermore, I then build the items for a channel from these lists and use them to build the channel itself. Everything is packed into an XML and then placed in the folder of the actual blog.
However, this script has two problems that I don't know how to solve (yet). On the one hand, articles are always published punctually at midnight! Unfortunately, BSS does not provide an exact time. But that doesn't really matter, does it? The second issue is that BSS allows you to publish blog pages but not yet display them in the so-called loop. The loop is the overview of articles that can be seen on the main page (/blog-en.html). However, this switch is only read during export in order to create the loop and is not saved as a separate data point. This means that RSS readers could get articles earlier. A workaround would be to first move these articles to another folder that is not scanned. On the other hand, you could also parse the loop itself, but I'll save that for another time.
Intermezzo: A weird standard
I had to learn the RSS standard in order to implement it. The channel element particularly caught my eye. I generously assumed that you can define several channels in a feed. Nope! You can't! Then why does the element exist at all? It doesn't occur to you that there can only be one of them. And now that I've finished, I read something about Atom. Admittedly a bit more complex, but maybe I'll add the Atom standard to the script (and include the loop parser). But I'm not making any promises.
Looking forward
This is my second and yet last blog post of the year 2024 (weird to write that while translating it mid January 2025). I'm looking forward to sharing more experiences and projects. After all, Mastodon is not the right place for the long-form content I'm sometimes in the mood for. Look forward to more technical stuff and a bit more furry stuff, 'kay?
Happy New Year, fellas
Finnley
Many thanks to Steffo for proofreading and for all the suggestions for improvement.