Migrating from WordPress.com to Jekyll and Netlify
When I started my personal blog in 2016 I wanted a simple solution. I built software for a living, and I didn’t want to deal with writing code for a simple blog. WordPress.com provided a good platform for this. It was $13 / year for the privilege of using my custom domain, which seemed OK. It was fine for what I needed, but after a while I got tired of the ads, and didn’t really want to pay more.
Now, three years later, I’ve taken an interest in static site generation. I began reading up on Jekyll, and I liked the idea of generating a static site based on simple markdown. I also learned about Netlify, and I became a fan of their continuous deployment and integration with GitHub. The idea of updating my blog by simply pushing to GitHub sealed the deal for me. I decided to migrate off WordPress.com and onto Netlify, generating my site with Jekyll and managing the code in GitHub.
Turns out I was able to migrate this blog in an afternoon! Here’s how I did it; maybe this will be helpful to someone else.
First, I exported the XML for my WordPress.com site using the URL below (replacing BLOGNAME with my WordPress blog’s name)
https://BLOGNAME.wordpress.com/wp-admin/export.php
I then created a new GitHub repo and cloned it
$ git clone reponame
$ cd reponame
Installed Ruby and Jekyll.
Created a new Jekyll blog in my local copy of the repo
$ jekyll new blog
$ cd blog
Installed jekyll-import and prerequisites
$ sudo apt-get install zlib1g-dev
$ sudo gem install hpricot
$ sudo gem install open_uri_redirections
$ sudo gem install jekyll-import
Copied the WordPress.com XML as wordpress.xml into the new blog directory.
Ran the import tool
$ ruby -r rubygems -e 'require "jekyll-import";
JekyllImport::Importers::WordpressDotCom.run({
"source" => "wordpress.xml",
"no_fetch_images" => false,
"assets_folder" => "assets"
})'
Ran the Jekyll site locally for testing
$ bundle exec jekyll serve
Some cleanup was required. Namely:
- In _config.yml set the following so that link URLs would be the same as the old WordPress URLs:
permalink: /:year/:month/:day/:title/
- I set the timezone in _config.yml to ensure that permalinks generated on the server would be as expected.
- Many of the images were weirdly sized or positioned. I removed width and height attributes on img tags and removed unused CSS classes. I also added some CSS classes as needed.
- Image galleries weren’t imported at all. I manually downloaded the missing image files and then used this helpful tip to enumerate the images in blog post.
- Certain linked files weren’t imported. I manually copied them and fixed up the links.
- Comments didn’t come over either, but I only had a few so I manually copied their text. I haven’t added a means of adding new comments.
- I made some minor changes to the look and feel of the site.
Once I had the site running satisfactorily locally, I pushed to GitHub and set up a new site on Netlify that deployed from GitHub. Then I switched the DNS record for blog.mattjustice.com to point to Netlify rather than WordPress.com. All pretty straightforward!