For some time I’ve ran this blog on Wordpress and I’ve had no complaints. Wordpress is a mature and very powerful platform.

However in my case that turns out to be it’s undoing. I blog at most once a week (it’s been much less than that in the last few months). This meant I was logging in to keep wordpress updated more than I was actually writing posts. Additionally there’s a lot that goes on behind the scenes in a wordpress install which meant that there was always going to be a performance hit.

I needed something that was going to require minimal maintenance and also be fairly minimal. To this end I started looking into a static generated site. The idea is that the site is written offline and then generated through a static site generator.

I looked through a number of Static Site Generators and settled on Pelican mainly because it was written in Python and I would be comfortable making changes if I had to.

Installing

The docs provide guidance on Installing pelican. I also installed markdown

Importing

The first step was to import my existing wordpress posts, fortunately Pelican provides an import script to do this.:

pelican-import -mmarkdown --wp-attach --wpfile --dir-cat -o import/ myWordpressExport.xml

(In order to run this you may need to pip install BeautifulSoup4 lxml)

It took a few attempts at playing around with options to get the import in a format I was happy with. The options I ended up using were:
—wpfile
Specifies that this will be a wordpress import.
-o import/
Specifies the output directory
-mmarkdown
Specifies that the posts should be imported as markdown files.
—wp-attach
Also pull down attachments
—dir-cat
Places articles into a folder based on it’s category.

There was still some outstanding issues however, links in the files were absolute links which would make testing the site locally a pain. Additionally I used GitHub Gist links in my articles which a wordpress plugin would then generate the script tags for. Finally the uploads were being pulled down into a wp-content folder.

All of these were minor though. I created an import script in python to replace the absolute URLs and move the uploads over to a different folder. Finally I created a python markdown gist plugin which would replace the gist URLs with the contents of the gist.

Setup

The above steps provided a site that I was fairly happy with. There was some things I wanted to change however. I was keen to keep my URL structure as similar as possible. Pelican allows changing the URL and save location for categories, tags, e.t.c. The following would have each category as a folder with each article as it’s own folder (which would give me “nice” URLs without the trailing “.html”).

USE_FOLDER_AS_CATEGORY = True
ARTICLE_URL = '{category}/{slug}/'
ARTICLE_SAVE_AS = '{category}/{slug}/index.html'
CATEGORY_URL = 'category/{slug}/'
CATEGORY_SAVE_AS = 'category/{slug}/index.html'
TAG_URL = 'tag/{slug}/'
TAG_SAVE_AS = 'tag/{slug}/index.html'

I also switched over to a Pelican Bootstrap 3 template and tweaked this to my liking and updated the config to use that.

Comments

Next up was comments. After investigating some options, including Disqus (which seemed to fiddle with all links on the page by default which I disliked) I decided to do away with comments altogether. I’ve had 407 comments on my site, of which 2 were not spam. If you’d like to see comments reinstated let me know in the Contact form.

Contact form

Speaking of contact form this would be a part of my site that wasn’t static - something would need to process the form. This may be the focus of a future post but in the mean time feel free to Contact Me.