Add an RSS feed to your Middleman blog

← back   //   Published April 16th, 2025
Table of Contents

You’re probably trying to add an RSS feed to your Middleman website. Unfortunately, Middleman doesn’t ship with an RSS feed, nor are there any all-in-one gems to easily add one.

However! Middleman does integrate with the builder gem, which renders XML data using Ruby code. We can use the builder gem to render a feed.xml file for us by specifying a feed.xml.builder file. This is similar to specifying a sitemap.xml file using a sitemap.xml.builder file, just with different syntax.

I’ve packaged up the feed.xml.builder file below with a bunch of other features and released it as a Middleman & Tailwind CSS Starter Blog Template which you might like.

You can view it live here — middleman blog template (live) — and the sitemap here, middleman template sitemap.

Below is a working RSS feed builder I’m using in my Middleman blogs (including this one!).

RSS Feed builder for your Middleman site

Here’s the feed.xml.builder file I use to generate my RSS feed. Below it is a short explanation, but if you copy the code below into your Middleman app at source/feed.xml.builder, it should work automatically.

# source/feed.xml.builder
#
site_url   = config.site_url
title      = "[insert title]"
desc       = "[insert description]"

# All posts in reverse‑chronological order
posts = blog.articles.sort_by(&:date).reverse

xml.instruct! :xml, version: '1.0', encoding: 'utf-8'
xml.rss version: "2.0", "xmlns:atom" => "http://www.w3.org/2005/Atom" do
 xml.channel do
 xml.title title
 xml.link site_url
 xml.description desc
 xml.language    'en-us'
 xml.lastBuildDate(posts.first.date.to_time.rfc2822) if posts.any?
 xml.tag!("atom:link", href: "#{site_url}/feed.xml", rel: "self", type: "application/rss+xml")

 posts.each do |post|
 xml.item do
 xml.guid        "#{site_url}#{post.url}"
 xml.link        "#{site_url}#{post.url}"
 xml.title post.data.title
 xml.pubDate post.date.to_time.rfc2822
 xml.description post.data.description
      end
    end
  end
end

This RSS feed is fully compliant and passed the W3C RSS Feed validator. Just copy it into your Middleman app, add your site title and description, and you should be golden.

To break down how it works:

  • We first grab all the blog posts and store them in posts. If you have multiple blogs, you should specify the blog name like blog("name").articles....
  • Next, we set up all the metadata for the RSS feed — information on your website, its URL etc. We use xml.tag! to insert a raw tag for atom:link which is needed for compliance with the RSS spec.
  • Finally, we add each blog post to the RSS feed and include a bit of information about them. This setup assumes each of your blog posts has title, description, and date available in its frontmatter.

Conclusion

Thanks for reading!

I hope this helped you add an RSS feed to your Middleman site. Since you’re interested in Middleman, you might like my Middleman blog template. It comes with an RSS feed already set up, alongside Tailwind CSS, code highlighting and more.