From 58ca053f9826ab68c4fc39a723b2799abdb8b11d Mon Sep 17 00:00:00 2001 From: David Karlsson <35727626+dvdksn@users.noreply.github.com> Date: Mon, 12 Jan 2026 13:42:20 +0100 Subject: [PATCH] hugo: add post-process script to flatten markdown files Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com> --- Dockerfile | 1 + hack/flatten-markdown.sh | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100755 hack/flatten-markdown.sh diff --git a/Dockerfile b/Dockerfile index aa4957bce5..2ec633711f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,6 +51,7 @@ ARG DOCS_URL="https://docs.docker.com" ENV HUGO_CACHEDIR="/tmp/hugo_cache" RUN --mount=type=cache,target=/tmp/hugo_cache \ hugo --gc --minify -e $HUGO_ENV -b $DOCS_URL +RUN ./hack/flatten-markdown.sh public # lint lints markdown files FROM ghcr.io/igorshubovych/markdownlint-cli:v0.45.0 AS lint diff --git a/hack/flatten-markdown.sh b/hack/flatten-markdown.sh new file mode 100755 index 0000000000..d055dc9bdb --- /dev/null +++ b/hack/flatten-markdown.sh @@ -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"