Sitemaps with nanoc
The Sitemaps protocol allows a webmaster to inform search engines about URLs on a website that are available for crawling. A Sitemap is an XML file that lists the URLs for a site. It allows webmasters to include additional information about each URL: when it was last updated, how often it changes, and how important it is in relation to other URLs in the site. This allows search engines to crawl the site more intelligently. Sitemaps are a URL inclusion protocol and complement robots.txt, a URL exclusion protocol.
Let’s have a look how to generate Sitemaps with nanoc. We start by adding the following line to
Next, we have to set up a base url for our website, by adding the following line to
Now we can create a sitemap page with the following content:
In this example I’m using HAML as a template language.
Last step is to adjust
Rules file to handle the sitemap file accordingly
compile 'sitemap' do filter :haml end route 'sitemap' do item.identifier.chop + '.xml' end
Once compiled and deployed, Sitemaps can be accessed at
/sitemap.xml of your website.
My Tech Newsletter
Get emails from me about programming & web development. I usually send it once a month