Skip to content

Commit 62bb17b

Browse files
committed
feat(config): improve redirection logic in vitePress config
1 parent 45964fd commit 62bb17b

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

docs/.vitepress/config.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,27 @@ const vitePressConfig: UserConfig = {
1818
"script",
1919
{},
2020
`
21-
(function() {
22-
const { pathname, search, hash } = window.location;
23-
const base = '/';
24-
if (pathname === base || pathname === (base + 'index.html')) {
25-
const userLang = navigator.language;
26-
if (userLang.toLowerCase().startsWith('zh')) {
27-
window.location.replace(base + 'zhHans/' + search + hash);
28-
}
21+
(function() {
22+
const { pathname, search, hash } = window.location;
23+
const base = '/';
24+
25+
const prefixes = ['/tessera-official-website', '/tessera-offcial-website'];
26+
for (const prefix of prefixes) {
27+
if (pathname.startsWith(prefix)) {
28+
const newPath = pathname.slice(prefix.length) || '/';
29+
window.location.replace(newPath + search + hash);
30+
return;
31+
}
32+
}
33+
34+
if (pathname === base || pathname === (base + 'index.html')) {
35+
const userLang = navigator.language;
36+
if (userLang.toLowerCase().startsWith('zh')) {
37+
window.location.replace(base + 'zhHans/' + search + hash);
2938
}
30-
})();
31-
`,
39+
}
40+
})();
41+
`,
3242
],
3343
],
3444

0 commit comments

Comments
 (0)