Skip to content

Instantly share code, notes, and snippets.

@AlexRiina

AlexRiina/publish.sh

Last active Dec 1, 2017
Embed
What would you like to do?
Publish Jekyll posts using simple git workflow
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# Move jekyll draft to post, timestamp it, and start to commit it
# Useage:
# $ ./publish.sh _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
original=$1
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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment