From 52eb43f4e1fe9906e094266a6dce7504bee86cab Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 3 May 2026 14:14:45 +0200 Subject: [PATCH] WIP --- src/main/resources/import-in-hugo.sh | 77 +++++++++++++++++----------- 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/src/main/resources/import-in-hugo.sh b/src/main/resources/import-in-hugo.sh index 1ff2c34..b263652 100644 --- a/src/main/resources/import-in-hugo.sh +++ b/src/main/resources/import-in-hugo.sh @@ -2,26 +2,28 @@ set -euo pipefail USAGE=$( - echo "Usage: $0 [--base ] [--project ] [--separator ] [ [ --current []] | [--archived []] ]"; + echo "Usage: $0 [--base ] [ [ --current []] | [--archived [] [--canonical ]] ]"; cat << EOF --base : Specifies the base-path for the rendered site. If not specifed, the site is rendered as a root section. The artifact-id and the version are always added to the path. ---project : Specifies the name of the project for path and url - (Default: ). - artifact-id and the version (Default: "/"). --current : [DEFAULT] - Adds "url: //" to front-matter. - If "" is not specified, "//" - is used. + Sets "url: //", "params.current=true" + and "params.canonical = /" in + front-matter. If "" is not specified, + "//" is used as "". Only one of "--current" and "--archived" can be used! ---archived : Adds "params.canonical=//" to - front-matter. - If "" is not specified, "//" - is used. +--archived : Sets "url: //", "params.current=false" + and "params.canonical = /" in + front-matter. If "" is not specified, + "//" is used as "" + If "" is not specified explicitly, + "/" is used as "" Only one of "--current" and "--archived" can be used! +--canonical : Explicitly specifies "" for "--archived". + Can only be specified when "--archived" is used! EOF ) @@ -36,9 +38,9 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) HUGO_ROOT="${1%%/}" shift -PROJECT="" CURRENT=0 ARCHIVED=0 +URL="" CANONICAL="" command -v jq >/dev/null 2>&1 || { echo "ERROR -- jq is required"; exit 1; } @@ -63,25 +65,15 @@ while [[ $# -gt 0 ]]; do fi shift 2 ;; - --project) - if [[ $# -lt 2 ]] - then - echo "ERROR -- Parameter for --project is missing!" - exit 1 - fi - PROJECT="${2%%/}" - PROJECT="${PROJECT##/}" - shift 2 - ;; --current) CURRENT=1 if [[ $# -lt 2 ]] then shift else - CANONICAL="${2%%/}" - CANONICAL="${CANONICAL##/}" - CANONICAL="/$CANONICAL" + URL="${2%%/}" + URL="${URL##/}" + URL="/$URL" shift 2 fi ;; @@ -91,12 +83,23 @@ while [[ $# -gt 0 ]]; do then shift else - CANONICAL="${2%%/}" - CANONICAL="${CANONICAL##/}" - CANONICAL="/$CANONICAL" + URL="${2%%/}" + URL="${URL##/}" + URL="/$URL" shift 2 fi ;; + --canonical) + if [[ $# -lt 2 ]] + then + echo "ERROR -- Parameter for --project is missing!" + exit 1 + fi + CANONICAL="${2%%/}" + CANONICAL="${CANONICAL##/}" + CANONICAL="/$CANONICAL" + shift 2 + ;; *) echo "ERROR -- Unknown parameter: $1" echo @@ -117,14 +120,26 @@ if [[ "$CURRENT" -eq 0 && "$ARCHIVED" -eq 0 ]] then CURRENT=1 fi +if [[ "$CURRENT" -eq 1 ]] +then + CURRENT="true" +fi echo "$JSON" | jq -C . -if [[ -z "$PROJECT" ]] +PROJECT=$(echo "$JSON" | jq -r '.artifactId') +VERSION=$(echo "$JSON" | jq -r '.version') + +if [[ -n "$URL" ]] then - PROJECT=$(echo "$JSON" | jq -r '.artifactId') + URL="${URL%/}" +else + URL="$BASE/$PROJECT" + if [[ "$ARCHIVED" -eq 1 ]] + then + URL="$URL/$VERSION" + fi fi -VERSION=$(echo "$JSON" | jq -r '.version') if [[ -n "$CANONICAL" ]] then -- 2.39.5