Create a draft

bin/draft: Adds a draft post. Drafts are apparently controversial, but I like to capture things with as little resistance as possible, so it fits my workflow.

Serve with bundle exec jekyll serve --drafts

#!/bin/bash
targetfile=_drafts/$(echo $* | sed -e "s/ /-/g").md
if [ ! -e $targetfile ] ; then
cat <<EOF > $targetfile
---
layout: post
title:  "DRAFT - $*"
categories: tk
---

$*

EOF
fi
vim $targetfile

Add a link

bin/addlink: Adds a link to my _draft/miscellaneous.md file. The idea is to capture an interesting link and write it up later.

TODO: produce a bullet for the link in an incoming links section

#!/bin/bash
lastlink=$(cat _drafts/miscellaneous.md | grep '^\[' | cut -d\] -f1 | sed 's/^\[//' | sort -nr | head -1)
nextlink=$(( $lastlink + 1 ))
echo "[$nextlink]: $1" >> _drafts/miscellaneous.md

Publish

bin/publish: Publish a draft. Checks for unfilled placeholders

TODO: use yaml to add published date

#!/bin/sh

for draft in $* ; do
    if [ -e "$draft" ] ; then
        if cat $draft | grep -i tk >/dev/null ; then
            echo "Error: $draft contains tk placeholders"
            exit 2
        fi
        if cat $draft | egrep 'published:.*false' >/dev/null ; then
            echo "Warning: $draft contains published: false in front matter"
        fi
        mv $1 _posts/$(date +"%Y-%m-%d")-$(basename $1)
    else
        echo "Error: $draft not found"
        exit 1
    fi
done

Categories

bin/update_categories: Grab the list of categories from the front matter of posts and create a category page if it doesn’t exist.

TODO: tags!

#!/bin/bash

tc () { echo $1 | gsed -e 's/\<./\U&/'; }

for post in _posts/* ; do
  for category in $( grep categories: $post | sed 's/categories://' ) ; do
    echo $category
    if [ -e category/$category.html ] ; then
      echo category/$category.html already exists
    else
      cat <<EOF > category/$category.html
---
layout: category
title: $(tc $category)
category: $category
---
EOF
    fi
  done
done

This page is generated by doing this:

cd _includes/
ln -s ../bin/* .
history

and then formatting the code blocks with

{% highlight bash %}
{% include update_categories %}
{% endhighlight %}

BTW - I had to use {% raw %} in that block so it wouldn’t process the Liquid template