Mike Conigliaro

From WordPress to nanoc

I finally decided to start blogging like a hacker, which is ironic, considering that I’ve actually come full-circle now. Back in the late-nineties (before I knew about databases, and before the term “blog” even existed), I spent a lot of time working on a Perl-based blogging engine that actually worked pretty similarly (though much less sophisticatedly) to how a lot of today’s static site generators work. Instead of working with sane formats like YAML or Markdown (which didn’t exist back then), I ended up managing everything in my own pseudo-XML format. As ugly and hackish as this system was, the resulting output was pretty nice, and the project was definitely a good learning experience for me as a teenager. But now that static site generators are all the rage, there are a lot of much better options out there, which gives us “hackers” a good opportunity to migrate away from WordPress without a ton of effort.

After reading this thread on Hacker News about yet another new static site generator, I decided to give nanoc a spin (mostly because it seemed to be the most popular option by people commenting on that thread). I skimmed through the nanoc Getting Started guide and (for the first time in several years) set out building a new layout for my new site. Since I didn’t want to repeat the pain of the old days, I made sure to get Compass integration working right away.

Once the layout was done, I spent about a week slowly reimplementing features and moving data over from my old WordPress site. The static pages were basically just a copy & paste (with some manual converting to Markdown), but there was no way I was going to repeat that process for 100+ blog posts. There are a few example WordPress-to-nanoc scripts floating around, but they all left a lot to be desired, so I ultimately ended up writing my own. The result of that effort can be found in wp2nanoc.rb. Besides the addition of some nice command line option parsing, my script also does some basic conversion from HTML to Markdown and from WP-Syntax to SyntaxHighlighter.

The last thing to bring over were my comments, and Disqus handled most of that for me. I basically just installed the Disqus WordPress plugin and ran through the automatic import process. Then to make the comments show up on my new site, I set disqus_shortname and disqus_url to the appropriate values in my embed code. Note: If you find the developer documentation as confusing as I did, just know that these are the only values that need to be set. I originally tried using disqus_identifier, but that didn’t work, because the plugin uses unconfigurable, WordPress specific values for this option which obviously won’t be available in nanoc.

So what did I gain from my migration to nanoc?

  • I can now keep my entire site (data and all) in git
  • Static files mean blazing speed
  • No database means I can host my site in Amazon S3 for pennies
  • No more worrying about PHP/WordPress security issues
  • I got to experiment with new (to me) technologies like Haml, Sass/SCSS, Compass and Blueprint
blog comments powered by Disqus