Switching from Jekyll to nanoc

Apologies to anyone who reads my atom feed in their reader of choice. I switched this blog from Jekyll to nanoc over the weekend which caused my old posts to show up as new.

When I started this blog in 2009 I decided on Jekyll, a static site generator. Jekyll is perhaps best known for powering Github Pages, a simple way to get a site at yourname.github.com. Due to a couple small differences, I’ve grown to prefer nanoc, and decided to switch this blog.

I’m certainly not the first to convert their site from Jekyll to nanoc. It was pretty straightforward, as both programs are fairly similar. However, some rules I used made nanoc more closely emulate Jekyll.

nanoc has a blogging helper, which provides similar functionality to Jekyll’s post handling. Unlike Jekyll, which keeps posts in /_posts, blogging helper considers any item with a :kind of article to be a post. Jekyll also determines an articles’ creation time from its title. I created the following preprocess rule to make nanoc act like Jekyll in that regard.

require 'time'
preprocess do
  items.each do |item|
    if item.identifier =~ %r{^/articles/(.*)$}
      item[:created_at] = Time.parse($1)
      item[:kind] = 'article'
    end
  end
end

The other rule was for the routes of articles, for which I used this regex to make articles go in the same location as Jekyll posts. There’s probably a cleaner solution, and the regex might need adjustment for others’ use of Jekyll, but this worked quite well for me.

item.identifier.gsub(%r{^/articles/(\d+)-(\d+)-\d+_\d+-\d+-(.*)$}) do |match|
  "/#{$1}/#{$2}/#{$3}/index.html"
end

With these changes I was able to use all of my Jekyll posts in nanoc without modification.