Starting afresh with Middleman

For the (3rd, 4th?) time I’ve decided to re-launch my blog. I thought I’d start with a brief post on some of the minor technical details of my experience in switching to use Middleman and Middleman-Blog. I’ve used both Jekyll and Octopress in the past for my blog, but life is for learning - right?

Rather than start from scratch, I decided to find an existing template to get me started as quickly as possible. I settled on Middleman-Casper, a theme based on Casper (the default theme for Ghost, and Middleman 4.

I’ve used Middleman in the past (we use it to power the Terracoding website too), and can really get behind the idea (and advantages) of a static site. Unfortunately the Terracoding site uses an older version of Middleman, so there were a few quirks and differences when it came to using version 4.0.

There seems to be a few issues with middleman-deploy, where deploying would push the root folder instead of the intended build folder (#114). Instead I used mgd, a fork of the build script to deploy Jekyll to Github Pages.

Version 4 of Middleman also removes the article command, as a result I wrapped this and the other mish-mash of functionality in a single Rakefile, standardising the commands/interactions.

require "#{Dir.pwd}/helpers/rake_helpers"
include RakeHelpers

desc 'Launch a server daemon with live reloading'
task :preview do
  # use system to pass the CTRL-D to the child process

desc 'Deploy the build folder to Github pages'
task :deploy do
  puts 'Removing existing build folder'
  `rm -rf build`
  puts 'Building and deploying site to master'
  `mgd --branch master`
  `git checkout source`

desc 'Create a post file and folder'
task :post, :title do |t, args|
  title = args[:title]
  slug = slugify(title)

  post_dir      = File.join('source', 'articles')
  post_filename = ["%F"), slug].join('-')
  post_path     = File.join(post_dir, "#{post_filename}")
  post_folder   = File.join(post_dir, post_filename)
  post = <<-POST
title: #{title}
date: #{"%F")}
layout: post

  File.write(post_path, post)