fix(docs): improve base path handling for vercel and github pages

Use withBase helper from vitepress to handle base paths consistently
Simplify vercel environment detection logic in config
This commit is contained in:
sanbuphy
2026-01-13 23:03:43 +08:00
parent 4c25317b86
commit 3ffdae8c1b
2 changed files with 5 additions and 7 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
import { defineConfig } from 'vitepress'
// 判断是否是 Vercel 环境, github page 和 vercel 的部署地址相关不一样
const isVercel = process.env.VERCEL === '1'
const base = isVercel ? '/' : '/easy-vibe/'
const isVercel = process.env.VERCEL === '1' || !!process.env.VERCEL_URL
const base = process.env.BASE || (isVercel ? '/' : '/easy-vibe/')
// 语言映射配置
const localeMap = {
+3 -5
View File
@@ -4,12 +4,9 @@ layout: home
<script setup>
import { onMounted } from 'vue'
import { withBase } from 'vitepress'
onMounted(() => {
// 获取当前的基础路径(考虑 Vercel 和 GitHub Pages
const isVercel = typeof window !== 'undefined' && window.location.hostname.includes('vercel.app')
const base = isVercel ? '' : '/easy-vibe'
// 语言映射:浏览器语言代码 -> 网站路径
const langMap = {
'zh': '/zh-cn/',
@@ -48,6 +45,7 @@ onMounted(() => {
}
// 立即跳转,不显示任何内容
window.location.replace(base + targetLang)
// 使用 withBase 自动处理 base 路径(根据 config.mjs 中的配置)
window.location.replace(withBase(targetLang))
})
</script>