diff --git a/scripts/create-stubs.sh b/scripts/create-stubs.sh new file mode 100755 index 0000000..2eb32fb --- /dev/null +++ b/scripts/create-stubs.sh @@ -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"