From 8bcd9699c3b7b32983155f7eab022802af17ac2e Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Thu, 6 Sep 2018 13:11:00 -0400 Subject: make new-post.sh script --- new-post.sh | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 new-post.sh diff --git a/new-post.sh b/new-post.sh new file mode 100755 index 0000000..4ff0637 --- /dev/null +++ b/new-post.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +set -e + +numargs=2 +function usage { + echo "Usage: $0 [options] +Options: + -i Create image directory + -d \"YYYY-MM-DD\" Custom date to use instead of today + -V Verbose + -x Dry run, don't make any changes +" + exit 1 +} + +td=$(date "+%Y-%m-%d") + +while [ "$(echo $1 | head -c1)" = '-' -o "$#" -gt $numargs ]; do + arg="$1" + shift + + case "$arg" in + "-i") IMG_DIR=1;; + "-d") td=$1; shift;; + "-V") VERBOSE=1;; + "-x") DRY_RUN=1;; + *) + echo "Unknown option '$arg'" + usage;; + esac +done + +if [ "$#" != $numargs ]; then usage; fi + +if [ ! -z $VERBOSE ]; then set -x; fi + +title="$1" +clean_title=$(echo "$title" |\ + tr '[:upper:]' '[:lower:]' |\ + sed 's/[^a-z0-9 ]//g' |\ + tr ' ' '-' \ + ) + +description="$2" +if $(echo "$description" | grep -q '[^.$!]$'); then + echo 'Description needs to be a complete sentence, with ending punctuation.' + exit 1 +fi + +postFileName=_posts/$td-$clean_title.md +echo "Creating $postFileName" +postContent=$(cat <- + $title +description: >- + $description +--- + +Write stuff here, title will automatically be added as an h1 + +## Secondary header + +Title is already h1 so all sub-titles should be h2 or below. +EOF +) + +if [ -z $DRY_RUN ]; then + echo "$postContent" > "$postFileName" +fi + +if [ ! -z $IMG_DIR ]; then + imgDirName="img/$clean_title" + echo "Creating directory $imgDirName" + if [ -z $DRY_RUN ]; then + mkdir -p "$imgDirName" + fi +fi -- cgit v1.2.3