generate_post_skeleton: Shellcheck cleanup

Also generify passing of title to not require quoting the entire
thing.

Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
This commit is contained in:
Harsh Shandilya 2019-06-20 19:06:05 +05:30
parent 08466309e3
commit a3a4ba7e57
1 changed files with 8 additions and 13 deletions

View File

@ -2,23 +2,18 @@
set -euo pipefail
base_template="
+++
date = \"%s\"
title = \"%s\"
slug = \"%s\"
tags = []
categories = []
+++
"
function create_post() {
local title filename postslug postdate
title="${1}"
if [ $# -lt 1 ]; then
echo -e "\033[01;31mProviding a title is a must!\033[0m"
return
else
title="${@}"
fi
postdate="$(date +"%Y-%m-%d")"
postslug="$(echo ${title:?} | tr -dc '[:alnum:][:space:]\n\r' | tr '[:upper:]' '[:lower:]' | sed 's/ /-/g')"
postslug="$(echo "${title}" | tr -dc '[:alnum:][:space:]\n\r' | tr '[:upper:]' '[:lower:]' | sed 's/ /-/g')"
filename="${postslug}.md"
printf "${base_template}" "${postdate}" "${title}" "${postslug}" > content/posts/"${filename}"
printf "+++\ndate = \"%s\"\ntitle = \"%s\"\nslug = \"%s\"\ntags = []\ncategories = []\n+++\n" "${postdate}" "${title}" "${postslug}" > content/posts/"${filename}"
}
create_post "${@}"