Blogging workflow using git and Jekyll
I've long been searching for a quick and easy solution for my website. Looking at Wordpress, Typo3 and all the other contentn management systems out there requiring a "huge" setup of PHP, MySQL and other packages, this was never a feasible solution for me. After countless hours of research I've stumbled upon Jekyll, a static site generator. Jekyll is based on ruby and comes with a template engine called Liquid. This allows for building static websites easily without the need to manually edit HTML files. It is a perfect match for my needs and may also be a good solution for you:
Since I work on multiple systems from multiple places I wanted to run with a minimal setup on the client side. This is why I chose git-scm which is a Windows git implementation. git is available on windows, Linux and OSX so it is a good solution to start with. For the editor I use Sublime Text which also runs on multiple platforms and works well for many languages like C, Cpp, Python, Ruby and - of course - markdown. Blogposts are made of text - the content - and some supportive images (unless it is an art gallery or somewhat. But that's what tumblr, Deviantart and such services are for). Markdown is a "language" which does not hide the markup from the author while writing. The writing style is very similar to what you would expect when editing Wikipedia. Those two programs are all you need to get started with Jekyll on the client side.
I'm hosting on Uberspace which is a hosting company letting me choose to pay whatever I want for their services. Unfortunately they only offer their services within Germany so you might want to find another company for your setup. Uberspace does trust their users being able to use the console, which is great because it enables me to use git on the command line and create a repository in my home directory ( /home/einball/nerdhybride ) on the server. This repository holds the entire Jekyll installation, much like Github Pages. Whenever I want wo work on a blogpost I just clone the repo and start writing. When I'm done or I want to see how a draft I'm working on looks like, I commit and push the files to the repository. This triggers a so called " post-receive hook" which is a functionality built into git. It allows you to execute code for automated testing, cleanup or deployment operations. This is what my post-receive hook located in /home/einball/nerdhybride/hooks/post-receive looks like:
GIT_REPO = einball@localhost:$HOME/nerdhybride/ TEMPBUILDDIR = $HOME/tmp/ git clone $GIT_REPO $TEMPBUILDDIR > /dev/null jekyll build -t --source $TEMPBUILDDIR --destination $TEMPBUILDDIR../tmpbuild/ RETVAL=$? [ $RETVAL -eq 0 ] && echo "Copying to production folder" [ $RETVAL -eq 0 ] && rm -rf /var/www/virtual/einball/html/* [ $RETVAL -eq 0 ] && cp -r $TEMPBUILDDIR/../tmpbuild/* /var/www/virtual/einball/html/ echo "Deleting build folders" rm -rf $TEMPBUILDDIR $TEMPBUILDDIR/../tmpbuild/
It first clones the repository to a temporary folder, starts a jekyll build and reports the status of the build. If it was a success, e.g. no syntax errors occurred in the files, it will delete the files in the production folder and replace them with the current build output. The temporary build folder will be deleted thereafter.
It's a pretty simple, but effective setup, isn't it?