msfjarvis.dev/generate_post_skeleton.sh
Harsh Shandilya 82898c3cf7 [skip deploy] generate_post_skeleton: Properly concatenate args
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
2020-01-08 10:06:24 +05:30

21 lines
658 B
Bash
Executable File

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