OOZOU
Get in Touch
Back to Blog

Adding per-tag Atom feeds to Middleman

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

December 12, 2014
2 min read
Adding per-tag Atom feeds to Middleman

Today we decided to add per-tag feeds to our blog. Middleman 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 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

Related Articles

How Can I Design a Software: A Beginners Guide for Business Owners

How Can I Design a Software: A Beginners Guide for Business Owners

Designing software is an exciting yet complex process that involves creativity, logical thinking, and problem-solving skills.

Read More →
The Future of Edge Computing: What Businesses Need to Know

The Future of Edge Computing: What Businesses Need to Know

The digital landscape is evolving rapidly, and businesses must adapt to keep up with rising demands for speed, efficiency, and real-time processing.

Read More →
The Future of Retail: AI, AR, and Digital Transformation Trends

The Future of Retail: AI, AR, and Digital Transformation Trends

Retail is evolving at an unprecedented pace, driven by AI (Artificial Intelligence), AR (Augmented Reality), and digital transformation technologies, revolutionizing the retail industry. Traditional brick-and-mortar stores are no longer just about selling products—they are becoming smart, interactiv

Read More →

Have a Project in Mind?

Let's discuss how we can help bring your ideas to life with our expertise in web and mobile development.

Start a Conversationhello@oozou.com
OOZOU Logo

Bangkok · Singapore · Hong Kong

X
Facebook
Instagram
LinkedIn

Services

  • Web Development
  • AI Agents & Generative AI
  • Mobile App Development
  • Data Analytics & Engineering
  • UI/UX & Product Design
  • Digital Transformation

Company

  • About Us
  • Careers
  • Blog
  • Whitepapers
  • Case Studies
  • Today I Learned
  • Contact

More

  • Industries
  • Get an Estimate
  • Partner Network
© 2026 OOZOU. All rights reserved.
Privacy PolicyCode of ConductABAC Policy