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
)
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; }
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
;;
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
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