From: Mark Szymanski Date: Tue, 2 Nov 2010 01:49:57 +0000 (-0500) Subject: Added newpost plugin. Creates a new jekyll post with the current date, and a user... X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=1a045dea98f647ade67463125991f021a559c7fd;p=common%2Fbash_it.git Added newpost plugin. Creates a new jekyll post with the current date, and a user specified title. Even fills in the YAML Front Matter. Sorry if that seemed like bragging, I just wanted everyone to notice so they could make use of it better... --- diff --git a/plugins/jekyll.plugins.bash b/plugins/jekyll.plugins.bash index 31fb9a3..1933f07 100644 --- a/plugins/jekyll.plugins.bash +++ b/plugins/jekyll.plugins.bash @@ -1,5 +1,9 @@ newpost() { + # 'cd' into the local jekyll root + + cd "$JEKYLL_LOCAL_ROOT/_posts" + # Get the date for the new post's filename FNAME_DATE=$(date "+%Y-%m-%d") @@ -8,5 +12,45 @@ newpost() { read -p "Enter title of the new post: " POST_TITLE + # Convert the spaces in the title to hyphens for use in the filename + + FNAME_POST_TITLE=`echo $POST_TITLE | tr ' ' "-"` + + # Now, put it all together for the full filename + + FNAME="$FNAME_DATE-$FNAME_POST_TITLE.$JEKYLL_FORMATTING" + + # And, finally, create the actual post file. But we're not done yet... + + touch "$FNAME" + + # Write a little stuff to the file for the YAML Front Matter + + echo "---" >> $FNAME + + # Now we have to get the date, again. But this time for in the header (YAML Front Matter) of + # the file + + YAML_DATE=$(date "+%B %d %X") + + # Echo the YAML Formatted date to the post file + + echo "date: $YAML_DATE" >> $FNAME + + # Echo the original post title to the YAML Front Matter header + + echo "title: $POST_TITLE" >> $FNAME + + # And, now, echo the "post" layout to the YAML Front Matter header + + echo "layout: post" >> $FNAME + + # Close the YAML Front Matter Header + + echo "---" >> $FNAME + echo >> $FNAME + + # Open the file in your favorite editor + $EDITOR $FNAME }