Add new-post.sh

This commit is contained in:
akp 2025-05-25 17:47:14 +01:00
parent 88988a3d36
commit 8fd3aebdae

21
scripts/new-post.sh Normal file
View file

@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -eu
REPOSITORY_BASE=$(git rev-parse --show-toplevel) # get the absolute base directory of this repository
read -p "Enter the post slug: " POST_SLUG
read -p "Create directory? (y/N) " CREATE_DIR
echo
(
cd $REPOSITORY_BASE
if [[ "$CREATE_DIR" == [Yy]* ]]; then
OUTPUT_PATH="site/blog/$POST_SLUG/content.md"
mkdir -vp $(dirname $OUTPUT_PATH)
else
OUTPUT_PATH="site/blog/$POST_SLUG.md"
fi
cp -v site/blog/_template.md $OUTPUT_PATH
)