Cedric Fung

Co-founder of Shou

Stream the future to the present

Jekyll My Blog

Aug 24, 2014

Just migrated my blog to Jekyll, it was a custom Rails application, and I wrote a simple Ruby script to convert all Markdown text in the MongoDB to Jekyll posts.

Post.published.each do |post|
  name = "#{post.created_at.strftime("%Y-%m-%d")}-#{post.slug}.markdown"
  File.open("_posts/#{name}", "w") do |f|
    f.puts "---"
    f.puts "layout: post"
    f.puts "title: \"#{post.title}\""
    f.puts "date:   #{post.created_at.strftime("%Y-%m-%d %H:%M:%S")}"
    f.puts "---"
    f.puts "\n"
    f.puts post.content.gsub("\r\n", "\n").gsub("```shell", "```bash")

With the experience in the heavy Rails framework, it has been much easier for me to use the gems jekyll-assets, autoprefixer-rails and jekyll-sitemap. The Jekyll theme is highly inspired by http://rickharrison.me.