Middleman Deploy to Github User Pages


Middleman has come a long ways and so have my habits. My blog is now running a stock version of the latest Middleman App.

I wanted to share this very simple rake task for deploying to Github User Pages.

Add Rake to Gemfile

gem "rake"

and remember to

bundle install --path=vendor

Deploy Rake Task

desc "Deploy"
task :deploy do

  puts 'do build'

  # build folder
  system "rm -rf build"
  system "mkdir build"

  # git
  Dir.chdir("build") do
    system "git init ."
    system "git remote add origin git@github.com:YOUR_ACCOUNT/YOUR_REPO.git"
    system "git checkout --orphan gh-pages"

  # do build
  system "bundle exec middleman build"

  # push build
  Dir.chdir("build") do
    system "git add -A"
    system "git commit -m build"
    system "git push -uf origin gh-pages"

NOTE: this is for a project page; if this is a user page you need to put your code in a source branch and have this publish into master.

Try it out

bundle exec rake deploy

Note the greatness

Happy blogging!