Skip to content

Instantly share code, notes, and snippets.

@dhulihan
Created January 21, 2013 22:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhulihan/4590199 to your computer and use it in GitHub Desktop.
Save dhulihan/4590199 to your computer and use it in GitHub Desktop.
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
Copy link

tmaier commented Apr 15, 2013

Looks great. Thank you.

Worth to note:

Gemfile

gem 'builder'

robots.txt.erb

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

@julsag
Copy link

julsag 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