Middleman and Github pages
Asked Answered
A

4

10

I'm trying to create a static site using Middleman. The git repo master has the source files. The static files are generated in the build folder which is in .gitignore. I have a branch gh-pages for Github pages. How do I setup things such that the gh-pages has contents of the build folder of master.

Thanks.

Allsun answered 4/8, 2012 at 13:53 Comment(0)
H
8

Looks like this gem provides an elegant solution:

middleman-gh-pages

Horseplay answered 17/1, 2013 at 3:3 Comment(0)
A
6

I've started using the same technique as Octopress uses, it works great for Middleman.

Basically I use two git repositories, one inside the root folder and one inside the build folder. The root repository pushes to the develop branch on the GitHub remote and excludes the build directory. The repository inside the build directory pushes to the master (or gh-pages) branch of the same GitHub remote.

To automate the pushing of the new static pages, I use the following Rakefile:

desc "deploy build directory to github pages"
task :deploy do
  puts "## Deploying branch to Github Pages "
  cp_r ".nojekyll", "build/.nojekyll"
  cd "build" do
    system "git add ."
    system "git add -u"
    puts "\n## Commiting: Site updated at #{Time.now.utc}"
    message = "Site updated at #{Time.now.utc}"
    system "git commit -m \"#{message}\""
    puts "\n## Pushing generated website"
    system "git push origin master"
    puts "\n## Github Pages deploy complete"
  end
end
Amerson answered 13/10, 2012 at 22:0 Comment(0)
E
2

Another good gem is middleman-deploy. After you have installed it and configured everything, you can simply run

$ middleman deploy 

and your build directory will be pushed to GitHub pages. You can specify which branch you push to in the config. I also have a blog post here regarding switching from Jekyll to GitHub pages and it talks a little about deployment.

Equalizer answered 1/9, 2013 at 0:25 Comment(0)
A
0

I couldn't find a clean way of doing this. This is a script I've been using:

bundle exec middleman build
mv build /tmp/

git checkout gh-pages
git rm -rf .
cp -r /tmp/build/* .
git add .
git commit -m "Update site"

rm -rf /tmp/build

git push
git checkout master
Allsun answered 14/8, 2012 at 6:38 Comment(1)
do you know of a cleaner way since then ?Thain

© 2022 - 2024 — McMap. All rights reserved.