Add helpers for creating draft posts
This commit is contained in:
parent
86d216fb08
commit
515866b0cb
3 changed files with 36 additions and 0 deletions
32
scripts/mkdraft.sh
Executable file
32
scripts/mkdraft.sh
Executable 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"
|
||||
3
src/posts/drafts/.gitignore
vendored
Normal file
3
src/posts/drafts/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
*
|
||||
!drafts.json
|
||||
!.gitignore
|
||||
1
src/posts/drafts/drafts.json
Normal file
1
src/posts/drafts/drafts.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"draft": true}
|
||||
Loading…
Add table
Add a link
Reference in a new issue