Skip to content

Commit a3d00a2

Browse files
authored
site: add redirect links from /xls/xls-[num].html to /xls/xls-[num]-[short-description].html (#443)
site: add redirect links from `/xls/xls-[num].html` to /xls/xls-[num]-[short-description].html
1 parent bf11948 commit a3d00a2

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

scripts/build_site.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,32 @@ def build_site():
100100
# Sort documents by number in reverse order (later ones more relevant)
101101
xls_docs.sort(key=lambda x: int(x.number), reverse=True)
102102

103+
# Generate simple redirect pages so /xls-<number>.html redirects to
104+
# the canonical document URL under /xls/<folder>.html.
105+
redirect_template = env.get_template("redirect.html")
106+
for doc in xls_docs:
107+
# Redirect pages live under /xls/, next to the canonical XLS HTML files.
108+
# For local builds (base_url == "."), use a relative URL that does *not*
109+
# add another /xls/ segment; otherwise we create /xls/xls/<file>.html.
110+
if base_url == ".":
111+
# From scripts/_site/xls/xls-<number>.html → ./<folder>.html
112+
target_url = f"./{doc.folder}.html"
113+
else:
114+
# On GitHub Pages, use an absolute URL with the base path.
115+
target_url = f"{base_url}/xls/{doc.folder}.html"
116+
117+
redirect_html = redirect_template.render(
118+
title=f"XLS-{doc.number}: {doc.title}",
119+
target_url=target_url,
120+
)
121+
122+
# /xls/ alias: /xls/xls-<number>.html
123+
redirect_xls_path = site_dir / "xls" / f"xls-{doc.number}.html"
124+
with open(redirect_xls_path, "w", encoding="utf-8") as f:
125+
f.write(redirect_html)
126+
127+
print(f"Generated redirect: {redirect_xls_path} -> {target_url}")
128+
103129
# Group documents by category for category pages and navigation
104130
categories = {}
105131
for doc in xls_docs:

scripts/templates/redirect.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>{{ title }}</title>
6+
<link rel="canonical" href="{{ target_url }}" />
7+
8+
<!-- Perform a JS redirect as early as possible to minimize flicker. -->
9+
<script>
10+
// Use replace() so the redirect page is not kept in history
11+
window.location.replace("{{ target_url }}");
12+
</script>
13+
<noscript>
14+
<meta http-equiv="refresh" content="0; url={{ target_url }}" />
15+
</noscript>
16+
17+
<!-- Match the site's dark background so there isn't a bright flash -->
18+
<style>
19+
html,
20+
body {
21+
margin: 0;
22+
padding: 0;
23+
background-color: #111112; /* var(--bg-color) from main site */
24+
color: #ffffff;
25+
font-family:
26+
system-ui,
27+
-apple-system,
28+
BlinkMacSystemFont,
29+
"Segoe UI",
30+
sans-serif;
31+
}
32+
</style>
33+
</head>
34+
<body>
35+
<p>
36+
Redirecting to
37+
<a href="{{ target_url }}">{{ title }}</a>...
38+
</p>
39+
</body>
40+
</html>

0 commit comments

Comments
 (0)