[Middleman 3] Middleman のテンプレートをつかって sitemap.xml を生成する

erb テンプレートをつかって、Sitemap XML を作成します。

“`prettyprinted
% middleman version
Middleman 3.3.6
“`

こちらで紹介されていました。

> [Understanding Middleman – the static site generator for faster prototyping – Author and responsive web developer Ben Frain](http://benfrain.com/understanding-middleman-the-static-site-generator-for-faster-prototyping/)

## sitemap.xml.erb

こちらで公開されているソースを利用して、`source/sitemap.xml.erb` にテンプレートを作成します。

> [Sitemap (sitemaps.org) generator for Middleman](https://gist.github.com/lukebowerman/3287848)

`youdomain.com` の箇所は、必要な値に書き換えます。

“`ruby:source/sitemap.xml.erb
<% pages = sitemap.resources.find_all{|p| p.source_file.match(/\.html/) } %>


<% pages.each do |p| %>

http://youdomain.com/<%=p.destination_path.gsub('/index.html','')%> 0.7

<% end %>

“`

## config.rb

sitemap.xml.erb に対して、テンプレートを無効にする設定を加えます。

> [Middleman: テンプレート](http://middlemanapp.com/jp/basics/templates/)

“`ruby:config.rb
page “/sitemap.xml”, :layout => false
“`

`middleman build` で /build にファイルが生成されました。