microblog automation via git and jekyll and shell scripts

A longer post explaining my setup, in case somebody else finds it useful.

So how do I do it:

first, I have a bare git repository on my webserver that acts as the master repository in to which all clients, that can post entrys push to. This repository I have called


for obvious reasons. Also on the server, there exists a clone of this bare repository that contains a working copy created via

git clone microblog.git

In order to make sure that this clone is always up-to-date, I have a post-receive-hook set in the config of the bare repository that looks like this:


cd ~/microblog
GIT_DIR=.git git pull origin master

so whenever I push to the bare repository from some other client (like e.g. on my laptop), the working copy on the server immediately does a pull.

Inside the repository lives a jekyll instance using the Hydejack theme. One relevant line in the ‘_config.yml’ file is

destination: /the/microblog/directory/in/the/webserver/

but also

      path: "_posts"
      layout: post
      title: ""

In this way, a new post can be created with minimal yaml frontmatter, i.e. only the ‘date:’ line is needed. Using the ‘title: “”’ trick creates microblog-like entries.

Now the workflow would be something like (on my laptop)

$ cd ~/microblog/_posts
$ vim 1971-01-01-01.md # here we need the date and a running numer
$ # now I edit the file, the yaml frontmatter needs
$ # date: 1971-01-01 00:00
$ # in between two sets of three dashes (---)
$ git add 1971-01-01-01.md
$ git commit -a -m 01
$ git push

On the server, in the checked out working copy directory, I have the following command running:

$ bundle exec jekyll build --watch

which means that as soon as a new entry appears (via the post-receive hook above), the jekyll site rebuilds itself. BUT this is still a pain in the ass, to be honest. I mean one would want to enter one command, type the actual content of the post, cause it to save and that’s it. So for that purpose I wrote myself a dumb bash script with the following content (has to be called inside ~/microblog/_posts)

# make a new entry for the microblog

# set up my variables
today=$(date +%F);
now=$(date +%F\ %H:%M);
filename=$today-$(printf "%02d" $iterator).md;

# make sure we have the hottest newest latest
git pull;

# determine the first available file for today
while [ -f $filename ]
  do iterator=$(($iterator+1));
  filename=$today-$(printf "%02d" $iterator).md;

# create the file
touch $filename;

# pre-populate the file
echo '---' >> $filename;
echo -n 'date: ' >> $filename;
echo $now >> $filename;
echo '---' >> $filename;
echo >> $filename;

# start editing
vim +star +4 $filename;

# and upload
git add $filename;
git commit -a -m $iterator;
git push;

echo all done with $filename;

And that’s how I do it. It is entirely possible that I forgot to mention some important detail in this description and it is also entirely possible that what I’m doing is overly complicated and/or completely wrongheaded. Also, I still need a nicer workflow for posting from my phone that basically replicates the above. That’s still a todo …