Migrating to a Jekyll Blog

Recently, I migrated my blog to Jekyll. I was previously using Posterous, but I wanted more of a development workflow when creating posts. With Jekyll, I get to use Markdown and Git to write blog posts. There is the option to use Markdown on Posterous, but it was somewhat clunky when you combine it with the wysiwyg editor they provide. Writing in Markdown feels so clean and uncluttered, unlike html.

What initiated this journey, was me stumbling upon the blog of Zach Holman and reading the source on GitHub. Doing some additional research I found a template and a blog post on getting started with Jekyll.

Setting Up

When I started, I wanted to treat my blog like a typical ruby project that I could setup with Bundler. Therefore, I created a Gemfile with all the dependencies that I was going to need. I was going to need jekyll, rdiscount for Markdown, and rake for creating project rake tasks.

source :rubygems

gem 'jekyll'
gem 'rdiscount'
gem 'rake'

Migrating Posts

Migrating my old posts to the new blog wasn not an easy task. I did get them copied over in html format using a quickly created rake task that parsed through my original Posterous feed. It created the proper filename based on the published date and name of the post. It also put the layout and title on the top of the page. The crappy part was that I had to manually go through the html and replace tags with their Markdown counterpart. I am sure there was an easier way to go about this, but I did not have that many posts to go through.

desc 'Task to jumpstart import'
task :import do
  blog = RSS::Parser.parse(open('http://blog.jonkarna.com/rss.xml'), false)
  blog.items.each do |post|
    name = post.link.gsub('http://blog.jonkarna.com/','')
    date = post.pubDate.strftime('%Y-%m-%d')
    filename = "_posts/#{date}-#{name}.md"
    content = post.description
    FileUtils.touch(filename)
    open(filename, 'w+') do |f|
      f.puts "---"
      f.puts "layout: post"
      f.puts "title: #{post.title}"
      f.puts "---"
      f.puts
      f.puts content
    end
  end
end

Installing Pygments

If you want syntax highlighting, you will need to install pygments either through apt-get on Ubuntu or something similar on osx. I have done it both ways, but it was a little more tricky doing it on osx with brew. I had to go through a few additional steps to get it to work.

brew install python
brew install pip
pip install pygments
ln -s /usr/local/Cellar/python/2.7.1/bin/pygmentize /usr/local/bin/pygmentize

Also, for some reason, I always found it difficult to track down a list of supported pygments: Pygments – Supported languages

Rake Tasks

I liked that Holman had rake tasks for starting up Jekyll and creating new posts. I kept the Jekyll startup task and modified the new post task to my own liking. Starting up Jekyll is even a little easier by just typing ‘rake’. Here is my new post task. It starts out very similar to Holman’s. Now that I am looking at it, there should be an intermediate step between creating the post and dating it, cause this post has taken too long. I will need to manually change the date.

desc "Draft a new post"
task :new do
  puts "What should we call this post for now?"
  name = STDIN.gets.chomp
  date = Time.now.strftime('%Y-%m-%d')
  filename = "_posts/#{date}-#{name}.md"
  FileUtils.touch(filename)

  open(filename, 'a') do |f|
    f.puts "---"
    f.puts "layout: post"
    f.puts "title: #{name}"
    f.puts "published: false"
    f.puts "---"
  end
end

So far I am enjoying my experience blogging with Markdown and Jekyll. I hope to be able to blog more often, but we will see.