From ce283130b6b92886f78b3aacf163c3883ffbbb5b Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 16 Jun 2026 18:19:58 +0000 Subject: [PATCH] Clean up and align import-in-hugo.sh and import-in-astro.sh Both scripts now share identical structure for argument parsing, validation, JSON extraction, and the HTML file loop: - CURRENT_BOOL variable (was: CURRENT converted to string in-place) - jq-quoted TITLE_YAML for safe YAML output - Skip files with no page entry (WARN + continue) in both scripts - Consistent output messages (Content:/Static:/Routing:) - Summary block at the end of both scripts import-in-hugo.sh fixes: - Remove debug output per file (echo "Found $FILE:", jq -C per entry) - Fix URL bug in directory redirect pages ($URL was last HTML file's URL) - Fix basename usage: basename "$SOURCE" not basename $SOURCE $SCRIPT_DIR - Quote all variable expansions - Fix inconsistent indentation in error blocks - Redirect page HTML: use properly quoted echo with single/double quotes import-in-astro.sh cleanup: - Remove inline comments that belong in CLAUDE.md - Simplify URL_BASE derivation to if/elif/else - Remove ENTRY_ID intermediate variable (inline into printf directly) Co-Authored-By: Claude Sonnet 4.6 --- src/main/resources/import-in-astro.sh | 70 +++--- src/main/resources/import-in-hugo.sh | 329 +++++++++++--------------- 2 files changed, 172 insertions(+), 227 deletions(-) mode change 100644 => 100755 src/main/resources/import-in-hugo.sh diff --git a/src/main/resources/import-in-astro.sh b/src/main/resources/import-in-astro.sh index 942504e..96b4d81 100755 --- a/src/main/resources/import-in-astro.sh +++ b/src/main/resources/import-in-astro.sh @@ -12,14 +12,16 @@ USAGE=$( (Default: artifactId from the Maven project metadata). --current : [DEFAULT] Marks this version as the current (visible) release. - Content URL: //page.html + Content URL: //page.html, params.current=true Routing: src/pages// - If is given, it overrides the URL base (default: //). ---archived : Marks this version as archived/snapshot (not visible by default). - Content URL: /projects///page.html + If is given, it overrides the URL base. + Only one of --current and --archived can be used! +--archived : Marks this version as archived (not visible by default). + Content URL: /projects///page.html, params.current=false Routing: src/pages/projects/// - params.canonical points to the corresponding page of the current version. + params.canonical points to the corresponding current-version page. If is given, it overrides the URL base. + Only one of --current and --archived can be used! --canonical : Explicitly sets the canonical URL base for --archived mode. Default: / Only valid with --archived. @@ -49,9 +51,6 @@ if [[ ! -f "$ASTRO_ROOT/package.json" ]]; then exit 1 fi -JSON=$(sed -n '/" >> "$TARGET" - echo "" >> "$TARGET" - echo "

View $TITLE

" >> "$TARGET" + if [[ -n "$PAGE_ENTRY" ]]; then + PAGE=$(echo "$PAGE_ENTRY" | jq '.value') + WEIGHT=$(echo "$PAGE_ENTRY" | jq -r '.key') + HREF=$(echo "$PAGE" | jq -r '.href') + TITLE_YAML=$(echo "$PAGE" | jq '.name') + PATH_PREFIX=$(echo "$PAGE" | jq -r '.path') + [[ -n "$PATH_PREFIX" && "${PATH_PREFIX: -1}" != "/" ]] && PATH_PREFIX="${PATH_PREFIX}/" + + TARGET="$HUGO_ROOT/content$PATH_BASE/${PATH_PREFIX}${DIR}/_index.html" + mkdir -p "$(dirname "$TARGET")" + + { + echo "---" + echo "title: $TITLE_YAML" + echo "weight: $WEIGHT" + echo "url: $URL_BASE/$DIR/" + echo "params:" + echo " current: $CURRENT_BOOL" + echo " canonical: $CANONICAL/$DIR/" + echo "---" + echo '' + echo '' + echo '

View '"$DIR"'

' + } > "$TARGET" + + echo "Redirect: $TARGET" fi done + +echo "" +echo "Done! Imported $PROJECT $VERSION (current=$CURRENT_BOOL)" +echo " Content: $HUGO_ROOT/content$PATH_BASE" +echo " Static: $HUGO_ROOT/static$URL_BASE" -- 2.39.5