anderegg.ca

On Template-Based Feed Generation

May 24, 2024

A couple of days ago, I was demoralized by a minor Jekyll issue. I was thinking about generating a single Atom feed from two content types. Turns out the plugin provided by GitHub Pages can’t do this directly.

When I was looking into this, I saw someone mentioning that they made their own feed template. This rubbed me the wrong way. I do a lot of systems integrations, and have encountered a huge amount of malformed XML in my career. I prefer to use a well-tested XML library when generating or consuming XML content so as to avoid these issues.

I ranted about this to a friend and he asked me how I felt about templated HTML documents. I write a lot of HTML by hand, and hadn’t considered the similarities. Web browsers are robust and built to try their best with even the most poorly formed markup. XML is expected to be well formed and many libraries will stop parsing at the first sign of a validation error.

But my mind flipped a bit because of this comparison. For one thing, even though there are a lot of ways to mess up HTML markup with templates, I can protect against most of them if I’m careful. In fact, I can validate my markup to confirm that I’m not doing something obviously stupid. RSS/Atom feeds are XML documents, but they’re also web documents that regularly get a bit mangled. Feed readers may not be as robust as web browsers, but they are good at dealing with the most common errors. Plus, I can also validate my feed’s XML to ensure it’s OK.

As I was writing the first post, I discovered that the feed generator I use has always been template-based. Since then, I also looked into generators for Hugo and 11ty. Turns out they’re both also template based! Here’s the first-party Hugo feed generation template, and here’s the one for 11ty. Neither allow combining of separate content feeds by default, and the advice is the same as with Jekyll: modify the feed template to query for the content you want.

While I was looking into this I also realized that I don’t need a separate “Links” type. I should just post stuff and stop over thinking things. I keep arriving at this decision, then end up waffling about a “correct” way to post. I will keep tweaking the site, but I want the changes to be incremental. I definitely don’t want to replatform the site while I’m this close to the end of May.