-
-
Save ryanburnette/5b1cebea7015f3bac3a7 to your computer and use it in GitHub Desktop.
Sitemap template and associated helpers for Middleman.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ./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