Skip to content

Instantly share code, notes, and snippets.

@dhulihan dhulihan/config.rb
Created Jan 21, 2013

Embed
What would you like to do?
middleman sitemap generator
# config.rb
page "/sitemap.xml", :layout => false
# data/site.yml
url: http://www.example.com
# source/sitemap.txt.erb
<% root_url = data.site.url %>
<% sitemap.resources.each do |page| %>
<%= "#{root_url}#{page.url}\n" if page.url !~ /\.(css|js|eot|svg|woff|ttf|png|jpg)$/ %>
<% end %>
# source/sitemap.xml.builder
xml.instruct!
xml.urlset "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9" do
sitemap.resources.each do |resource|
xml.url do
xml.loc "#{data.site.url}#{resource.url}"
end if resource.url !~ /\.(css|js|eot|svg|woff|ttf|png|jpg)$/
end
end
@tmaier

This comment has been minimized.

Copy link

commented Apr 15, 2013

Looks great. Thank you.

Worth to note:

Gemfile

gem 'builder'

robots.txt.erb

Sitemap: <%= data.site.url %>/sitemap.xml
@julsag

This comment has been minimized.

Copy link

commented Aug 29, 2016

hello, gem 'builder' no works for me. When i try your files, sitemap.xml.builder is the same on my folder build in middleman

Thanks in advance

Jul

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.