Deploy Jekyll Site To Github With Make
At risks of being too meta, I want to talk about how this post is going to go
from my computer to a repository on Github on both the master
and gh-pages
branch. The former contains the file I'm typing, and the latter an updated
HTML site generated by Jekyll.
Here's how: I type make deploy
once I commit this file in my local
repository.
I spent a day to set up a Jekyll site. The last part involves deploying it to Github, my preferred way to host a static site. There are a lot of posts and scripts on how to achieve it. And Github seems to have an "afficial" support for Jekyll site that disables plugin scripts (understandably so).
But having worked with git and make for all these years made me immune to all the fanciness the Internet tries to sell.
Here's my script for deploying a Jekyll project to Github pages:
DEPLOY_PATH=/tmp/jekyll_deploy
build:
jekyll build
deploy:
git checkout -f gh-pages
git clean -d -x -f
git pull
git checkout master
jekyll build
rm -rf ${DEPLOY_PATH}
mkdir ${DEPLOY_PATH}
cp -R .git ${DEPLOY_PATH}
cd ${DEPLOY_PATH}; git checkout gh-pages; git clean -d -x -f
cp -R _site/* ${DEPLOY_PATH}
cd ${DEPLOY_PATH}; git add .; git commit -m "`curl whatthecommit.com/index.txt`"
cd ${DEPLOY_PATH}; git push -f origin gh-pages
Drop it into root of your Jekyll project, commit all changes (including the
Makefile
). And type make deploy
. BOOM, done.
There are a couple of assumptions:
- You build the site in the
_site
folder - You store Jekyll source on
master
and have thegh-pages
branch up. - You can build the site by running
jekyll build
. - You don't care about commit message on the deploy branch.
I like it better than other methods because it does not require installing additional software/scripts and there's no restriction on plugins.