---
title: "Adding per-tag Atom feeds to Middleman"
description: "Learn how to generate Atom/XML feeds based on tags by using Middleman."
canonical: https://oozou.com/blog/adding-per-tag-atom-feeds-to-middleman-17
locale: en
date: 2014-12-12
author: "OOZOU Team"
---

# Adding per-tag Atom feeds to Middleman

> Learn how to generate Atom/XML feeds based on tags by using Middleman.

Published: 2014-12-12 · Author: OOZOU Team (Engineering) · 2 min read

Today we decided to add per-tag feeds to our blog. [Middleman](http://middlemanapp.com/) proved to be flexible enough to make this pretty easy.

When we set out, we had two main questions:

1. How to access the tags in config.rb, given that new posts can just arbitrarily add new ones?
2. How to generate the file for each category?

It took us a bit to find the answer to the first question, but it turns out that the ready callback which is run after the rest of config.rb is exactly what we needed:

```
ready do
  blog.tags.each do |tag, posts|
    proxy "/tags/#{tag}/feed.xml",
          "/tag.xml",
          locals: { tag: tag, posts: posts },
          ignore: true,
          layout: false
  end
end
lang-ruby
```

The second point was much easier to solve: We’re using Middleman’s [dynamic_pages](http://middlemanapp.com/basics/dynamic-pages/) to proxy the request to an Atom template (tag.xml.builder), passing in each tag and its associated posts as locals. The ignore: true option makes sure that Middleman won’t try to build the template itself.

Here’s the builder in all its glory:

```
xml.instruct!
xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
  site_url = "http://blog.oozou.com/"
  xml.title "The Oozou Blog — #{tag.capitalize}"
  xml.subtitle "We handcraft beautiful Web and Mobile apps"
  xml.id URI.join(site_url, tag_path(tag))
  xml.link "href" => URI.join(site_url, tag_path(tag))
  xml.link "href" => URI.join(site_url, current_page.path), "rel" => "self"
  xml.updated(blog.articles.first.date.to_time.iso8601) unless blog.articles.empty?
  xml.author { xml.name "Oozou" }

  posts.first(10).each do |article|
    xml.entry do
      xml.title article.title
      xml.link "rel" => "alternate", "href" => URI.join(site_url, article.url)
      xml.id URI.join(site_url, article.url)
      xml.published article.date.to_time.iso8601
      xml.updated File.mtime(article.source_file).iso8601
      xml.author article.data.author
      xml.avatar article.data.avatar
      xml.content article.body, "type" => "html"
    end
  end
end
lang-ruby
```

---

Contact OOZOU: hello@oozou.com · +66 2544 0000 · https://oozou.com/contact

More for AI agents: https://oozou.com/llms.txt · every page has a markdown twin at its URL plus ".md"
