Create script to help quickly generate multiple branch bundles

This commit is contained in:
Christian Wolf 2024-10-24 15:39:22 +02:00
parent d19cf32e12
commit d111bd5a50

53
scripts/create-stubs.sh Executable file
View File

@ -0,0 +1,53 @@
#!/bin/bash
if [ ! -d "content/albums" ]
then
echo "You are not in the correct directory. Aborting."
exit 1
fi
if [ -f "content/albums/_index.md" ]
then
echo "You already have an _index.md file. This looks like you are in the template."
echo "You need to run this script from the main page directory."
exit 1
fi
tmp=$(mktemp)
find content/albums -mindepth 1 -type d | while read dir
do
(
cd "$dir"
if [ -f _index.md ]
then
# echo "Skipping $dir"
exit 0
fi
echo "Marking creation of stub for $dir"
echo "$dir/_index.md" >> "$tmp"
)
done
cat "$tmp" | while read line
do
dirname="$(basename "$(dirname "$line")")"
escaped="$(echo "$dirname" | sed 's@-@!@' )"
IFS=! read weight name <<< "$escaped"
text="title: \"$name\"\nweight: $weight"
# echo -e "$text"
# npm run hugo -- new content "$line"
# sed "s@^title:.*@$text@@" -i "$line"
cat > "$line" << EOF
---
title: "$name"
weight: $weight
date: $(date -Iseconds)
draft: false
---
EOF
done
rm "$tmp"