Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sitemap template and associated helpers for Middleman.
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<% sitemap_resources.each do |r| %>
<url>
<loc><%= sitemap_path(r) %></loc>
<priority><%= sitemap_priority(r) %></priority>
</url>
<% end %>
</urlset>
# ./helpers/sitemap_helpers.rb
module SitemapHelpers
def canonical_domain
development? ? "localhost:4567" : "someurl.com"
end
def sitemap_path(r)
"http://#{canonical_domain}/#{r.destination_path}"
end
def sitemap_resources
sitemap.resources
.reject { |r| r.destination_path.include?("sitemap.xml") }
.reject { |r| r.destination_path.end_with?(".css") }
.reject { |r| r.destination_path.end_with?(".png") }
.reject { |r| r.destination_path.end_with?(".js") }
.reject { |r| r.destination_path.end_with?("robots.txt") }
end
def sitemap_priority(resource)
if resource.data.sitemap && resource.data.sitemap.priority
resource.data.sitemap.priority
else
"0.7"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.