Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ 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 \
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"
Expand All @@ -30,6 +33,9 @@ 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 \
build/site \
admc/1.35/en

.PHONY: community-remote-netlify
community-remote-netlify: tmpdir environment
Expand All @@ -38,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
Expand Down
11 changes: 0 additions & 11 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,3 @@ command = "make community-remote-netlify"

#[build.environment]
# NODE_OPTIONS = "--max_old_space_size=4096"

# Redirect old Docusaurus-style URLs (/<path>) to the new Antora URLs
# (/admc/1.35/en/<path>).
# 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
74 changes: 74 additions & 0 deletions scripts/generate-redirects.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/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 pages in the new Antora structure.
#
# 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> <antora-prefix>
# 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:
# ./scripts/generate-redirects.sh build/site admc/1.35/en

set -euo pipefail

SITE_DIR="${1:?site-output-dir argument required}"
ANTORA_PREFIX="${2:?antora-prefix argument required}"

if [ ! -d "$SITE_DIR" ]; then
echo "ERROR: site output directory not found: $SITE_DIR" >&2
exit 1
fi

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 '' html; do
# Derive the page path relative to the antora prefix dir, without .html
rel="${html#"$ANTORA_DIR"/}"
rel="${rel%.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 if the flat path is already claimed by Antora output
if [ -e "${SITE_DIR}/${rel}.html" ]; then
continue
fi

# Overwrite unconditionally so version bumps to ANTORA_PREFIX always take effect
mkdir -p "$flat_dir"
cat > "$out_file" <<HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0; url=${new_url}">
<link rel="canonical" href="${new_url}">
<title>Redirecting...</title>
</head>
<body>
<p>This page has moved. <a href="${new_url}">Click here if you are not redirected.</a></p>
</body>
</html>
HTML

count=$((count + 1))
done < <(find "$ANTORA_DIR" -name "*.html" -not -name "index.html" -print0)

echo "Generated ${count} redirect file(s) under ${SITE_DIR}."
Loading