master
Jay 2 years ago
parent 43c99e4b79
commit f664af0aa2

@ -3,36 +3,26 @@
# by: Jay/nq4t/@music_onhold # by: Jay/nq4t/@music_onhold
# usage: ./compose.sh [category] [title] # usage: ./compose.sh [category] [title]
# example: /compose.sh blog MY AWESOME BLOG TITLE NO YOU DON'T NEED TO ENCLOSE IT! # example: /compose.sh blog MY AWESOME POST TITLE NO YOU DON'T NEED TO ENCLOSE IT!
# run in the root of your site files/repository # run in the root of your site files/repository
# assumes categories are directories in root # assumes categories are directories in root
# Arguments and Variables # Variables and category argument
category=$1 category=$1
pd=$(date +'%Y-%m-%d') pd=$(date +'%Y-%m-%d')
pt=$(date +'%T') pt=$(date +'%T')
file=blog$$.md file=blog$$.md
title=$2 # Ditch the category argument
# I'm lazy. I want every indvidual word after shift 1
# the first one to be the title. No special # Read everything else as title.
# characters. Just cycle through them. title=$@
shift 2 # Let's write the front matter to our temp file.
for word in "$@" printf -- "---\ntitle: $title\nlayout: post\ndate: $pd $pt\nexcerpt_separator: <!--more-->\n---\n\n" >> $file
do # Write the post in whatever editor you want.
title="$title $1";
shift 1;
done
# Let's write the front matter to our file.
printf -- "---\ntitle: $title\nlayout: post\ndate: $pd $pt\nexcerpt_separator: <!--more-->\n---\n" >> $file
# Write the post in nano.
nano + $file nano + $file
# Make a lowercase copy of title.
# Rename the file and copy the post to the right directory.
t=${title,,} t=${title,,}
# Move the file to category/_posts replacing spaces with hyphen
mv $file $category/_posts/$pd-${t// /-}.md mv $file $category/_posts/$pd-${t// /-}.md
# Display some output to verify it's done.
printf "\nPost $title created in $category: $category/_posts/$pd-${t// /-}.md\n\n" printf "\nPost $title created in $category: $category/_posts/$pd-${t// /-}.md\n\n"

Loading…
Cancel
Save