StuartEllis.eu

Notes on Nanoc

  1. Declaring Optional Dependencies with Bundler
  2. URLs without Extensions
  3. Generating an XML Sitemap
  4. Other Resources

These are some notes on using the nanoc static Web site generator.

Declaring Optional Dependencies with Bundler

Several features of nanoc rely on optional dependencies. For example, the view option requires the adsf package. This Gemfile specifies the dependencies for some commonly used features:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
source :gemcutter

# Dependencies for local Web server
gem 'adsf'
gem 'mime-types'
gem 'rack'

# Dependencies for syntax colorizing filter
gem 'coderay'
gem 'nokogiri'

# Dependency for Textile filter  
gem 'RedCloth'

# Dependency for XML Sitemap generation
gem 'builder'

# nanoc
gem 'nanoc'

Once you have created a Gemfile with these contents, use Bundler to ensure that all of these dependencies are installed. Run the standard install command:

bundle install

Other filters may require additional dependencies.

URLs without Extensions

To create an item without a file extension in the final URL, specify the unique name as a directory, and the name of the item itself as index:

nanoc ci myitem/index

This creates an index.html file in a new directory called myitem/. Your Web server can then resolve a clean URL that does not expose the extension of the source file:

http://www.mydomain.com/myitem/

Generating an XML Sitemap

To configure nanoc to automatically generate a sitemap, ensure that you have installed the Builder gem, and then follow these steps.

First, add a base_url setting to the config.yaml file:

1
2
# The base URL for this site. This is required for XML sitemap generation. 
base_url: http://www.mydomain.com

Add the following line to the lib/helpers_.rb file:

1
include Nanoc3::Helpers::XMLSitemap

Now add an item file with the name sitemap.xml in the content/ directory that only contains this line:

1
<%= xml_sitemap %>

Finally, amend the Rules to handle this item correctly:

1
2
3
4
5
6
7
compile 'sitemap' do
  filter :erb
end

route 'sitemap' do
  item.identifier.chop + '.xml'
end

Once the XMLSitemap helper is included, you may specify priority and changefreq settings for items. Refer to the documentation for XMLSitemap for details.

Other Resources