Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 25 additions & 1 deletion .github/utils/promote_unstable_docs_docusaurus.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import sys

VERSION_VALIDATOR = re.compile(r"^[0-9]+\.[0-9]+$")

MAX_STABLE_VERSIONS = 5

if __name__ == "__main__":
parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -89,3 +89,27 @@
config = config.replace(f"lastVersion: '{previous_stable}'", f"lastVersion: '{target_version}'") # "2.19" -> "2.20"
with open("docs-website/docusaurus.config.js", "w") as f:
f.write(config)

# regenerate vercel.json redirects for inactive versions (those beyond the top MAX_STABLE_VERSIONS)
with open("docs-website/versions.json") as f:
updated_versions = json.load(f)
stable_versions = [v for v in updated_versions if not v.endswith("-unstable")]
inactive_versions = stable_versions[MAX_STABLE_VERSIONS:]
redirects = []
for v in inactive_versions:
redirects.append({"source": f"/docs/{v}/:slug*", "destination": "/docs/:slug*", "permanent": True})
redirects.append({"source": f"/reference/{v}/:slug*", "destination": "/reference/:slug*", "permanent": True})
try:
with open("docs-website/vercel.json") as f:
vercel_config = json.load(f)
except FileNotFoundError:
vercel_config = {}
version_redirect_re = re.compile(r"^/(docs|reference)/\d+\.\d+/")
manual_redirects = [
r for r in vercel_config.get("redirects", []) if not version_redirect_re.match(r.get("source", ""))
]
vercel_config["redirects"] = manual_redirects + redirects
with open("docs-website/vercel.json", "w") as f:
json.dump(vercel_config, f, indent=2)
f.write("\n")
print(f"Updated vercel.json with {len(redirects)} redirect(s) for inactive versions: {inactive_versions}")
44 changes: 44 additions & 0 deletions docs-website/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"redirects": [
{
"source": "/docs/2.21/:slug*",
"destination": "/docs/:slug*",
"permanent": true
},
{
"source": "/reference/2.21/:slug*",
"destination": "/reference/:slug*",
"permanent": true
},
{
"source": "/docs/2.20/:slug*",
"destination": "/docs/:slug*",
"permanent": true
},
{
"source": "/reference/2.20/:slug*",
"destination": "/reference/:slug*",
"permanent": true
},
{
"source": "/docs/2.19/:slug*",
"destination": "/docs/:slug*",
"permanent": true
},
{
"source": "/reference/2.19/:slug*",
"destination": "/reference/:slug*",
"permanent": true
},
{
"source": "/docs/2.18/:slug*",
"destination": "/docs/:slug*",
"permanent": true
},
{
"source": "/reference/2.18/:slug*",
"destination": "/reference/:slug*",
"permanent": true
}
]
}
Loading