refactor(docs): 优化文档站点配置和404页面实现多语言支持

- 更新VitePress配置移除不必要的服务器中间件
- 实现404页面的中英文国际化显示
- 为404页面添加倒计时自动跳转功能
- 重构404页面样式并添加返回首页按钮
- 优化依赖缓存哈希值更新构建配置
This commit is contained in:
GeWuYou 2026-02-11 11:12:05 +08:00 committed by gewuyou
parent b835d3af67
commit 6f4bbd6d06
3 changed files with 86 additions and 126 deletions

View File

@ -1,25 +1,25 @@
{
"hash": "f04df328",
"configHash": "15e8eca7",
"hash": "74ecdc37",
"configHash": "1c302118",
"lockfileHash": "42b6a898",
"browserHash": "342224e2",
"browserHash": "b3e735e5",
"optimized": {
"vue": {
"src": "../../../node_modules/vue/dist/vue.runtime.esm-bundler.js",
"file": "vue.js",
"fileHash": "c87f1bc4",
"fileHash": "5c6400c6",
"needsInterop": false
},
"vitepress > @vue/devtools-api": {
"src": "../../../node_modules/@vue/devtools-api/dist/index.js",
"file": "vitepress___@vue_devtools-api.js",
"fileHash": "4ddc9988",
"fileHash": "673694b5",
"needsInterop": false
},
"vitepress > @vueuse/core": {
"src": "../../../node_modules/@vueuse/core/dist/index.js",
"file": "vitepress___@vueuse_core.js",
"fileHash": "3d4a475e",
"fileHash": "7fde5c45",
"needsInterop": false
}
},

View File

@ -1,53 +1,19 @@
import { defineConfig } from 'vitepress'
export default defineConfig({
title: "GFramework",
description: "面向游戏开发场景的模块化 C# 框架",
base: "/GFramework/",
vite: {
plugins: [
{
name: 'catch-all-404',
configureServer(server) {
return () => {
server.middlewares.use((req, res, next) => {
const url = req.url || ''
title: 'GFramework',
description: '面向游戏开发场景的模块化 C# 框架',
// 排除这些路径
const excludePaths = [
'/@vite',
'/@fs',
'/node_modules',
'/__vite',
'/public'
]
/** GitHub Pages / 子路径部署 */
base: '/GFramework/',
// 如果是资源文件或特殊路径,跳过
if (excludePaths.some(path => url.startsWith(path)) ||
url.includes('.') ||
url.startsWith('/GFramework/')) {
return next()
}
// 其他路径重定向到 404
res.writeHead(302, { Location: '/GFramework/404' })
res.end()
})
}
}
}
],
server: {
strictPort: false,
// 添加中间件处理不带斜杠的情况
proxy: {}
}
},
/** 多语言 */
locales: {
root: {
label: '简体中文',
lang: 'zh-CN',
link: '/zh-CN/',
themeConfig: {
logo: '/logo-icon.png',
@ -94,6 +60,7 @@ export default defineConfig({
]
}
],
'/zh-CN/core/': [
{
text: 'Core 核心框架',
@ -107,6 +74,7 @@ export default defineConfig({
]
}
],
'/zh-CN/game/': [
{
text: 'Game 游戏模块',
@ -119,6 +87,7 @@ export default defineConfig({
]
}
],
'/zh-CN/godot/': [
{
text: 'Godot 集成',
@ -131,6 +100,7 @@ export default defineConfig({
]
}
],
'/zh-CN/source-generators/': [
{
text: '源码生成器',
@ -142,6 +112,7 @@ export default defineConfig({
]
}
],
'/zh-CN/tutorials/': [
{
text: '教程',
@ -152,6 +123,7 @@ export default defineConfig({
]
}
],
'/zh-CN/api-reference/': [
{
text: 'API 参考',
@ -185,56 +157,6 @@ export default defineConfig({
next: '下一页'
}
}
},
// 未来添加英文版本时取消注释
/*
en: {
label: 'English',
lang: 'en-US',
link: '/en/',
themeConfig: {
logo: '/logo-icon.png',
search: {
provider: 'local'
},
nav: [
{ text: 'Home', link: '/en/' },
{ text: 'Getting Started', link: '/en/getting-started/installation' },
{ text: 'Core', link: '/en/core/overview' },
{ text: 'Game', link: '/en/game/overview' },
{ text: 'Godot', link: '/en/godot/overview' },
{ text: 'Source Generators', link: '/en/source-generators/overview' },
{ text: 'Tutorials', link: '/en/tutorials/basic-tutorial' },
{ text: 'API Reference', link: '/en/api-reference/core-api' }
],
sidebar: {
'/en/getting-started/': [
{
text: 'Getting Started',
items: [
{ text: 'Installation', link: '/en/getting-started/installation' },
{ text: 'Quick Start', link: '/en/getting-started/quick-start' },
{ text: 'Architecture Overview', link: '/en/getting-started/architecture-overview' }
]
}
],
// ... 其他英文侧边栏配置
},
socialLinks: [
{ icon: 'github', link: 'https://github.com/GeWuYou/GFramework' }
],
footer: {
message: 'Released under the Apache 2.0 License',
copyright: 'Copyright © 2026 GeWuYou'
}
}
}
*/
}
})
})

View File

@ -2,34 +2,37 @@
layout: page
---
<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
<script setup lang="ts">
import { ref, onMounted, onUnmounted, computed } from 'vue'
import { useData, useRouter, withBase } from 'vitepress'
const { lang } = useData()
const router = useRouter()
/** 是否中文 */
const isZh = computed(() => lang.value === 'zh-CN')
/** 倒计时 */
const countdown = ref(5)
let timer = null
let timer: number | null = null
const goHome = () => {
if (timer) clearInterval(timer)
router.go(withBase(isZh.value ? '/zh-CN/' : '/en/'))
}
onMounted(() => {
timer = setInterval(() => {
timer = window.setInterval(() => {
countdown.value--
if (countdown.value <= 0) {
clearInterval(timer)
window.location.href = '/GFramework/zh-CN/'
goHome()
}
}, 1000)
})
onUnmounted(() => {
if (timer) {
clearInterval(timer)
}
if (timer) clearInterval(timer)
})
const goHome = () => {
if (timer) {
clearInterval(timer)
}
window.location.href = '/GFramework/zh-CN/'
}
</script>
<style scoped>
@ -104,30 +107,65 @@ const goHome = () => {
background: #2841a0;
transform: translateY(-2px);
}
.suggestions {
margin-top: 24px;
}
.suggestions ul {
list-style: none;
padding: 0;
}
.suggestions li {
margin: 6px 0;
}
</style>
<div class="not-found-container">
<h1 class="error-code">404</h1>
<h2 class="error-title">Page Not Found / 页面未找到</h2>
<p class="error-message">The page you are looking for does not exist.<br>您访问的页面不存在。</p>
<h2 class="error-title">
{{ isZh ? '页面未找到' : 'Page Not Found' }}
</h2>
<p class="error-message">
<template v-if="isZh">
您访问的页面不存在。
</template>
<template v-else>
The page you are looking for does not exist.
</template>
</p>
<p class="countdown-text">
Auto redirecting in <span class="countdown-number">{{ countdown }}</span> seconds<br>
<span class="countdown-number">{{ countdown }}</span> 秒后自动跳转
<template v-if="isZh">
<span class="countdown-number">{{ countdown }}</span> 秒后自动跳转
</template>
<template v-else>
Auto redirecting in <span class="countdown-number">{{ countdown }}</span> seconds
</template>
</p>
<div class="suggestions">
<h3>📚 您可能想访问:</h3>
<ul>
<li><a href="/GFramework/zh-CN/getting-started/installation">安装配置</a></li>
<li><a href="/GFramework/zh-CN/getting-started/quick-start">快速开始</a></li>
<li><a href="/GFramework/zh-CN/core/overview">Core 核心框架</a></li>
<li><a href="/GFramework/zh-CN/tutorials/basic-tutorial">基础教程</a></li>
<div class="suggestions">
<h3>📚 {{ isZh ? '您可能想访问:' : 'You might be looking for:' }}</h3>
<ul v-if="isZh">
<li><a :href="withBase('/zh-CN/getting-started/installation')">安装配置</a></li>
<li><a :href="withBase('/zh-CN/getting-started/quick-start')">快速开始</a></li>
<li><a :href="withBase('/zh-CN/core/overview')">Core 核心框架</a></li>
<li><a :href="withBase('/zh-CN/tutorials/basic-tutorial')">基础教程</a></li>
</ul>
<ul v-else>
<li><a :href="withBase('/en/getting-started/installation')">Installation</a></li>
<li><a :href="withBase('/en/getting-started/quick-start')">Quick Start</a></li>
<li><a :href="withBase('/en/core/overview')">Core Overview</a></li>
<li><a :href="withBase('/en/tutorials/basic-tutorial')">Basic Tutorial</a></li>
</ul>
</div>
<div class="action-buttons">
<button class="btn btn-primary" @click="goHome">
Go to Homepage / 返回首页
{{ isZh ? '返回首页' : 'Go to Homepage' }}
</button>
</div>
</div>
```