How to easily jekyll-import a WordPress site hosted on NearlyFreeSpeech.NET

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.

  1. Install the development headers for libmysqlclient
  2. 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.
  3. Open up two terminal windows
  4. 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
  5. 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 use localhost, it will try to use a UNIX domain socket rather than a TCP socket and fail.

  6. 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.

CC BY-SA 4.0 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.

This entry was posted in Geek Stuff. Bookmark the permalink.

1 Response to How to easily jekyll-import a WordPress site hosted on NearlyFreeSpeech.NET

  1. some_reader says:

    Thanks for recommending NFSN. I did not know that project.

Leave a Reply

Your email address will not be published. Required fields are marked *

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution under the same terms as the associated post.

All comments are moderated. If your comment is generic enough to apply to any post, it will be assumed to be spam. Borderline comments will have their URL field erased before being approved.