Skip to content

Commit d831f54

Browse files
feat: add redirects for inactive documentation versions in vercel.json (#11027)
* feat: add redirects for inactive documentation versions in vercel.json * Update .github/utils/promote_unstable_docs_docusaurus.py Co-authored-by: Stefano Fiorucci <stefanofiorucci@gmail.com> * fix: remove try/except block as file has to exist --------- Co-authored-by: Stefano Fiorucci <stefanofiorucci@gmail.com>
1 parent 865e7a5 commit d831f54

2 files changed

Lines changed: 71 additions & 1 deletion

File tree

.github/utils/promote_unstable_docs_docusaurus.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import sys
1313

1414
VERSION_VALIDATOR = re.compile(r"^[0-9]+\.[0-9]+$")
15-
15+
MAX_STABLE_VERSIONS = 5
1616

1717
if __name__ == "__main__":
1818
parser = argparse.ArgumentParser()
@@ -89,3 +89,29 @@
8989
config = config.replace(f"lastVersion: '{previous_stable}'", f"lastVersion: '{target_version}'") # "2.19" -> "2.20"
9090
with open("docs-website/docusaurus.config.js", "w") as f:
9191
f.write(config)
92+
93+
# regenerate vercel.json redirects for inactive versions (those beyond the top MAX_STABLE_VERSIONS)
94+
with open("docs-website/versions.json") as f:
95+
updated_versions = json.load(f)
96+
stable_versions = [v for v in updated_versions if not v.endswith("-unstable")]
97+
inactive_versions = stable_versions[MAX_STABLE_VERSIONS:]
98+
redirects = []
99+
for v in inactive_versions:
100+
redirects.append({"source": f"/docs/{v}/:slug*", "destination": "/docs/:slug*", "permanent": True})
101+
redirects.append({"source": f"/reference/{v}/:slug*", "destination": "/reference/:slug*", "permanent": True})
102+
103+
with open("docs-website/vercel.json") as f:
104+
vercel_config = json.load(f)
105+
106+
existing_redirects = vercel_config.get("redirects", [])
107+
existing_sources = {r.get("source") for r in existing_redirects}
108+
109+
for r in redirects:
110+
if r["source"] not in existing_sources:
111+
existing_redirects.append(r)
112+
113+
vercel_config["redirects"] = existing_redirects
114+
with open("docs-website/vercel.json", "w") as f:
115+
json.dump(vercel_config, f, indent=2)
116+
f.write("\n")
117+
print(f"Updated vercel.json with {len(redirects)} redirect(s) for inactive versions: {inactive_versions}")

docs-website/vercel.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"redirects": [
3+
{
4+
"source": "/docs/2.21/:slug*",
5+
"destination": "/docs/:slug*",
6+
"permanent": true
7+
},
8+
{
9+
"source": "/reference/2.21/:slug*",
10+
"destination": "/reference/:slug*",
11+
"permanent": true
12+
},
13+
{
14+
"source": "/docs/2.20/:slug*",
15+
"destination": "/docs/:slug*",
16+
"permanent": true
17+
},
18+
{
19+
"source": "/reference/2.20/:slug*",
20+
"destination": "/reference/:slug*",
21+
"permanent": true
22+
},
23+
{
24+
"source": "/docs/2.19/:slug*",
25+
"destination": "/docs/:slug*",
26+
"permanent": true
27+
},
28+
{
29+
"source": "/reference/2.19/:slug*",
30+
"destination": "/reference/:slug*",
31+
"permanent": true
32+
},
33+
{
34+
"source": "/docs/2.18/:slug*",
35+
"destination": "/docs/:slug*",
36+
"permanent": true
37+
},
38+
{
39+
"source": "/reference/2.18/:slug*",
40+
"destination": "/reference/:slug*",
41+
"permanent": true
42+
}
43+
]
44+
}

0 commit comments

Comments
 (0)