Skip to content

Commit 25aeabf

Browse files
committed
chore: auto redirect for en
1 parent 630d29e commit 25aeabf

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

docs/src/components/Head.astro

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ const props = Astro.props;
88
<StarlightHead {...props} />
99
<ClientRouter />
1010

11+
<script is:inline>
12+
(function() {
13+
// Only redirect on root (zh) pages, not already on /en/
14+
if (window.location.pathname.startsWith('/en')) return;
15+
// Only redirect once per session
16+
if (sessionStorage.getItem('lang-redirected')) return;
17+
var lang = navigator.language || navigator.userLanguage || '';
18+
if (!lang.startsWith('zh')) {
19+
sessionStorage.setItem('lang-redirected', '1');
20+
window.location.replace('/en' + window.location.pathname);
21+
}
22+
})();
23+
</script>
24+
1125
<script>
1226
import mediumZoom from 'medium-zoom';
1327

0 commit comments

Comments
 (0)