From d3df77e93b4f999511e218aa5b66e1832b46e8c6 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Mon, 2 Feb 2026 18:08:19 +0100 Subject: [PATCH] WIP:von-anderem-projekt --- src/main/resources/import-maven-site.sh | 82 +++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 src/main/resources/import-maven-site.sh diff --git a/src/main/resources/import-maven-site.sh b/src/main/resources/import-maven-site.sh new file mode 100755 index 0000000..1e895b0 --- /dev/null +++ b/src/main/resources/import-maven-site.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [ "$#" -ne 1 ]; then + echo "Usage: import-maven-site.sh " + exit 1 +fi + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +HUGO_ROOT="$1" + +command -v yq >/dev/null 2>&1 || { echo "yq is required"; exit 1; } + +YAML=$(sed -n '/MAVEN-NAVIGATION-BEGIN/,/MAVEN-NAVIGATION-END/p' "$SCRIPT_DIR/index.html" | sed '1d;$d') + +PATH_IN_HUGO_CONTENT=$(echo "$YAML" | yq -r '.path') + +TARGET="$HUGO_ROOT/content/$PATH_IN_HUGO_CONTENT" + +mkdir -p "$TARGET" + +declare -A MENU_PATH +declare -A MENU_HAS_ITEMS +declare -A MENU_DEPTH + +while IFS=$'\t' read -r path has_items href depth +do + href="${href#/}" + src="$SCRIPT_DIR/$href" + [ -f "$src" ] || continue + + MENU_PATH["$href"]="$path" + MENU_HAS_ITEMS["$href"]="$has_items" + MENU_DEPTH["$href"]="$depth" +done < <( echo "$YAML" | yq -r ' +def segment: + sub("\\.html$"; "") | ltrimstr("/"); +def walk(path): + if (.href | type) == "string" and .href != "" then + (path + [(.href | segment)]) as $newPath + | [ + ($newPath | join("/")), + ((.items | length) > 0), + .href, + ($newPath | length) + ], + (.items[]? | walk($newPath)) + else + (.items[]? | walk(path)) + end; +.menus[].items[] | walk([]) +| @tsv +') + +for href in "${!MENU_PATH[@]}" +do + src="$href" + path="${MENU_PATH[$href]}" + has_items="${MENU_HAS_ITEMS[$href]}" + + if [[ "$has_items" == "true" ]] + then + dst="${TARGET}${path}/_index.html" + else + dst="${TARGET}${path}.html" + fi + + case "$href" in + index.html) + dst="${TARGET}_index.html" + ;; + esac + + mkdir -p "$(dirname "$dst")" + cp -v "$src" "$dst" +done + +mkdir -p "$HUGO_ROOT/static/$PATH_IN_HUGO_CONTENT" +for i in $(find "$SCRIPT_DIR" -maxdepth 1 -mindepth 1 -type d) +do + cp -av "$i" "$HUGO_ROOT/static/$PATH_IN_HUGO_CONTENT" +done -- 2.39.5