2014/06/24 03:36:44

So, I've been wanting to put up some sort of blog here for a while now. Since this is hosted on Github, a static blog was appropriate. There's plenty of static blog generators out there (Jekyll probably being the most popular), but none of them appealed to me. Most of them are written in a slow, interpreted language like Ruby, or they are overkill for my needs.

Since *nix systems are already great at text processing, I decided to just roll my own using Markdown and some Bash scripts. What I came up with consists of three scripts:

  1. A script to generate non-blog pages
  2. A script to generate blog pages
  3. A script to create a new blog post; aliased to "blog" in my shell

(No link to script #3, so I'll show it here):

#!/bin/bash

BLOGPATH="$HOME/Projects/dorkster.github.com"
BLOGDATE="$(date -u +"%Y/%m/%d %H:%M:%S")"
BLOGFILE="$(echo $BLOGDATE | sed -e 's/\//-/g' -e 's/:/-/g' -e 's/ /_/g').md"
PAGETITLE="## $BLOGDATE"

vim /tmp/$BLOGFILE

if [ -r "/tmp/$BLOGFILE" ] && [ -d "$BLOGPATH/.git/" ]; then
    echo -e "$PAGETITLE\\n" | cat - /tmp/$BLOGFILE > "$BLOGPATH/markdown/blog/$BLOGFILE"
    rm /tmp/$BLOGFILE

    cd "$BLOGPATH"
    sh markdown/scripts/generate_blog.sh
    git add index.html blog*.html markdown/ images/
    git status
fi

It took a bit of time for me to put all this together, but it seems to work perfectly. I might make some later tweaks and additions (like an RSS feed), but this should be satisfactory for now.