Created
September 3, 2015 21:25
-
-
Save beforeyouknowit/2707b0705338873b9b07 to your computer and use it in GitHub Desktop.
Ashley's Jekyll New Post "jnpost" Bash Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ashley's Jekyll "jnpost" New Post script, based heavily on: | |
# http://nateeagle.com/2011/09/21/easier-post-creation-for-jekyll-with-bash/ | |
# This is intended to be run from the base of your Jekyll folder, NOT from within the _posts folder. | |
# On Mac, copy this 'jnpost` executable shell script into your /usr/local/bin folder, and chmod it to 700. | |
# Configuration | |
author="Firstname Lastname" | |
editor="subl" | |
# Presumed to have Sublime Text 2 or 3 installed with "subl" bash script in /usr/local/bin/ | |
format="markdown" | |
# Appends ".markdown" to the end of the filename | |
# Get layout via getopts (-l) | |
# -- | |
# http://wiki.bash-hackers.org/howto/getopts_tutorial | |
while getopts ":l:" opt; do | |
case $opt in | |
l) | |
layout=$OPTARG | |
;; | |
:) echo "$opt requires an argument" >&2 | |
exit 1 | |
;; | |
esac | |
done | |
# Set default layout config values | |
# http://www.cyberciti.biz/tips/howto-setting-default-values-for-shell-variables.html | |
: ${layout:="post"} | |
# Date codes: http://linux.about.com/od/commands/l/blcmdl1_date.htm | |
echo "---" | |
echo "Creating a new ${layout} for" `date +%A", "%B" "%e", "%Y`"." | |
echo "Enter the title:" | |
read title | |
# Turn spaces into dashes | |
# http://stackoverflow.com/questions/1469849/how-to-split-one-string-into-multiple-strings-in-bash-shell | |
for word in $title | |
do | |
dashedTitle=${dashedTitle}-${word} | |
done | |
# Convert title to lowercase | |
# http://stackoverflow.com/questions/2264428/converting-string-to-lower-case-in-bash-shell-scripting | |
# http://www.kclug.org/pipermail/kclug/2003-April/015084.html | |
dashedTitle="`echo ${dashedTitle} | tr '[A-Z]' '[a-z]'`" | |
# Create a filename with the date, dashed title, and format | |
filename="_posts/`date +%Y-%m-%d`${dashedTitle}.${format}" | |
echo $filename | |
touch $filename | |
# Add initial YAML frontmatter to the top of the new file: | |
echo "---" >> $filename | |
echo "layout: ${layout}" >> $filename | |
echo "title: \"${title}\"" >> $filename | |
echo "author: ${author}" >> $filename | |
echo "date: `date +%Y-%m-%d\ %T`" >> $filename | |
echo "tags: " >> $filename | |
echo "- HERE" >> $filename | |
echo "img: HERE.jpg" >> $filename | |
echo "thumb: HERE.jpg" >> $filename | |
echo "summary: HERE" >> $filename | |
echo "---" >> $filename | |
echo "" >> $filename | |
# date format: 2014-04-25 16:54:46 | |
# Open in preferred text editor and go to the end of the file ( + ) | |
# via http://stackoverflow.com/questions/268123/vim-how-to-start-inserting-at-the-end-of-the-file-in-one-step | |
${editor} + $filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment