Adding a feed
Published on June 15, 2025
More under the hood tweaks.
This time, I’ve added an RSS feed.
I had to install eleventy-plugin-rss and then tweak a new layout, feed.njk.
There was a lot of back-and-forth trying to get everything to work together.
First, it’s important that there is not a single space or line befor ethe start of the XML content in the feed layout—any items that breaks this renders the feed invalid, apparently.
I wanted to provide the top few lines of my feed.njk, but the Eleventy interpreter doesn’t seem to respect the “code” function and tries to interpret it instead.
If you need it, I’ll figure out a way to publish it, perhaps on github.
I also had to create some custom filters in my .eleventy.js configuration in order to get the output where I wanted it.
One of these was a head
filter to extract the proper number of items to create the feed:
/* --- head filter: first N items --- */
eleventyConfig.addFilter("head", (array, n = 10) => {
if (!Array.isArray(array)) return [];
if (n < 0) return array.slice(n); // allow negative index (“last N”)
return array.slice(0, n);
});
Ten items is the default but you can pass a different number. Inside the fancy curly bracket stuff, it looks like this:
set items = collections.notes | reverse | head(25)
I also needed an excerpt
filter to avoid escaped text:
const excerpt = (html, length = 280) => {
// strip tags, decode entities
const txt = html.replace(/<[^>]+>/g, '')
.replace(/&[#0-9a-z]+;/gi, ' ')
.trim();
return txt.length > length ? txt.slice(0, length) + '…' : txt;
};
eleventyConfig.addFilter("excerpt", excerpt);
This prevented my feed from publishing content like this:
<description>
https://perpetualbeta.com/%3Cp%3EI%20can%E2%80%99t%20even%20remember%20what%20started%20it.
%3C/p%3E%3Cp%3EThis%20site%20was%20decomposing,%20slowly%20at%20first,%20then%20rapidly.
%20%20The%20software%20driving%20the%20site%E2%80%94WordPress,
%20for%20something%20more%20than%20a%20decade%E2%80%94automatically%20updated%20past%20
the%20non-automatic%20and%20largely%20ignored%20update%20demands%20of%20...
</description>
Instead, it now renders like this:
<description>
I can’t even remember what started it. This site was decomposing, slowly at first,
then rapidly. The software driving the site—WordPress, for something more than a
decade—automatically updated past the non-automatic and largely ignored update
demands of its dependencies. What version of PHP does it require? What version
of MySQL? Some number far higher than was here. The old blog posts, the old ar...
</description>
After all that, I had to tweak the content portion of the feed.njk for everything to function properly. Again, can’t post the code here but maybe elsehere.
Next step: adding an automated sitemap.