Skip to content

Instantly share code, notes, and snippets.

@vvps
Forked from flohei/jekyll-new-post.sh
Last active February 11, 2016 12:56
Show Gist options
  • Save vvps/911ccefb197b97cb9f3a to your computer and use it in GitHub Desktop.
Save vvps/911ccefb197b97cb9f3a to your computer and use it in GitHub Desktop.
This script creates a new blog post for Jekyll.
#!/bin/sh
# variables
title="New Post"
postdate=`date +%Y-%m-%d`
posttime=`date +%H:%M:%S`
timezone="+0100"
publishdate="$postdate $posttime $timezone"
tags=
categories=
openfile=true
# parameter handling
while getopts "n:t:c:l:d:p:o" arg
do
#echo "ARG is $arg"
case "$arg" in
n) title="$OPTARG";;
d) publishdate="$OPTARG"
postdate=`date -jf "%F %T" "$publishdate" +%Y-%m-%d`
posttime=`date -jf "%F %T" "$publishdate" +%H:%M:%S`;;
o) openfile=true;;
t) tags="$OPTARG";;
c) categories="$OPTARG";;
-) break;;
\?) ;;
*) echo "unhandled option $arg";;
?) echo $usage_string
exit 1;;
esac
done
# create the file name
lowercase=`echo $title | awk '{print tolower($0)}'`
stripped=`echo ${lowercase// /-}`
filename=$postdate-$stripped.md
file=$HOME/$filename
# create the file and add content
echo "---" >> $file
echo "layout: post" >> $file
echo "title: \"$title\"" >> $file
echo "date: $publishdate" >> $file
echo "tags: $tags" >> $file
echo "categories: $categories" >> $file
echo "---\n" >> $file >> $file
echo "TIL content goes here." >> $file
# open file if wanted
if $openfile; then
open $file
fi
# done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment