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";
      "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 "" than "localhost"):

~/Dev/jekyll-blog $ ruby -rubygems -e 'require "jekyll-import"; JekyllImport::Importers::WordPress.run({ "dbname" => "blog", "user" => "MY_USER", "password" => "MY_PASSWORD", "host" => "", "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

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


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.