Skip to content

Instantly share code, notes, and snippets.

@dbtlr
Last active March 10, 2017 18:55
Show Gist options
  • Save dbtlr/5294990 to your computer and use it in GitHub Desktop.
Save dbtlr/5294990 to your computer and use it in GitHub Desktop.
Sitemap.xml file in HAML for Middleman.
<?xml version="1.0" encoding="UTF-8"?>
- pages = sitemap.resources.find_all{ |page| page.source_file.match(/\.html/) and not page.source_file.match(/source\/test\// ) }
-# Fill this array in with pages you don't want in the sitemap.
- excluded_paths = ['404']
- host = "http://yoursite.com/"
%urlset{ :xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9" }
%url
%loc= host
%priority 0.3
%lastmod= DateTime.now.to_time.iso8601
%changefreq daily
- pages.each do |page|
- path = page.destination_path.gsub('/index.html','')
- unless excluded_paths.include? path
- priority = 0.4
- changefreq = 'monthly'
- lastmod = ''
- article = blog.articles.find {|a| a.url == '/' + path }
- if article
- lastmod = article.date.to_time.iso8601 if article
- priority = 0.2
- changefreq = 'monthly'
- lastmod = page.data.lastmod.to_time.iso8601 if page.data.lastmod
- changefreq = page.data.changefreq if page.data.changefreq
- priority = page.data.priority if page.data.priority
%url
%loc= host + path
%lastmod= lastmod
%changefreq= changefreq
%priority= priority
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment