I’ve just completed the migration of a Wordpress blog to GitHub pages using the Ruby based Jekyll blogging engine. The following resource was very useful…

Migrating from Wordpress to GitHub Pages

But there were a couple of small changes I needed to make to get this fully working for me. The code to convert the Wordpress xml export to html contains a minor error…

ruby -rubygems -e 'require "jekyll-import";
JekyllImport::Importers::WordpressDotCom.run({
  "source" => "youdidwhatwithtsqlcom.wordpress.2021-03-13.xml",
  "no_fetch_images" => false,
  "assets_folder" => "assets/images"
})'

This threw the following error:

Traceback (most recent call last): 1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require' /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require’: cannot load such file – ubygems (LoadError)

This command should be:

ruby -r rubygems -e 'require "jekyll-import";
    JekyllImport::Importers::WordpressDotCom.run({
      "source" => "youdidwhatwithtsqlcom.wordpress.2021-03-13.xml",
      "no_fetch_images" => false,
      "assets_folder" => "assets"
    })'

After this I could convert all my posts to html format. Then I could run the ruby ./wordpress-html-to-md.rb "_posts" command to convert all of the posts to markdown. This worked but I spotted a formatting problem. All of my code snippets were on a single line. Something was stripping all the line endings from my code examples. I tracked this down to the reverse_markdown (2.0.0) library used by the conversion process. This problem has already been fixed with the addition of three lines of code. This wasn’t available to me via gem install so I just pasted the following lines of code:

when 'text'
  # Preserve '\n' in the middle of text/words, get rid of indentation spaces
  ReverseMarkdown.cleaner.remove_leading_newlines(node.text.gsub("\n", '<br>').strip.gsub('<br>', "\n"))

into the following file /Library/Ruby/Gems/2.6.0/gems/reverse_markdown-2.0.0/lib/reverse_markdown/converters/pre.rb at the appropriate line. Rerunning the conversion process showed the problem had been resolved.