LiteSun commented on code in PR #2078:
URL: https://github.com/apache/apisix-website/pull/2078#discussion_r3654928739
##########
.github/workflows/deploy.yml:
##########
@@ -229,6 +315,72 @@ jobs:
mkdir -p "website/build/$(dirname "$path")"
cp -R "next/dist/$path" "website/build/$path"
done
+ # Latest-version docs come from Astro; every versioned directory
+ # (3.16/, next/, v1.6/, …) stays exactly as Docusaurus built it.
+ # Replacement is per-page, not per-subtree: under docs/<project>/ the
+ # version dirs and the latest-version pages sit side by side, so a
+ # subtree swap would delete the archive. Only paths the Astro build
+ # actually produced are touched.
+ for locale_prefix in "" "zh/"; do
+ src="next/dist/${locale_prefix}docs"
+ [ -d "$src" ] || continue
+ (cd "$src" && find . -name index.html) | sed 's|^\./||' | while
read -r rel; do
+ case "$rel" in
+ # Never touch an archived version directory.
+ */[0-9].[0-9]*/*|*/next/*|*/v[0-9]*/*) continue ;;
+ esac
+ dest="website/build/${locale_prefix}docs/$rel"
+ mkdir -p "$(dirname "$dest")"
+ cp "$src/$rel" "$dest"
+ # Ship the Markdown twin next to the page it mirrors.
+ twin="${rel%index.html}index.md"
+ [ -f "$src/$twin" ] && cp "$src/$twin"
"website/build/${locale_prefix}docs/$twin"
+ done
+ done
+ # The version archives must survive untouched.
+ test -f website/build/docs/apisix/3.16/plugins/cors/index.html
+ test -f website/build/docs/apisix/next/plugins/cors/index.html
+ grep -q 'docusaurus'
website/build/docs/apisix/3.16/plugins/cors/index.html
+ # …and the latest-version pages must now be the Astro build.
+ grep -q '/_astro/' website/build/docs/apisix/plugins/cors/index.html
+ grep -q '/_astro/'
website/build/zh/docs/apisix/plugins/cors/index.html
+ # The archives are still a Docusaurus SPA, and their version dropdown
+ # and "older version" banner link to the version-less URLs we just
+ # replaced. Without a real navigation, React would client-route to
+ # its own stale render of those URLs instead of fetching the Astro
+ # page. target="_self" forces a document load (same trick the repo
+ # already uses for pathname:// links in the locale dropdown).
+ node -e '
+ const fs = require("fs"), path = require("path");
+ const roots = ["website/build/docs", "website/build/zh/docs"];
+ // /docs/<project>/<page…>/ with no version segment right after the
+ // project — i.e. exactly the URLs the Astro build now owns.
+ const re =
/(<a\b[^>]*?\bhref="\/(?:zh\/)?docs\/[a-z0-9-]+\/(?!(?:[0-9]+\.[0-9]+|next|v[0-9])\/)[^"]*")/g;
+ let patched = 0;
+ const walk = (d) => fs.existsSync(d) && fs.readdirSync(d, {
withFileTypes: true }).forEach((e) => {
+ const p = path.join(d, e.name);
+ if (e.isDirectory()) return walk(p);
+ if (e.name !== "index.html") return;
+ // Only the archived pages need this; the Astro pages are not a
SPA.
+ const html = fs.readFileSync(p, "utf8");
+ if (!html.includes("docusaurus")) return;
+ const out = html.replace(re, (m) => (m.includes("target=") ? m :
`${m} target="_self"`));
Review Comment:
Thanks for replacing the `target="_self"` patch, but the new
`onlyIncludeVersions` approach does not resolve this yet. The generated
versions JSON contains release names only; Docusaurus injects `current`
separately, chooses the first included release as `lastVersion`, and assigns
that version the empty (version-less) path. For APISIX, `all.slice(1)`
therefore excludes both `current` and 3.17, makes 3.16 own the version-less
routes, and stops producing both `/3.16/` and `/next/`. The
archive-preservation assertions later in this workflow will fail, while the
route manifest still owns the migrated URLs with 3.16 content. For every
sub-project, `SUBPROJECT_VERSIONS_TO_KEEP` is 1, so the helper returns
`undefined` and their version-less routes remain unchanged. Please configure
explicit paths for the retained versions/current route and verify all seven
plugin manifests plus the exact `3.16/` and `next/` outputs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]