Search code examples
rubysitemapmiddleman

How to ignore pages in Middleman Sitemap


I'm new to Middleman (and Ruby) and am working on an HTML and XML sitemap. I've got the sitemap generated correctly using this method.

<% pages = sitemap.resources.find_all{|p| p.source_file.match(/\.html/) } %>
<?xml version="1.0" encoding="UTF-8"?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <% pages.each do |p| %>
  <url>
  <loc>http://youdomain.com/<%=p.destination_path.gsub('/index.html','')%></loc>
  <priority>0.7</priority> 
</url>
<% end %>
</urlset>

But this is all .html pages within the site. How do I exclude certain pages (gated content, AB test pages, etc) from the query so they are not included in the sitemap?


Solution

  • Just add more criteria to your .find_all block:

    .find_all { |p|
      p.source_file.match(/\.html/)
      && p.whatever !== 'something'
    }