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