Static Site Generators
The evolution of my blog from Pelican to Hugo
I periodically like to refresh the look and feel of my blog and I been on a journey over the years from initially using Wordpress to embracing the simplicity and speed of static websites. As a python fan I was initial drawn to Pelican but in my most recent search for an updated theme, I have started to realise even though I still like idea of Pelican I am no longer as passionate about it as I once was. We have a new kid on the block.
First a little history ..
I have used Wordpress in the past and my first thought was to go down this route once more with the Raspberry Pi that I now use to host my website, my only question was would it perform to my expectations. I decided to use NGinx (lightweight and fast) and found a couple of posts detailing the steps, but after spending way too many hours tweaking parameters and adding various web caches within Wordpress, I finally came to the conclusion that PHP was just a CPU hog, which was taxing the poor Raspberry Pi way too much. With a minimal set of plugins, I was unable to get the first visit to the page to load in less than 10 seconds. In addition, I was becoming increasingly concerned with the endless flood of vulnerabilities that are continually being discovered so I decided to go back to basics but what to use?
While searching on the net I came across Pelican, the documentation was great it was all written in Python and available in GitHub. Finally as a bonus, Pelican has a rich set of themes that are also available via GitHub and easily customizable with a little bit of Python.
The idea behind Pelican is really simple, instead of building dynamic sites with databases, just write a blog post in Markdown then along with some other configuration files use Pelican to generate an efficient static website. Versioning and backup of the website is then performed using GitHub and a simple cron job pulls the source once a day and uses Pelican to regenerate and update your website. So as a database guy for many years my first post is all about creating a blogging site and not using a database!
The following steps assume that you have a raspberry pi running Raspbian but it should be easy to tweak the steps for your own environment.
First install some packages
$ apt-get install nginx
$ apt-get install python-pip
$ apt-get install git
Then upgrade pip and use it to install some python based tools
$ pip install -U pip
$ pip install pelican
$ pip install BeautifulSoup
$ pip install Markdown
Next clone the pelican plugins repository to provide easy access to the rich set of plugins that exists.
$ git clone -recursive https://github.com/getpelican/pelican-plugins
Finally, choose a theme and start writing your blog in Markdown. Lots of themes are available but I really like DandyDev’s theme which I have tweaked for my own site. I travel a lot and consequently I will not always have direct access to my Raspberry Pi. To get around this problem, I use GitHub to manage my edits and versions. I then have a simple cron job running that pulls from github periodically and regenerates the entire website using pelican in a few seconds.
#!/bin/bash
git pull https://github.com/gregory-smith/pelican-theme.git
$ git pull https://github.com/gregory-smith/data-smith.git
$ pelican -d /stage/data-smith.ca/content -o /usr/share/nginx/html -s /stage/data-smith.ca/pelicanconf.py
Hello Hugo!
I always had a few issues with Pelican, mainly around the non-obvious way the final static site would be organised. I lived with these quirks but in many ways the final straw was when I want to find a new theme that reflected a more up to date look and feel. I really like the work that HTML5.UP are doing in this area and really just wanted to create a template using Pelican. I spent a couple of days in my spare time starting to look at creating a new template, but quickly realised that was actually a major distraction from what I should be doing which was getting into good habits writing blogs. Twenty minutes of googling later and I discovered that not only did a nice new tool exist, that ran on a Mac (I love my Mac) but someone had already spent all the time and effort porting the very template I wanted to use. The rest as the saying goes is history, download Hugo and use it, it’s fast, intuitive, allows you to edit your website in real-time and has a large and active community.
