Skip to content

Commit 58ca053

Browse files
committed
hugo: add post-process script to flatten markdown files
Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
1 parent b619ed2 commit 58ca053

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ ARG DOCS_URL="https://docs.docker.com"
5151
ENV HUGO_CACHEDIR="/tmp/hugo_cache"
5252
RUN --mount=type=cache,target=/tmp/hugo_cache \
5353
hugo --gc --minify -e $HUGO_ENV -b $DOCS_URL
54+
RUN ./hack/flatten-markdown.sh public
5455

5556
# lint lints markdown files
5657
FROM ghcr.io/igorshubovych/markdownlint-cli:v0.45.0 AS lint

hack/flatten-markdown.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Flatten markdown files from public/path/to/page/index.md to public/path/to/page.md
5+
# This makes markdown output links work correctly
6+
7+
PUBLIC_DIR="${1:-public}"
8+
9+
[ -d "$PUBLIC_DIR" ] || { echo "Error: Directory $PUBLIC_DIR does not exist"; exit 1; }
10+
11+
find "$PUBLIC_DIR" -type f -name 'index.md' | while read -r file; do
12+
# Skip the root index.md
13+
[ "$file" = "$PUBLIC_DIR/index.md" ] && continue
14+
15+
# Get the directory containing index.md
16+
dir="${file%/*}"
17+
18+
# Move index.md to parent directory with directory name
19+
mv "$file" "${dir%/*}/${dir##*/}.md"
20+
done
21+
22+
echo "Flattened markdown files in $PUBLIC_DIR"

0 commit comments

Comments
 (0)