hugo: add post-process script to flatten markdown files

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
This commit is contained in:
David Karlsson
2026-01-12 13:42:20 +01:00
parent b619ed27d3
commit 58ca053f98
2 changed files with 23 additions and 0 deletions

22
hack/flatten-markdown.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/sh
set -e
# Flatten markdown files from public/path/to/page/index.md to public/path/to/page.md
# This makes markdown output links work correctly
PUBLIC_DIR="${1:-public}"
[ -d "$PUBLIC_DIR" ] || { echo "Error: Directory $PUBLIC_DIR does not exist"; exit 1; }
find "$PUBLIC_DIR" -type f -name 'index.md' | while read -r file; do
# Skip the root index.md
[ "$file" = "$PUBLIC_DIR/index.md" ] && continue
# Get the directory containing index.md
dir="${file%/*}"
# Move index.md to parent directory with directory name
mv "$file" "${dir%/*}/${dir##*/}.md"
done
echo "Flattened markdown files in $PUBLIC_DIR"