DEV Community

Conor Meagher
Conor Meagher

Posted on • Originally published at on

RSS Feed in a 11ty site

RSS Logo

Dave Rupert is right. Really Simple Syndication or RSS is a great way for people to digest their favorite blog articles with a RSS reader of their choice not be bombarded with ads, click-bait, and spam. So why not do your readers a favor and add it to your 11ty blog?

Install package #

Start in your 11ty project folder and install this package.

npm install @11ty/eleventy-plugin-rss --save-dev
Enter fullscreen mode Exit fullscreen mode

Include in your 11ty configuration #

In the .eleventy.js file, require the plugin and include it in the module.exports function with any other plugins you may have.

const pluginRss = require("@11ty/eleventy-plugin-rss");
  module.exports = function(eleventyConfig) { eleventyConfig.addPlugin(pluginRss);
Enter fullscreen mode Exit fullscreen mode

Add to feed metadata #

In the _data/metadata.json file, add the unique metadata for the feed.

  "feed": {
     "subtitle": "Tech posts to educate, elevate, but mostly entertain.",
     "filename": "feed.xml",
     "path": "/feed/feed.xml", 
     "url": "",
     "id": ""
Enter fullscreen mode Exit fullscreen mode

Create a RSS feed #

From your top-level of your 11ty project folder, create this template file.

touch src/feed.xml
Enter fullscreen mode Exit fullscreen mode

Atom has several advantages over RSS: less restrictive licensing, IANA-registered MIME type, XML namespace, URI support, RELAX NG support. [1] Knowing this, we will copy and paste the Atom format to produce our feed template. Other formats are available such as RSS and JSON. [2]

# Metadata comes from _data/metadata.jsonpermalink: "{{ metadata.feed.path }}"eleventyExcludeFromCollections: true
<?xml version="1.0" encoding="utf-8"?><feed xmlns="">
<title>{{ metadata.title }}</title>
<subtitle>{{ metadata.feed.subtitle }}</subtitle>
<link href="{{ metadata.feed.url }}" rel="self"/> <link href="{{ metadata.url }}"/>
<updated>{{ collections.posts | getNewestCollectionItemDate | dateToRfc3339 }}</updated>
<id>{{ metadata.url }}</id>
  <name>{{ }}</name>
  <email>{{ }}</email>
{%- for post in collections.posts | reverse %}
{% set absolutePostUrl %}{{ post.url | url | absoluteUrl(metadata.url) }}{% endset %}
  <title>{{ }}</title>
  <link href="{{ absolutePostUrl }}"/>
  <updated>{{ | dateToRfc3339 }}</updated>
  <id>{{ absolutePostUrl }}</id>
  <content type="html">{{ post.templateContent | htmlToAbsoluteUrls(absolutePostUrl) }}</content>
{%- endfor %}
Enter fullscreen mode Exit fullscreen mode

Important: This code assumes you save your date frontmatter in UTC format, not your local timezone.

date: 2022-01-01T00:00:00Z
Enter fullscreen mode Exit fullscreen mode

That's it. You now have a Atom v1.0 feed on your 11ty website when you serve or build the project.

Check out mine and subscribe!

  1. "RSS compared with Atom". Retrieved June 14, 2022 ↩︎

  2. "Sample Feed Templates". Retrieved July 12, 2022 ↩︎

Top comments (0)