Going Static with Nanoc
I used Wordpress to publish this website for many years. Wordpress is a great piece of open source software and has helped millions of people get into online publishing. However, after some frustrating experiences with updating themes on this site and helping a couple friends recover their sites after hackers trashed them, I started looking around for something different. I heard about static site generators and tried several including Middleman, Jekyll and Octopress before finally settling on nanoc.
Static Site Generators
Why go static?
With over 60 million sites using Wordpress, it has enjoyed immense popularity. This has also led to Wordpress installations being a huge target for hackers. To keep Wordpress secure, you need to manually update it quite often, something many site owners don't do. Even up-to-date Wordpress installations are now a targets as hackers are simply brute-forcing admin passwords and taking over sites. Static websites have no code running on the server and no database, so barring some sort of security hole in your web server or operating system, hacking a static website would be very difficult if not impossible.
Wordpress needs to compile your pages every single time someone visits your website... a process that does not scale well when your site suddenly gets a lot of traffic. There are caching systems that help relieve this problem and speed things up, but they can be rather complicated to set up correctly. With a static website, your server only needs to serve your content, which makes your website really fast! It also means that you no longer need to have a MySQL or PHP running on your server, so you can host your sites from any platform that can serve static files (including Amazon S3).
Simple server configuration
Most modern hosting platforms come with support for Wordpress, but setting up an optimized VPS for running high traffic sites can be a real chore. If your site is static, any web server should be able to do a good job of serving up your site. Setting up hosting for a static site on Ubuntu server can be as easy as running
sudo apt-get install nginx and copying and pasting an optimized config file.
Everything stored in Git
One thing that really bothered me about Wordpress is that a site's content is stored all over the place. You have Wordpress files, theme files, plugin files, and content stored in dozens of database tables. If you make a change to your site, it's difficult to go back and see what it was like before. With a static website generator, you can store the entire contents of the site in simple text and graphics files which in turn can be stored in a version control system like Git. This means that your website's entire history is stored in version control and going back to a previous version is easy. I also like being able to see exactly how my code changes are reflected on the website. With Git diffs, I can verify that my changes are doing what I expect (and only what I expect). Storing everything in Git also makes it really fast and easy to deploy to my VPS.
I tried several other apps before giving nanoc a try. I had avoided it at first because people said it was difficult to learn. Ironically, I found it easier to learn than the others and by far the most powerful. I probably like it so much because I love the Ruby programming language and nanoc lets me take full advantage of Ruby and different Ruby gems. I found it to be a very "pure" Ruby environment, with a lot less "magic" than you get with something like Rails. Nanoc has a very active community and creator Denis Defreyne is always updating nanoc with new features and helping people in the nanoc Google Group and IRC.
It is true that nanoc has a bit of a learning curve, but so do most things worth learning. I found the online tutorials very useful and people are always around to help answer questions in IRC and discussion groups. Once I got my head wrapped around nanoc, I found myself loving it!
Challenges of going static
The easiest way to implement comments on a static site is with Disqus. Their platform has really matured over the years and is quite user friendly. I also found that user engagement went up dramatically after switching to Disqus (and spam dramatically went down as well). Adding Disqus comments is as easy as copying and pasting some code into your template.
The easiest way to solve this problem is to use Google Custom Search. Using other systems are possible but require much more work or a lot of money.
After building several sites with nanoc, I couldn't be more happy (although the roadmap for nanoc 4 does look like things will get even better). As part of the process of upgrading this site to nanoc, I decided to release the source code for the site under the MIT license. I've posted the code used to generate this site over at GitHub so that you can download it and give nanoc a try for yourself. Hopefully, someone will find this it useful.
Have you used a static site generator? Which one is your favorite? Leave a comment below!comments powered by Disqus