Drupal 7 to Jekyll, an Epic Journey
Static blogs have many advantages over PHP engines:
- They’re much faster since there’s no computation overhead at runtime for composing the rendered page
- There’s no security issues regarding SQL injection
- Finally, generating the site removes the need for a staging area with possibly mismatched configurations
Before doing anything, I went through the motion of creating a Ubuntu VM, with the Ruby and RubyGems packages.
sudo apt-get install ruby sudo apt-get install rubygems
Blog migration explained
My first strategy was to follow instructions from this blog post, which seemed to exactly match my target. In essence, I was to get the SQL dump from my Drupal site, execute it on a local MySQL base and execute some Ruby script wrapping a SQL one.
The problem is that the propsed SQL script was not adapted to the structure of my base: I fixed the prefixes and the node types, but I had still no success running the script.
I found other scripts on the Internet, but none was adapted to the structure of my database and I couldn’t get any running despite my best efforts.
Back to the basics: given that no hand-crafted script was able to run on my database, I decided to look further into Jekyll documentation and found there was a gem associated with a Drupal 6.1 migrator.
So, I installed Jekyll – a Ruby gem – and I could finally run the script.
sudo gem install jekyll ruby -rubygems -e 'require "jekyll/migrators/drupal"; Jekyll::Drupal.process($MYSQL_INSTANCE, $LOGIN, $PASSWORD)
At this point, I got no errors running the Ruby script but no output whatsoever. However, I tweaked the
script a bit, where I commented out the lines concerning the node and
entity types (30-31), as well as the whole tag things (lines 53-60 and
69) and I finally obtained some results: a
_drafts and a
_posts folder, with the latter full of
Running Jekyll with
jekyll --server finally generated a
_site folder, with a load of pages.
There are some problems with what I got:
- Some pages have unparseable sections (
REXML could not parse this HTML/XML)
- Pages have no extensions, despite being HTML, so the browser doesn’t recognize the MIME type when they’re run under Jekyll. The normal way would be to have index.html under folders named as the post
- There’s no index
Cloning Octopress and Jekyll
Given my very limited knowledge (read none) of what happens under the cover and my unwillingness to further change the script, I tried the same on a ready-to-use template named Octopress, with the possible intention to migrate the few pages I had (not very satisfying from a software developer point-of-view but pragmatic enough for my needs).
sudo apt-get install git git clone https://github.com/imathis/octopress
Unfortunately, there was an error in the script So, in a desperate attempt, I wanted to give a try to Jekyll Bootstrap.
git clone https://github.com/plusjade/jekyll-bootstrap.git
And lo, I finally got no error, an output and something to view in the browser at http:/0.0.0.0/index.html!
I’ve been tweaking and updating included files (those in the _included folder) and I’m beginning to get something bearing some similarity to the original layout.
To obtain that, I had to install Pygments, the code prettifier:
sudo apt-get install python-pygments
At this point, there are basically 2 options: either manually port other posts and finalize the layout (as well as work toward the original theme), or invest in the configuration process to make it work.
At present, I’m leaning toward the first option. Feedback welcome!
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)