Skip to content

Commit 1c38bfc

Browse files
committed
fix root redirect: detect browser language, add no-js + manual fallbacks
previously / hardcoded location.replace('/zh-hans/'), so english users hitting subs.js.org always landed on the chinese version regardless of navigator.language. now the root path runs three layers in priority order: - inline js in <head> reads navigator.language and routes zh* to /zh-hans/, everything else to /en/ - <meta http-equiv="refresh"> as a hard fallback to /en/ for no-js environments - visible black-bg page with brand-yellow language buttons as the last resort if both are blocked moved the page from src/pages/index.astro to public/index.html so it ships as a 2.4kb static file with no tailwind bundle, no baselayout, no header/footer flash. links are relative (./zh-hans/, ./en/) for portability. refs #23, #24
1 parent a89e285 commit 1c38bfc

3 files changed

Lines changed: 109 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@
44

55
---
66

7+
## 2026-05-05
8+
9+
修首页重定向:之前不论浏览器语言一律落到 `/zh-hans/`,英文用户被强行带到中文版。顺手补上多层兜底。
10+
11+
### 修复
12+
13+
- **首页根路径语言识别**:根 `/` 之前是一段把 `location.replace("/zh-hans/")` 写死的 `src/pages/index.astro`,浏览器语言完全没参与判断。现在 head 里一段内联 JS 读 `navigator.languages[0] || navigator.language``zh*``/zh-hans/`,其余 → `/en/`
14+
15+
### 改进
16+
17+
- **重定向改成三层冗余**
18+
- 第一层 JS 跑在 `<head>` 顶部、同步执行,正常环境下用户感知不到这一跳;
19+
- 第二层 `<meta http-equiv="refresh" content="0; url=./en/">` 兜禁用 JS 的环境(`en` 作为国际访客的安全 fallback,中文用户只要 JS 能跑就会被 JS 路径接走);
20+
- 第三层是一张纯黑页,写一行 "Redirecting" 大标题 + 中英双行提示 + 两个黄色描边的语言按钮(简体中文 / English),任何环境下都能让用户手动到达正确语种。
21+
- **从 Astro 页搬到纯静态 `public/index.html`**:之前是 `.astro` 文件,构建出来会被自动挂上 43KB 的全局 Tailwind bundle 和 `data-astro-cid-*` 作用域属性,对一张 1ms 后就要消失的重定向页是纯浪费。现在直接走 `public/`**产物 2.4KB,零外部依赖,无 Tailwind / 无 BaseLayout / 无 Header & Footer 闪烁**,符合 issue 里"极致加载速度、禁止无用代码"的要求。
22+
- **链接全部相对路径**`./zh-hans/``./en/`),不绑死 `montagesubs.github.io` 这一个域,迁去自定义域 / Codeberg 都不用改。
23+
- **sitemap 自然剔除根路径**`/` 不再是 Astro 路由,重定向页本来也不该被搜索引擎单独索引(页面带 `noindex,follow`);语种页通过 `hreflang=zh-Hans / en / x-default` 继续正常向爬虫声明对应关系。
24+
25+
---
26+
727
## 2026-05-04
828

929
品牌色定锚后的一次对齐:把全站的"近似黄"换成品牌定的那支金黄,背景顺手暖了一档。

public/index.html

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>MontageSubs · 蒙太奇字幕社区</title>
6+
<meta name="viewport" content="width=device-width,initial-scale=1">
7+
<meta name="robots" content="noindex,follow">
8+
<meta name="theme-color" content="#000000">
9+
<script>
10+
(function () {
11+
try {
12+
var l = (navigator.languages && navigator.languages[0]) || navigator.language || '';
13+
location.replace(/^zh\b/i.test(l) ? './zh-hans/' : './en/');
14+
} catch (_) {
15+
location.replace('./en/');
16+
}
17+
})();
18+
</script>
19+
<meta http-equiv="refresh" content="0; url=./en/">
20+
<link rel="alternate" hreflang="zh-Hans" href="./zh-hans/">
21+
<link rel="alternate" hreflang="en" href="./en/">
22+
<link rel="alternate" hreflang="x-default" href="./zh-hans/">
23+
<link rel="icon" type="image/svg+xml" href="./favicon.svg">
24+
<link rel="icon" type="image/x-icon" href="./favicon.ico">
25+
<style>
26+
:root { color-scheme: dark; }
27+
*, *::before, *::after { box-sizing: border-box; }
28+
html, body { margin: 0; padding: 0; }
29+
body {
30+
min-height: 100vh;
31+
background: #000;
32+
color: #f5f1e8;
33+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
34+
display: flex;
35+
align-items: center;
36+
justify-content: center;
37+
padding: 2rem 1.5rem;
38+
line-height: 1.5;
39+
}
40+
main { max-width: 34rem; text-align: center; }
41+
h1 {
42+
margin: 0 0 0.75rem;
43+
font-size: clamp(2rem, 6vw, 3rem);
44+
font-weight: 800;
45+
letter-spacing: -0.02em;
46+
}
47+
p { margin: 0 0 2rem; color: #cfc9bb; font-size: 0.95rem; }
48+
ul {
49+
list-style: none;
50+
margin: 0;
51+
padding: 0;
52+
display: flex;
53+
gap: 0.75rem;
54+
flex-wrap: wrap;
55+
justify-content: center;
56+
}
57+
a {
58+
display: inline-block;
59+
padding: 0.7rem 1.4rem;
60+
border: 1px solid #FBC100;
61+
color: #FBC100;
62+
text-decoration: none;
63+
font-size: 0.875rem;
64+
letter-spacing: 0.05em;
65+
transition: background-color 0.15s ease, color 0.15s ease;
66+
}
67+
a:hover { background: #FBC100; color: #000; }
68+
a:focus-visible {
69+
background: #FBC100;
70+
color: #000;
71+
outline: 2px solid #FBC100;
72+
outline-offset: 3px;
73+
}
74+
</style>
75+
</head>
76+
<body>
77+
<main>
78+
<h1>Redirecting</h1>
79+
<p>
80+
If this doesn&rsquo;t work, please choose a language below.<br>
81+
如未自动跳转,请选择语言。
82+
</p>
83+
<ul>
84+
<li><a href="./zh-hans/" hreflang="zh-Hans" lang="zh-Hans">简体中文</a></li>
85+
<li><a href="./en/" hreflang="en" lang="en">English</a></li>
86+
</ul>
87+
</main>
88+
</body>
89+
</html>

src/pages/index.astro

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)