Skip to content

Instantly share code, notes, and snippets.

@zormit
Forked from xianny/jekyll-new
Last active February 22, 2017 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zormit/87b8635761363079a6d409875a563215 to your computer and use it in GitHub Desktop.
Save zormit/87b8635761363079a6d409875a563215 to your computer and use it in GitHub Desktop.
jekyll-new-post
#!/bin/bash
# This script creates a new post or draft in jekyll with pre-filled front matter
# ./script some title for your post
# use -d option for draft
FILEDIR="_posts/"
while getopts "d" opt; do
case $opt in
d)
FILEDIR="_drafts/"
;;
esac
done
shift $((OPTIND-1))
if [ ! -d "$FILEDIR" ]; then
mkdir $FILEDIR
fi
TITLE=""
for word in $@
do
TITLE+="-$word"
done
FILENAME="$FILEDIR$(date +%Y-%m-%d)$TITLE.md"
echo "---" > $FILENAME
if [ $# -gt 0 ]
then
echo "title: \"$@\"" >> $FILENAME
fi
echo "layout: post" >> $FILENAME
echo "date: $(date +%Y-%m-%d) $(date +%T) $(date +%z)" >> $FILENAME
echo "tags: " >> $FILENAME
echo "categories: " >> $FILENAME
echo "---" >> $FILENAME
gedit $FILENAME &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment