Jekyll Setup

Posted on

Something I miss with using Jekyll is the ease of posting a URL or video that comes with a hosted platform like Tumblr. To get around this, I’ve set up a couple of simple scripts and shortcuts to help streamline the process of creating and publishing a new post. Before getting too far, I’ll just mention now that my current setup consist of Sublime Text 2, iA Writer and Alfred (with Powerpack), so if you’re not using these, this post might not be too helpful.

Firstly, I added a draft post template called link-template.md to a new folder called _drafts in my site directory. This contains the basic variables of a Jekyll post.

    ---
    layout: post
    type: link
    title: 
    link: 
    date: 
    ---

With this in place, I set up a shell script extension in Alfred to duplicate and rename the template file, and then open it in iA Writer. The keyword command in Alfred also takes a query parameter, which is used in conjunction with the date to name the new file.

alfred bash panel
    # copy file and rename by date + query
    cp ~/Sites/Github/aaronmoodie.github.com/_drafts/link-template.md ~/Sites/Github/aaronmoodie.github.com/_drafts/"`date '+%Y-%m-%d'`-{query}.md"

    # open file with iA Writer
    open $1 -a /Applications/iA\ Writer.app ~/Sites/Github/aaronmoodie.github.com/_drafts/"`date '+%Y-%m-%d'`-{query}.md"

This post then stays in _drafts untill it’s ready to be published. As I have my ‘Sites’ folder on Dropbox, I can edit this post from my mobile or iPad if needed. When it come time to publish, I move the post to the _posts dir (which can also be done via Alfred) and push to Github using another shell script set up in Alfred. Again, this command takes a query parameter, which is used as the commit comment.

    # change dir
    cd ~/Sites/Github/aaronmoodie.github.com

    # git commands
    git add .; git commit -m "update {query}"; git push

The last thing to address was an issue with the post date. As I’ve included the date with file name, this is used whenever Jekyll looks for a date variable. The problem is if you are posting more than once a day, the order is lost due to not having a time stamp. To fix this, we add a date: variable – including the time – to the top of the post which will override the date in the file name. Not being one to type this out each time, I installed a handy little Sublime Text extention insertdate, which inserts a date via key command. This does mean having to jump into Sublime before publishing though.

And that’s it. There are some other options such as Jekyll Post Creator which are a little more streamline, but being a big fan of iA Writer, I wanted to do as much of my composing there as possible.