We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

How to use JSON and WXR to migrate to Publii

  • #1884
    Avatar photo[anonymous]

    I recently moved my blog from Drupal 7 to Publii. I love Drupal, but I don’t want the hassle of doing regular updates and patching and Publii is extremely easy to use. Blogging should be easy, and frictionless. Publii offers that.

    Luckily my old blog was hosted using Drupal so exporting content wasn’t an issue. What was frustrating was that Publii only supports the poorly documented WXR format. But seeing as there are loads and loads of WordPress websites, I’m not the first to tackle this problem.

    I decided to share the code and process here in case someone decided to do the same. It will save you a few hours.

    Step 1

    I created a view in Drupal using Views Datasource that generated JSON file with all the fields needed, according to what I found out about the WXR format. The WXR Node page has useful information about the format (see below). The Views display page path was the URL that my importer consumed. I’ve exported the view in case you’re also using Drupal. Note that this was an old Drupal 7 website with Views 7.x-3.5.

    Step 2

    I set up a small project in Node and used the “WXR Node” NPM module. This module took me 80% of the way. I had to modify it to generate a WXR that Publii accepted. I made a pull request to merge my changes. You’ll need that version of importer.js for the app to work.

    The app (json2wxr) relies on Node WXR and is attached below as a zip file. It’s a regular Node app that you run from the Terminal.

    Step 3

    I imported the WXR in Publii using categories for tags. Tags and images came with. I had to manually set main tag, featured image, slug, and meta description for all the posts. For the slugs, I converted the old paths, changing “/” to “_” using a spreadsheet formula. That way I could keep keywords in the slugs and could redirect almost all old paths. My new website uses rewrite rules to redirect from the old page paths to the new.

    A day’s work, all in all.

    Useful tools

    As always, no guarantees, neither expressed nor implied. Keep backups of everything. Data migration is a rinse-and-repeat process 🙂