My Blogging System: Nanoc

I've spent a good while looking for the perfect blogging software. I've jumped between WordPress, TextPattern, ExpressionEngine, and Tumblr, just to name a few. But none of them really fit me. WordPress was the closest to what I wanted, and is an excellent platform, but it was just too big for the relatively small amount of features I need. The others were also viable alternatives, but none of them really hit home.

Then, a few days ago, a link to Brent Simmon's home-grown system popped up in several of my feeds, so I decided to take a look. Right away I knew I wanted something similar. The simplicity of writing this post out in TextMate gives a programmer-geek like me such high levels of joy that it's difficult to capture in words. Do I want bolded text? Simple: wrap it in a <strong> tag. The amount of control I have over every aspect of the website is exactly what I was looking for.


So, what do to? I toyed with writing my own system from the ground up, but I realized that it would never get finished that way; too many things happen around this time every year with school that it would be impossible to devote enough attention to a side project. That's when I somehow stumbled upon Nanoc, and I realized that it would be perfect, and it has been. Nanoc has been flexible enough for me to roll my own customized setup, but not so flexible that I have to write everything. Obviously, Nanoc wasn't made specifically to power blogs, so I gladly had to get my hands dirty and write some code to really make things perfect.

The Homepage

As a prerequisite for the blogging aspect of the site, I wanted each post to have a permalink, and have one post featured on the front page of the website. Some background, first: each page in Nanoc has two files, a YAML file containing metadate, as well as the actual HTML / XML / what-have-you file. Each post is created in a folder corresponding to the date it was written. For example, this post currently resides in /posts/2009/02/02, as you can see from the permalink; there's no fancy mod_rewrite magic happening, the file's are really there. To stick a post to the home page, I simply open the metadata file assocated to the post, and add the following line: This tells the custom Nanoc filter I wrote which post to display on the homepage:

As you can see, it is was really quite simple to do what I wanted to do, and I only had to resort to one "hack". However, I am almost 100% sure that there has to be a better way to pass data back between the file and the filter, but I have not yet found it.

Creating Posts

Every post will obviously follow similiar guidelines; it will be created in a folder corresponding to the date (/posts/year/month/day), it will have an attribute named created_at, and it will be passed to the post filter to add the permalink, etc. No self-respecting programmer will allow him- or herself to do that much manual labour, so I wrote an extension to the Nanoc CLI. Unfortunately, the only way I was able to do so was by creating the file directly into the nanoc/lib folder, where the gem was installed. Once again, if anyone knows of a better way, please let me know. The command I created allows me to create a new post just like I would create a new page, except all the repetitiveness is removed.


One thing that I haven't mentioned so far is Nanoc's key feature: static files. Everything is generated locally, on my MacBook, and then uploaded to this website. As such, loading times are greatly reduced, since every page is just plain HTML. To generate the static files for your site is one simple command. However, you would then have to log into your FTP client and upload the website every time you made any change. Once again, that wouldn't cut it for me. So, I wrote a simple Rake task to deploy the site using Net::SFTP by Jamis Buck:
Deployment is now one short command away.


I've written other filters but those are for another day. For example, the archive page is powered by a filter that separates posts into a Hash organized by date. The RSS filter is a work in progress, and should be up soon. It will utilize the amazing Builder gem. And I'm just getting started, really; everyday I find something new to do in Nanoc, and I don't think I'll ever stop learning.

In conclusion, Nanoc is the perfect tool for what I was trying to do: create a blog that could be easily expanded using my favourite language, Ruby. It fit the bill perfectly for this project, and it may be just what you're looking for as well.

Posted on Monday, February 2nd at 07:35 PM. Permalink.

Other Recent Posts

Welcome to!