Two New Jekyll Scripts
Every now and then I try to make the process of writing posts in Jekyll a bit more pleasant. Last time, I shared a script that was supposed to make the post creation process a bit easier. It turned out, though, that I almost never really use this script because of its complexity. There are just too many switches and configuration options. (Of which some don’t even work reliably.)
Though this script did not help me as much as I hoped it would, it led me to two new, extremely simple scripts in my toolchain.1
draft.sh
This one just takes the title of the new draft as an argument and creates the appropriate file markdown file inside my general purpose drafts folder on my Dropbox2 and opens it in TextMate.
#!/bin/sh
# variables
site_path=~/Sites/example.com
drafts_path=~/Dropbox/Drafts
title=$1
# create the file name
lowercase=`echo $title | awk '{print tolower($0)}'`
stripped=`echo ${lowercase// /-}`
filename=$stripped.md
file_path=$drafts_path/$filename
echo "File path: $file_path"
# create the file and add content
echo "---\n" >> $file_path
echo "title: \"$title\"" >> $file_path
echo "layout: post" >> $file_path
echo "published: false" >> $file_path
echo "categories: " >> $file_path
echo "tags: " >> $file_path
echo "date: " >> $file_path
echo "\n---\n" >> $file_path
echo "Content goes here." >> $file_path
# open file if wanted
mate $file_path
# done
exit 0
This way I get a basic post file and I can just start typing right away. I usually fill in details like tags, categories and the date later.
publish.sh
When I feel like publishing that new draft as a post on the site I could just locate it in Finder, move it to _posts
, rename it, open it, add the additional information, rebuild the site and upload it to my server.
publish.sh
takes the draft’s name as a single argument, renames it, moves it to _posts
and opens it in TextMate so I can make some final changes before going into build mode.
#!/bin/sh
# variables
site_path=~/Sites/flohei.de
drafts_path=~/Dropbox/Drafts
file_name=$1
file=$drafts_path/$file_name
# check if the draft exists
if [ ! -e $file ]; then
echo "draft $file does not exist"
exit 1
fi
# create the file name
post_date=`date +%Y-%m-%d`
target=$site_path/_posts/$post_date-$file_name
# move and open the file
mv $file $target
mate $target
exit 0
I’m rather confident that I will use these simple scripts way more often than the other bulky one.
Hope this helps.
I keep all my site-related scripts in a
_script
folder in my Jekyll site directory. This way I can easily access them when needed. ↩︎I switched to storing drafts on Dropbox because it’s way easier to access the files on there from my iOS devices via 1Writer (http://1writerapp.com), for example. ↩︎