Today For the past 2 weeks, I've been trying to move out from my beloved Wordpress blog to this new, shiny and hipsterish blog plateform called Ghost.

So, two big moves:

The longest part wasn't to have Ghost up and running but to import all my Wordpress shit into this baby's DB. Ha, a long story that involved automated and manual work.

Import WP data into Ghost

At first, I tried the Ghost Wordpress Plugin which exported well my WP data but I couldn't import it my Ghost DB on AWS for some unknown reasons... So I tried it again locally and it worked!
Bad luck, the WP plugin didn't convert HTML to Markdown (yes, I wrote all my WP articles in HTML) so I needed to find another way to convert it.

I finally used the ExitWP script to convert my Wordpress WXR file into Markdown (this part was very tricky because the Python script doesn't convert the <> entities inside pre tags so most of articles weren't properly converted.
There was a lot of manually operations here to replace all the code parts my blog has.

Once all converted, I replaced the Ghost in-DB-HTML content by the equivalent Markdown content... manually*!

When done, all my data was all Markdown but problem is: all pictures are still pulling from my Wordpress content upload directory...

(*) Yes, because I needed to strip a few things from my articles, like removing all the smiley faces.

Importing WP images

This little tasks wasn't the longest but the most exciting. As of today, the WP Ghost plugin doesn't handle the images (or any other file import) so I wrote a script called wp2ghost_image_importer.php.

What you need to do to use this magic is:

  1. Import your blog content in Ghost with Markdown syntax (very important).
    I used ExitWP (https://github.com/thomasf/exitwp) then replaced all my Ghost data by its equivalent in Markdown
  2. Export your Ghost database (yourblogurl/ghost/debug)
  3. Configure this script
  4. Run this script in console (needs PHP >= 5.3)
  5. Re-generate a ghost.db file (backup your old one first) by deleting it and restarting the app
  6. Import your updated Ghost database (generated by this script)
  7. Move all your pictures into your Ghost installation picture directory

That's it. All pictures or whatever file is properly imported into your Ghost installation. Don't hesitate to reach out if getting a trouble with this script.

Importing comments & URLs

Comments

Before you decide to move away from Wordpress, you must switch to Disqus and make sure it has all your comments.

Once it's done, you will need to rewrite all threads URLs. For instance, my WP were fomatting this way:

http://blog.eexit.net/{year}/{month}/{slug}.html

And now with Ghost:

http://blog.eexit.net/{slug}/

Go on the Disqus > Discussions > Tools > click on « Start URL Mapper ».
Download the CSV file and open it with an editor (I chose Sublime Text).

Perform following find/replace with Regex:

^(http:\/\/[^/]+/)(\d{4}\/\d{2}/)([^.]+)(\.html)

\1\2\3\4, \1\3/

That will update each line to this:

http://blog.eexit.net/{year}/{month}/{slug}.html, http://blog.eexit.net/{slug}/

Upload the updated file to the URL mapper tool and run it.

Rewritting URLs

The thing is that all your wild links are still pointing on your old URL. You need to redirect all those link to the new URL.

Add a rewriting rule to your Web server virtual host to rewrite all URLs properly.
Add this line in the location part of your Ngninx virtual host:

rewrite "\d{4}\/\d{2}\/([^.]+)\.html(.*)$" /$1$2 permanent;

Reboot the server (sudo service ngninx restart) and you're set. Yay!

Hope this article will be useful for people who wants to have their own self-hosted Ghost blog.


Joris Berthelot