Creating Multiple Feeds with the 11ty RSS Plugin


Creating a feed using the 11ty RSS plugin is pretty straightforward and doesn’t require much configuration. Less obvious to me was how to create a second feed for a filtered subset of my data. In this case I wanted to create a feed of only posts tagged with ‘Drupal’ that can be submitted to Planet Drupal.

Since the plugin required so little configuration, it wasn’t clear to me if there was a way to make the plugin aware of a second feed template. As it turns out, the plugin is smart enough to pick up on any number of feed templates, located anywhere in your codebase. I created a /src/_feeds directory that contained by default feeds.njk template and my new Drupal-specific drupal.njk template. As long as you add a unique permalink in this template’s json frontmatter, the plugin will generate a new feed for you. In this case I used:

  "permalink": "drupal.xml",

Next was determining how to filter my 11ty collection based on a specific tag. This quick tip on creating tag pages gave me what I needed. Instead of iterating through collections.all as I did in my default feed, I added the following tag filter:

{`%- for post in collections[ 'drupal' ] | reverse %`}

As a result, I had only my content tagged with Drupal. The resulting drupal.njk feed template looked like this:

Now all I have to do is write some Drupal related posts…