Wordpress to Jekyll

A simple tutorial to migrate

Crédit illustration : Florian Lissot

Few weeks ago, I discovered Octopress, via a Quentin's blog. It's a blog aware and Jekyll based static site generator. Didn't really know those two (Octopress & Jekyll), but I observed they are really light and powerful ways to create content based websites. No more database, juste flat files!

How it works

Based on ruby, jekyll is able to compile a website from several flat files : structure files and content files. The basic structure of a jekyll directory is the following:

.  
├── _config.yml  
├── _drafts  
|   ├── begin-with-the-crazy-ideas.textile  
|   └── on-simplicity-in-technology.markdown  
├── _includes  
|   ├── footer.html  
|   └── header.html  
├── _layouts  
|   ├── default.html  
|   └── post.html  
├── _posts  
|   ├── 2007-10-29-why-every-programmer-should-play-nethack.textile  
|   └── 2009-04-26-barcamp-boston-4-roundup.textile  
├── _data  
|   └── members.yml  
├── _site  
└── index.html  

After compiling, the "_site" folder contains the files you can upload to your web hosting service.

WP2JK tutorial

Here are the steps I followed to migrate this weblog from the monstrous wordpress to the lightweight jekyll (based on jekyll's tutorial).

1.Check ruby

~/Dev $ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]

Running Mavericks, I already had ruby installed. If not, there are many tutorials to install it. Then, just a little test (I'm a ruby noob!) :

~/Dev $ irb
irb(main):001:0> puts "Hello World!"
Hello World!
=> nil

2.Get Brew

In order to get the all requirements, I got homebrew: the mac package installer.

~/Dev $ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Then, a "brew doctor" permits to know which packages are missing or out of date.

~/Dev $ brew doctor

Finally, I upgraded the package (git) that needed to...

~/Dev $ brew upgrade git

3.Install Jekyll

It's now time to get Jekyll up! And it's as simple as a one-line command:

~/Dev $ sudo gem install jekyll jekyll-import     

When finished, let's create the website...

~/Dev $ jekyll new jekyll-blog
New jekyll site installed in /Users/flissot/Dev/jekyll-blog.

So we now can check our brand new jekyll site structure.

~/Dev $ cd jekyll-blog 

4.Import blog posts

The command is the following:

ruby -rubygems -e 'require "jekyll-import";
    JekyllImport::Importers::WordPress.run({
      "dbname"   => "",
      "user"     => "",
      "password" => "",
      "host"     => "localhost",
      "prefix"   => "wp_",
      "clean_entities" => true,
      "comments"       => true,
      "categories"     => true,
      "tags"           => true,
      "more_excerpt"   => true,
      "more_anchor"    => true,
      "status"         => ["publish"]
    })'

To make it work properly, I had to install some gems before...

~/Dev/jekyll-blog $ sudo gem install sequel
~/Dev/jekyll-blog $ sudo gem install mysql2
~/Dev/jekyll-blog $ sudo gem install htmlentities

It was then possible to run the blog posts import. My weblog's database was hosted by OVH and it's not possible to access it remotely. So I first replicated it locally (note that it works better with "127.0.0.1" than "localhost"):

~/Dev/jekyll-blog $ ruby -rubygems -e 'require "jekyll-import"; JekyllImport::Importers::WordPress.run({ "dbname" => "blog", "user" => "MY_USER", "password" => "MY_PASSWORD", "host" => "127.0.0.1", "prefix" => "wp_", "clean_entities" => true, "comments" => true, "categories" => true, "tags" => true, "more_excerpt" => true, "more_anchor" => true, "status" => ["publish"]  })'

5.Checking time

It's almost finished!

Now, all posts from wordpress are imported...

~/Dev/jekyll-blog $ cd _posts 
~/Dev/jekyll-blog/_posts $ ls
2012-02-24-gallery.markdown
2012-02-29-change-the-default-main-domain-folder-to-subfolder.markdown
2012-02-29-hello-world.markdown
2012-02-29-introducing-arduino.markdown
2012-03-07-the-french-presidential-campaign-twitter-and-its-new-stakes.markdown
2012-03-16-blogs-quentin-rousseau.markdown
2012-03-19-finally-arrived-canon-5d-mkiii.markdown
2012-03-30-blogs-%c2%adtwitter.markdown
2012-05-02-interactive-mcq-introduction.markdown
2012-05-03-le-debat-on-twitter.markdown
2012-05-11-watering-plants-in-the-era-of-the-internet-of-things.markdown
2012-05-15-what-is-the-internet-of-things.markdown
2012-06-19-interactive-mcq-end-of-phase-1.markdown
2012-08-24-fakeimg-pl-via-korben-a-mockup-images-tool.markdown
2014-01-02-interactive-mcq-what-happened-then.markdown
2014-01-03-data-re-use.markdown
2014-02-10-welcome-to-jekyll.markdown

Note that they are converted in markdown, but it will need some changes to get a clean blog post.

6.Build

Back to website's main directory...

~/Dev/jekyll-blog/_posts $ cd ..

The only remaining step is to compile the website, so that we'll get a "_site" folder containing all the hostable files!

~/Dev/jekyll-blog $ jekyll build
Configuration file: /Users/flissot/Dev/jekyll-blog/_config.yml
            Source: /Users/flissot/Dev/jekyll-blog
       Destination: /Users/flissot/Dev/jekyll-blog/_site
      Generating... done.