In the time since I last tried migrating my blog to Jekyll, it has gained an official WordPress importer. Unfortunately, that importer requires direct database access and NearlyFreeSpeech.NET doesn’t have the requisite Ruby dependencies.
…so I decided to hack around that. It’s much easier to run the importer locally, but NFSN doesn’t expose their database servers to the world at large… SSH port forwarding to the rescue.
- Install the development headers for libmysqlclient
gem install jekyll-import sequel mysql2 unidecode`
Note: Make sure it does complain about `htmlentities` being missing or you’ll get a broken import with things like the/
in</a> escaped.
- Open up two terminal windows
- In one terminal, adjust this SSH command and run it to forward the MySQL client port
ssh -L 3306:YOUR_DSN_HERE:3306 USERNAME_SITENAME@ssh.phx.nearlyfreespeech.net
- In the other terminal, adjust and run this jekyll-import command to dump the blog
ruby -rubygems -e 'require "jekyll-import"; JekyllImport::Importers::WordPress.run({ "dbname" => "___________", "user" => "___________", "password" => "___________", "host" => "127.0.0.1", "socket" => "", "table_prefix" => "wp_", "clean_entities" => true, "comments" => true, "categories" => true, "tags" => true, "more_excerpt" => true, "more_anchor" => true, "status" => ["publish"] })'
Note: Make sure `host` is set to
127.0.0.1
. If you uselocalhost
, it will try to use a UNIX domain socket rather than a TCP socket and fail. - Exit the ssh connection to close the tunnel and start fine-tuning the exported content.
Unfortunately, I found jekyll-import insufficient (eg. it made no attempt to preserve permalinks) so I started investigating alternatives. I discovered that Pelican (a Python alternative to Jekyll) has some very appealing plugins (eg. [1] [2] [3] [4]), so I’ll probably use that instead.
How to easily jekyll-import a WordPress site hosted on NearlyFreeSpeech.NET by Stephan Sokolow is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Thanks for recommending NFSN. I did not know that project.