Add helpers for creating draft posts

This commit is contained in:
arne 2022-03-10 09:11:05 +01:00
commit 515866b0cb
3 changed files with 36 additions and 0 deletions

32
scripts/mkdraft.sh Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -o pipefail
if [ -z "$1" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo 'Usage: scripts/mkdraft.sh Title Of Your Post'
[ -z "$1" ] && exit 1 || exit
fi
# thx https://stackoverflow.com/a/29436423
function yes_or_no {
read -p "$* [y/N]: " yn
case $yn in
[Yy]*) return 0 ;;
*) echo "Aborted" ; return 1 ;;
esac
}
title="$@"
path="src/posts/drafts/$(date +%F)-$(echo -n $title | tr 'A-Z' 'a-z' | tr -c '[:alnum:]' -).md"
if [ -f $path ]; then
yes_or_no "$path already exists! Do you want to overwrite it?" || exit
fi
cat << EOF > $path
---
title: $title
---
# $title
EOF
echo "Created new draft in $path"