--- /dev/null
+#!/usr/bin/env bash
+set -euo pipefail
+
+if [ "$#" -ne 1 ]; then
+ echo "Usage: import-maven-site.sh <path-to-hugo-content-root>"
+ 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