Script to Publish a Jekyll Post

I really hate typing dates. Home row is easy, but I typo numbers and symbols frequently. After publishing two posts manually, I decided to look for a script to help out and found jekyll-compose which has similar command under publish. Unfortunately, it didn’t timestamp the files and it didn’t intend to integrate with any SCM.

I really wanted something that would make all the changes, git mv the file, and then prompt me to commit it, so I wrote this gist (gist styling is different from the rest of the code on the site, so I’ve included the file as markdown).

# Fork from
set -euo pipefail

# Move jekyll draft to post, timestamp it, and start to commit it

# Useage:
#   $ ./ _draft/cool-article.markdown
# moves the draft to _posts/2017-12-01-cool-article.markdown
# inserts the published date into the "front matter"
# adds the changes and prompts you to commit them

shortname=$(basename -s .markdown $original)
newfile="_posts/$(date -I)-${shortname}.markdown";

sed -i "2 i date: $(date '+%F %T %z')" $original
git mv "$original" "$newfile"
git add $newfile
git commit -e -m "publish $shortname"