]> juplo.de Git - maven-thymeleaf-skin/commitdiff
WIP
authorKai Moritz <kai@juplo.de>
Sun, 3 May 2026 12:14:45 +0000 (14:14 +0200)
committerKai Moritz <kai@juplo.de>
Sun, 3 May 2026 12:14:45 +0000 (14:14 +0200)
src/main/resources/import-in-hugo.sh

index 1ff2c347f38a495b3fe6387f7a62e5d6f54547fa..b263652c47c68c5dd1d26de6c8a831b592b098b4 100644 (file)
@@ -2,26 +2,28 @@
 set -euo pipefail
 
 USAGE=$(
-  echo "Usage: $0 <HUGO_ROOT> [--base <path>] [--project ]  [--separator ] [ [ --current [<canonical>]] | [--archived [<canonical>]] ]";
+  echo "Usage: $0 <HUGO_ROOT> [--base <path>] [ [ --current [<url>]] | [--archived [<url>] [--canonical <url>]] ]";
   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>).
-              artifact-id and the version (Default: "/").
 --current   : [DEFAULT]
-              Adds "url: <canonical>/<path_in_site>/" to front-matter.
-              If "<cononical>" is not specified, "<path>/<project>/"
-              is used.
+              Sets "url: /<url>/<path_in_site>", "params.current=true"
+              and "params.canonical = <url>/<path_in_site>" in
+              front-matter.  If "<url>" is not specified,
+              "<path>/<project>/" is used as "<url>".
               Only one of "--current" and "--archived" can be used!
---archived  : Adds "params.canonical=<canonical>/<path_in_site>/" to
-              front-matter.
-              If "<cononical>" is not specified, "<path>/<project>/"
-              is used.
+--archived  : Sets "url: /<url>/<path_in_site>", "params.current=false"
+              and "params.canonical = <canonical>/<path_in_site>" in
+              front-matter.  If "<url>" is not specified,
+              "<path>/<project>/<version>" is used as "<url>"
+              If "<canonical>" is not specified explicitly,
+              "<path>/<project>" is used as "<canonical>"
               Only one of "--current" and "--archived" can be used!
+--canonical : Explicitly specifies "<canonical>" 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