From bed8ff4b8555a18a96052a63ef26563f9c618151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Cuadrado=20Juan?= Date: Tue, 19 May 2026 16:04:08 +0200 Subject: [PATCH 1/5] feat: generate static HTML redirect files for old Docusaurus URLs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add scripts/generate-redirects.sh, which creates meta-refresh HTML files at old flat paths (e.g. /reference/threat-model/index.html) pointing to the new Antora URL structure (/admc/1.35/en/...). Wire into both `make community-remote` and `make community-local` targets so GitHub Pages serves the redirects without needing server-side configuration. Signed-off-by: Víctor Cuadrado Juan --- Makefile | 8 ++++ scripts/generate-redirects.sh | 69 +++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100755 scripts/generate-redirects.sh diff --git a/Makefile b/Makefile index cfb6cf79c7..937f4d13d2 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,10 @@ community-local: tmpdir environment kw-local-community-playbook.yml \ 2>&1 | tee -a tmp/community-local-build.log cd build-local-community/site && ln -s kubewarden/latest latest + ./scripts/generate-redirects.sh \ + docs/admc/version-1.35/modules/en/pages \ + build-local-community/site \ + /admc/1.35/en @echo @echo "If your build was successful, you can preview the site with" @echo "'make preview-local-community'. The server needs to be used, viewing" @@ -30,6 +34,10 @@ community-remote: tmpdir environment kw-remote-community-playbook.yml \ 2>&1 | tee -a tmp/community-remote-build.log cd build/site && ln -s kubewarden/latest latest + ./scripts/generate-redirects.sh \ + docs/admc/version-1.35/modules/en/pages \ + build/site \ + /admc/1.35/en .PHONY: community-remote-netlify community-remote-netlify: tmpdir environment diff --git a/scripts/generate-redirects.sh b/scripts/generate-redirects.sh new file mode 100755 index 0000000000..b04db68c5e --- /dev/null +++ b/scripts/generate-redirects.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +# generate-redirects.sh +# +# Generates static HTML meta-refresh redirect files for old flat Docusaurus- +# style URLs, pointing them at the equivalent page in the new Antora structure. +# +# Usage: ./generate-redirects.sh +# pages-dir path to the Antora modules/en/pages directory +# site-output-dir path to the built site root (e.g. build/site) +# antora-prefix URL prefix for new pages (e.g. /admc/1.35/en) +# +# Example: +# ./generate-redirects.sh \ +# docs/admc/version-1.35/modules/en/pages \ +# build/site \ +# /admc/1.35/en + +set -euo pipefail + +PAGES_DIR="${1:?pages-dir argument required}" +SITE_DIR="${2:?site-output-dir argument required}" +ANTORA_PREFIX="${3:?antora-prefix argument required}" + +if [ ! -d "$PAGES_DIR" ]; then + echo "ERROR: pages directory not found: $PAGES_DIR" >&2 + exit 1 +fi + +if [ ! -d "$SITE_DIR" ]; then + echo "ERROR: site output directory not found: $SITE_DIR" >&2 + exit 1 +fi + +count=0 + +while IFS= read -r -d '' adoc; do + # Derive the relative path from the pages root, without the .adoc extension + rel="${adoc#"$PAGES_DIR"/}" + rel="${rel%.adoc}" + + new_url="${ANTORA_PREFIX}/${rel}.html" + out_file="${SITE_DIR}/${rel}/index.html" + + # Skip if a real file already exists at this path (Antora owns it) + if [ -e "${SITE_DIR}/${rel}.html" ] || [ -d "${SITE_DIR}/${rel}" ]; then + continue + fi + + mkdir -p "$(dirname "$out_file")" + + cat > "$out_file" < + + + + + + Redirecting... + + +

This page has moved. Click here if you are not redirected.

+ + +HTML + + count=$((count + 1)) +done < <(find "$PAGES_DIR" -name "*.adoc" -not -name "nav.adoc" -print0) + +echo "Generated ${count} redirect file(s) under ${SITE_DIR}." From 0c51d131c62aa3bc4432ebc8b91e52b5f157c96e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Cuadrado=20Juan?= Date: Tue, 19 May 2026 16:12:19 +0200 Subject: [PATCH 2/5] chore: Drop Netlify redirects, not needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Víctor Cuadrado Juan --- netlify.toml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/netlify.toml b/netlify.toml index 3c6213fd6e..8260b4f0ea 100644 --- a/netlify.toml +++ b/netlify.toml @@ -5,14 +5,3 @@ command = "make community-remote-netlify" #[build.environment] # NODE_OPTIONS = "--max_old_space_size=4096" - -# Redirect old Docusaurus-style URLs (/) to the new Antora URLs -# (/admc/1.35/en/). -# Netlify serves existing files directly, so this only fires for paths that -# don't have a real file in the build output (the old doc URLs). -# Netlify pretty URL feature automatically adds the .html on the new Antora -# URLs. -[[redirects]] -from = "/*" -to = "/admc/1.35/en/:splat" -status = 301 From 55af7e23849994bcce1f2fc1560a0ebf6ea89cd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Cuadrado=20Juan?= <2196685+viccuad@users.noreply.github.com> Date: Thu, 21 May 2026 14:55:54 +0200 Subject: [PATCH 3/5] Skip creating redirect if antora created a file in that path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Víctor Cuadrado Juan <2196685+viccuad@users.noreply.github.com> --- scripts/generate-redirects.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/generate-redirects.sh b/scripts/generate-redirects.sh index b04db68c5e..b4a1b3a60b 100755 --- a/scripts/generate-redirects.sh +++ b/scripts/generate-redirects.sh @@ -40,9 +40,12 @@ while IFS= read -r -d '' adoc; do new_url="${ANTORA_PREFIX}/${rel}.html" out_file="${SITE_DIR}/${rel}/index.html" + antora_html_file="${SITE_DIR}/${rel}.html" + antora_index_file="${SITE_DIR}/${rel}/index.html" - # Skip if a real file already exists at this path (Antora owns it) - if [ -e "${SITE_DIR}/${rel}.html" ] || [ -d "${SITE_DIR}/${rel}" ]; then + # Skip only if Antora already produced a real page at this path. + # Otherwise, overwrite the redirect deterministically on each run. + if [ -e "$antora_html_file" ] || [ -e "$antora_index_file" -a "$antora_index_file" != "$out_file" ]; then continue fi From 63bc8125a36b728ccd02cdfe9e05352cfb09a3f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Cuadrado=20Juan?= Date: Thu, 21 May 2026 15:00:23 +0200 Subject: [PATCH 4/5] fix: derive redirect targets from built output instead of source tree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Generate redirects by scanning the HTML files Antora produced under the antora prefix in the built site, rather than the local .adoc source tree. This ensures the redirect list always matches the actual build output, regardless of which branch or remote Antora pulled content from. Also drop the now-unnecessary PAGES_DIR argument from generate-redirects.sh Signed-off-by: Víctor Cuadrado Juan --- Makefile | 6 ++-- scripts/generate-redirects.sh | 62 ++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index 937f4d13d2..b8b2525726 100644 --- a/Makefile +++ b/Makefile @@ -17,9 +17,8 @@ community-local: tmpdir environment 2>&1 | tee -a tmp/community-local-build.log cd build-local-community/site && ln -s kubewarden/latest latest ./scripts/generate-redirects.sh \ - docs/admc/version-1.35/modules/en/pages \ build-local-community/site \ - /admc/1.35/en + admc/1.35/en @echo @echo "If your build was successful, you can preview the site with" @echo "'make preview-local-community'. The server needs to be used, viewing" @@ -35,9 +34,8 @@ community-remote: tmpdir environment 2>&1 | tee -a tmp/community-remote-build.log cd build/site && ln -s kubewarden/latest latest ./scripts/generate-redirects.sh \ - docs/admc/version-1.35/modules/en/pages \ build/site \ - /admc/1.35/en + admc/1.35/en .PHONY: community-remote-netlify community-remote-netlify: tmpdir environment diff --git a/scripts/generate-redirects.sh b/scripts/generate-redirects.sh index b4a1b3a60b..22ef516b4a 100755 --- a/scripts/generate-redirects.sh +++ b/scripts/generate-redirects.sh @@ -2,55 +2,57 @@ # generate-redirects.sh # # Generates static HTML meta-refresh redirect files for old flat Docusaurus- -# style URLs, pointing them at the equivalent page in the new Antora structure. +# style URLs, pointing them at the equivalent pages in the new Antora structure. # -# Usage: ./generate-redirects.sh -# pages-dir path to the Antora modules/en/pages directory -# site-output-dir path to the built site root (e.g. build/site) -# antora-prefix URL prefix for new pages (e.g. /admc/1.35/en) +# Instead of reading source .adoc files, this script derives redirect targets +# from the HTML files that Antora actually produced under ANTORA_PREFIX in the +# built site. This guarantees the redirect list matches the real build output, +# regardless of which branch or remote Antora pulled content from. +# +# Usage: ./scripts/generate-redirects.sh +# site-output-dir path to the built site root (e.g. build/site) +# antora-prefix path under site-output-dir where Antora pages live +# (e.g. admc/1.35/en) # # Example: -# ./generate-redirects.sh \ -# docs/admc/version-1.35/modules/en/pages \ -# build/site \ -# /admc/1.35/en +# ./scripts/generate-redirects.sh build/site admc/1.35/en set -euo pipefail -PAGES_DIR="${1:?pages-dir argument required}" -SITE_DIR="${2:?site-output-dir argument required}" -ANTORA_PREFIX="${3:?antora-prefix argument required}" +SITE_DIR="${1:?site-output-dir argument required}" +ANTORA_PREFIX="${2:?antora-prefix argument required}" -if [ ! -d "$PAGES_DIR" ]; then - echo "ERROR: pages directory not found: $PAGES_DIR" >&2 +if [ ! -d "$SITE_DIR" ]; then + echo "ERROR: site output directory not found: $SITE_DIR" >&2 exit 1 fi -if [ ! -d "$SITE_DIR" ]; then - echo "ERROR: site output directory not found: $SITE_DIR" >&2 +ANTORA_DIR="${SITE_DIR}/${ANTORA_PREFIX}" + +if [ ! -d "$ANTORA_DIR" ]; then + echo "ERROR: antora prefix directory not found: $ANTORA_DIR" >&2 exit 1 fi count=0 -while IFS= read -r -d '' adoc; do - # Derive the relative path from the pages root, without the .adoc extension - rel="${adoc#"$PAGES_DIR"/}" - rel="${rel%.adoc}" +while IFS= read -r -d '' html; do + # Derive the page path relative to the antora prefix dir, without .html + rel="${html#"$ANTORA_DIR"/}" + rel="${rel%.html}" - new_url="${ANTORA_PREFIX}/${rel}.html" - out_file="${SITE_DIR}/${rel}/index.html" - antora_html_file="${SITE_DIR}/${rel}.html" - antora_index_file="${SITE_DIR}/${rel}/index.html" + # The old flat URL path (what users had bookmarked under Docusaurus) + flat_dir="${SITE_DIR}/${rel}" + out_file="${flat_dir}/index.html" + new_url="/${ANTORA_PREFIX}/${rel}.html" - # Skip only if Antora already produced a real page at this path. - # Otherwise, overwrite the redirect deterministically on each run. - if [ -e "$antora_html_file" ] || [ -e "$antora_index_file" -a "$antora_index_file" != "$out_file" ]; then + # Skip if the flat path is already claimed by Antora output + if [ -e "${SITE_DIR}/${rel}.html" ]; then continue fi - mkdir -p "$(dirname "$out_file")" - + # Overwrite unconditionally so version bumps to ANTORA_PREFIX always take effect + mkdir -p "$flat_dir" cat > "$out_file" < @@ -67,6 +69,6 @@ while IFS= read -r -d '' adoc; do HTML count=$((count + 1)) -done < <(find "$PAGES_DIR" -name "*.adoc" -not -name "nav.adoc" -print0) +done < <(find "$ANTORA_DIR" -name "*.html" -not -name "index.html" -print0) echo "Generated ${count} redirect file(s) under ${SITE_DIR}." From 305178a072466797f62237f2825784099a42ef3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Cuadrado=20Juan?= Date: Thu, 21 May 2026 16:22:20 +0200 Subject: [PATCH 5/5] feat: Also generate redirects for community-remote-netlify target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Víctor Cuadrado Juan --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index b8b2525726..45a4e6df6d 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,9 @@ community-remote-netlify: tmpdir environment kw-remote-community-netlify-playbook.yml \ 2>&1 | tee -a tmp/community-remote-netlify-build.log cd build/site && ln -s kubewarden/latest latest + ./scripts/generate-redirects.sh \ + build/site \ + admc/1.35/en .PHONY: clean