Skip to content

Instantly share code, notes, and snippets.

@ryanburnette
Forked from ls-lukebowerman/sitemap.xml.erb
Last active February 4, 2017 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanburnette/5b1cebea7015f3bac3a7 to your computer and use it in GitHub Desktop.
Save ryanburnette/5b1cebea7015f3bac3a7 to your computer and use it in GitHub Desktop.
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