Alexander Zeitler

Multiple feeds with 11ty

Published on Tuesday, November 19, 2024

You can create multiple feeds using 11ty.

For example, if you want to split Posts and TILs (Today I Learned).

Create a new collection til in .eleventy.js:

eleventyConfig.addCollection("til", function(collectionApi) {
  return collectionApi.getFilteredByTag("til");
});

Create a new til.njk template for the feed.

---json
{
  "permalink": "til.xml",
  "eleventyExcludeFromCollections": true,
  "metadata": {
    "title": "Alexander Zeitler | TIL",
    "url": "https://alexanderzeitler.com/",
    "feedUrl": "https://alexanderzeitler.com/til.xml",
    "author": {
      "name": "Alexander Zeitler",
      "email": "alexander.zeitler@pdmlab.com"
    }
  }
}
---
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>{{ metadata.title }}</title>
  <subtitle>{{ metadata.subtitle }}</subtitle>
  <link href="{{ metadata.feedUrl }}" rel="self"/>
  <link href="{{ metadata.url }}"/>
  <updated>{{ collections.til | rssLastUpdatedDate }}</updated>
  <id>{{ metadata.url }}</id>
  <author>
    <name>{{ metadata.author.name }}</name>
    <email>{{ metadata.author.email }}</email>
  </author>
  {%- for post in collections.til %}
  {% set absolutePostUrl %}{{ post.url | url | absoluteUrl(metadata.url) }}{% endset %}
  <entry>
    <title>{{ post.data.title }}</title>
    <link href="{{ absolutePostUrl }}"/>
    <updated>{{ post.date | rssDate }}</updated>
    <id>{{ absolutePostUrl }}</id>
    <content type="html">{{ post.templateContent | htmlToAbsoluteUrls(absolutePostUrl) }}</content>
  </entry>
  {%- endfor %}
</feed>

Tag your posts with til:

---
title: 'Multiple feeds with 11ty'
date: 2024-11-19T12:00:00
layout: default
tags: til
---
What are your thoughts about
"Multiple feeds with 11ty"?
Drop me a line - I'm looking forward to your feedback!
Please be aware that I'm no longer active on social media. I'm just cross posting things over there (it's a bot).
Imprint | Privacy