Goodbye WordPress, hello Jekyll
After five years on a self-hosted WordPress, this blog now runs on Jekyll and GitHub Pages. Why, how the migration went, and what I ran into along the way.
If you’re reading this, it works. As of today this blog no longer runs on WordPress at a cheap shared host, but on Jekyll and GitHub Pages. All posts since 2010 have moved along, the old URLs should still work, and if something’s broken, let me know.
Why leave WordPress?#
WordPress isn’t bad. I built dozens of sites with it back at the agency and it taught me how the web works. But for a personal blog I update a few times a month, it was costing me more than it gave back:
- Updates. Every month an update of WordPress itself or of some plugin. Which is good, but every time with the question whether my theme would survive it.
- Spam. Akismet caught most of it, but over the years I’ve still deleted tens of thousands of spam comments.
- That one time. In 2013 a contact form plugin had a hole in it, and for a week my blog served hidden links to a pharmacy in a country I’ve never been to. Jef from the agency helped me clean up the mess, with a look on his face that said “told you so”.
- Writing. I write everything in vim. Then I’d paste it into the WordPress editor, which mangled my code blocks. Every. Single. Time.
What I wanted: Markdown files in a git repository, static HTML, nothing to hack, nothing to update.
Why Jekyll and GitHub Pages?#
I also looked at Hugo, which is written in Go and builds ridiculously fast. But GitHub Pages builds Jekyll sites automatically on every push, and that’s exactly the workflow I wanted: git push and it’s online. Free hosting is a nice bonus.
The migration#
Exporting#
In WordPress you can create an XML file with all your posts via Tools > Export. Jekyll has an importer for that:
gem install jekyll-import
ruby -rubygems -e 'require "jekyll-import";
JekyllImport::Importers::WordpressDotCom.run({
"source" => "domienator.wordpress.2015-09-12.xml"
})'
That gave me a _posts folder with over a hundred files. The result is HTML with YAML front matter, not Markdown. I converted the newest posts by hand; the oldest ones stay as they are for now. Jekyll doesn’t mind.
Keeping the old URLs#
My WordPress used permalinks like /2012/05/03/title-of-the-post/. In _config.yml you can set the same pattern:
title: "Life of a Developer"
url: "http://domienator.com"
markdown: kramdown
highlighter: pygments
permalink: /:year/:month/:day/:title/
exclude: ["Gemfile", "Gemfile.lock", "README.md", "vendor"]
Then I spent an evening with a little script checking every old URL from the WordPress sitemap against the local Jekyll build. Seven posts had ended up with a different slug because of accents in the title (“café” became “cafe” instead of “caf%c3%a9”). Fixed by hand in the front matter.
Testing locally#
To be sure the site builds locally the same way it does at GitHub, I use the github-pages gem, which pins the same versions GitHub itself uses:
# Gemfile contains: gem 'github-pages'
bundle install
bundle exec jekyll serve --watch
And the blog is up at http://localhost:4000.
The domain#
A CNAME file in the repository containing domienator.com, and at my registrar the DNS records pointed to GitHub. An hour later it worked.
Comments#
A static site has no database, so no comments either. I moved the old comments over to Disqus. I’m not entirely comfortable leaving that to an external service, but all the alternatives are more work.
What I miss#
One thing bugs me: GitHub Pages doesn’t support HTTPS on a custom domain. On yourname.github.io it does, on domienator.com it doesn’t. For a blog without logins or forms that’s not a disaster, but after a year in which I’ve wrestled with certificates more than enough, it feels like a step back. I hope that changes someday.
What I don’t miss#
The shared host. The admin panel. The email “A new version of WordPress is available”. The feeling that somewhere there’s a PHP file I didn’t write myself that someone else is abusing.
This post was written in vim, committed with git commit -m "Post about the move" and published with git push. That’s exactly how I wanted it.
Segfault deleted a post from 2011 during the migration, by the way, by lying down on the Delete key. Luckily everything is in git now.