Jekyll Plugins Hosted on github.io

Github is great for hosting your static site using jekyll. It’s free and is not ad-supported. One of the only drawbacks is that jekyll plugins won’t be run when you push code to your repo. There several workarounds for this limitation, one of which is described here: http://www.sitepoint.com/jekyll-plugins-github/.

Another approach involves two git repos: one for the jekyll code, and another one for the generated static html/js/css/image assets. Assuming you already have a jekyll site setup, this is how you’d get started. After you’ve run jekyll build, cd to _site and initialize a git repo, add all the files and commit:

$ cd _site
$ git init .
$ git commit -a -m 'Intial commit'

Now move the resuling .git directory so that it is a sibling of the jekyll directory, and give it a more descriptive name:

$ mv .git ../../atongen.github.io

Finally, set the git core.worktree configuration item so that it points back to the static html in _site:

$ cd ../../atongen.github.io
$ git config core.worktree path/to/jekyll/_site

At this point, the contents of your static html directory will look like a bare git repo, but it’s not! It just has a detached work tree. You can now push this repo to your hosted github user or project repo. The benefit here is that you can use plugins with jekyll and delete and re-build the entire _site directory without worrying about .git directory.

Related Posts