Migrations: from Wordpress to a static site with Nikola

This is it ! My first post writen with Nikola and, even better, all my website is now made only of static pages.

After serving me well during the past 12 years, Wordpress (thanks to Automattic and its community) will not power anymore my blog, which I expect to consule less resource and to require only marginally less maintenance.

The new software I'm using to replace it is called Nikola (a big thank you to Roberto Alsina, Chris Warrick and other contributors) and it generates my whole website as static HTML pages.

The flexibility of Nikola allowed me to keep most of the organisation of this site untouched with remarkably few change of addresses for the content but still with a little bit of extra efforts that I'll describe below.

For the most important, though, you can find the blog posts and the photos albums at the same places as they were before.

Walking through a Wordpress to Nikola migration

1. Exporting content from Wordpress

The conversion works from an XML export that Wordpress can do for you.

However, this export had a few shortcomings in my case.

First a hack in Wordpress's code is required to also expots the translations of the post and page titles as is indicated at https://github.com/qtranslate/qtranslate-xt/issues/199

In wp-admin/includes/export.php change
  `echo apply_filters( 'the_title_rss', $post->post_title );
to
  `echo apply_filters( 'the_title_export', $post->post_title );

Second I had to manually correct, in the exported file, some attachments paths that started by /mnt/sda... (ie those were absolute paths on the server's internal filesystem). But this happened only for the oldest posts (and so I guess the oldest versions of Wordpress).

2. Importing the content

With such an export, Nikola will easily generate a complete website as is well explained in its manual_.

However, since my blog used, over the time, several "generations" of an extension called qtranslate that helped publishing in french and english, some things were sadly off.

Thankfully Nikola is written in Python and so I could jump in and make the code work for me with this pull request: https://github.com/getnikola/nikola/pull/3275

Then a simple command line invocation does most of the import job:

nikola import_wordpress --qtranslate --one-file --no-draft --export-comments -o site tlog.WordPress.2019-06-16.xml

The result is a perfectly fuctional website, with a raw look'n'feel that can be browsed on one's local machine:

nikola build && nikola serve

To add a more personal touch it is also very easy to play with and adapt Nikola's themes even though there isn's many.

3. Address changes

Nikola automatically generates redirection pages for the content that changes place compared to its original place in the Wordpress site.

One thing that isn't automatic though is to update the relative links in the posts. These links end up pointing at the redirection pages which is totally fine. But a little search'n'replace session did help to improve this.

In any case the generation of redirection pages is very useful and it can even be abused to find a better middleground between the new and legacy url conventions by playing on the redirection map saved in the conf.py file and tweaking some preferences.

This way I renammed the "posts" folder into /blog to keep most posts at the exact same address while I stuck to Nikola's convention for "pages" in /pages.

One last thing after all this, the "translated" urls were, in my instance of Wordpress, below /blog/en whereas Nikola put them in /en/blog. And for this I prefered also to stick to Nikola's choice even if it costed me a few extra search'n'replaces.

4. What about photos galleries ?

A great but non trivial thing in this migration is that Nikola is able to replace both my old Wordpress blog and my zenPhoto powered galleries.

To keep most information (title and descriptions) of the photo albums I had to write index pages for the galleries and album. But Nikola makes it quite easy to do anyway.

5. Statistics and comments

Nikola allows to use comment systems like disqus that I was using previously.

However, considering the few comments I used to recieve (not counting the spam) I prefered to stop bothering with comments.

Wordpress also had a visit statistics sytem that was quite nice to use and that's clearly where I'll loose the most. I could chose to track my users with Google analytics but I prefered to fallback to a much cruder non-tracking system offered by my host Dreamhost.

6. And...

That's it !

Eventually most of the annoying issues I must say came from my bilingual set-up in my original site.

Hopefully this post can be useful to people with a weird set-up as I had and considering such a migration.

Docutils System Messages

System Message: ERROR/3 (<string>, line 55); backlink

Unknown target name: "manual".