Skip to content

Harness engineering beginner tutorial, from 0 to 1

Fix homepage language redirect for GitHub Pages

sanbuphye66e534b63ef
diff --git a/docs/index.md b/docs/index.md
index b4dd526..d5149ba 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -4,8 +4,9 @@ layout: page
<script setup>
if (typeof window !== 'undefined') {
+ const base = import.meta.env.BASE_URL || '/'
const lang = navigator.language || navigator.languages?.[0] || ''
- const target = lang.startsWith('zh') ? '/zh/' : '/en/'
+ const target = `${base}${lang.startsWith('zh') ? 'zh/' : 'en/'}`
if (!window.location.pathname.replace(/\/$/, '').endsWith(target.replace(/\/$/, ''))) {
window.location.replace(target)
}
@@ -19,7 +20,7 @@ Redirecting...
<template>
<p>Choose your language / 选择语言:</p>
<ul>
- <li><a href="/zh/">中文</a></li>
- <li><a href="/en/">English</a></li>
+ <li><a href="./zh/">中文</a></li>
+ <li><a href="./en/">English</a></li>
</ul>
</template>