mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-24 20:34:29 +08:00
- 在 VitePress 配置中集成 markdown-escape-plugin - 实现代码块保护机制避免代码中的 < > 符号被转义 - 添加预处理器确保代码块内容不被 HTML 转义影响 - 通过占位符机制实现代码块的临时替换和恢复 - 提供完整的代码块解析和转义处理流程
205 lines
6.7 KiB
TypeScript
205 lines
6.7 KiB
TypeScript
import { defineConfig } from 'vitepress'
|
||
|
||
export default defineConfig({
|
||
|
||
title: 'GFramework',
|
||
description: '面向游戏开发场景的模块化 C# 框架',
|
||
|
||
/** GitHub Pages / 子路径部署 */
|
||
base: '/GFramework/',
|
||
vite: {
|
||
plugins: [markdownEscapePlugin()]
|
||
},
|
||
/** 多语言 */
|
||
locales: {
|
||
root: {
|
||
label: '简体中文',
|
||
lang: 'zh-CN',
|
||
link: '/zh-CN/',
|
||
|
||
themeConfig: {
|
||
logo: '/logo-icon.png',
|
||
|
||
search: {
|
||
provider: 'local',
|
||
options: {
|
||
translations: {
|
||
button: {
|
||
buttonText: '搜索文档',
|
||
buttonAriaLabel: '搜索文档'
|
||
},
|
||
modal: {
|
||
noResultsText: '无法找到相关结果',
|
||
resetButtonTitle: '清除查询条件',
|
||
footer: {
|
||
selectText: '选择',
|
||
navigateText: '切换',
|
||
closeText: '关闭'
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
|
||
nav: [
|
||
{ text: '首页', link: '/zh-CN/' },
|
||
{ text: '入门指南', link: '/zh-CN/getting-started/installation' },
|
||
{ text: 'Core', link: '/zh-CN/core/' },
|
||
{ text: 'Game', link: '/zh-CN/game/' },
|
||
{ text: 'Godot', link: '/zh-CN/godot/' },
|
||
{ text: '源码生成器', link: '/zh-CN/source-generators/overview' },
|
||
{ text: '教程', link: '/zh-CN/tutorials/basic-tutorial' },
|
||
],
|
||
|
||
sidebar: {
|
||
'/zh-CN/getting-started/': [
|
||
{
|
||
text: '入门指南',
|
||
items: [
|
||
{ text: '安装配置', link: '/zh-CN/getting-started/installation' },
|
||
{ text: '快速开始', link: '/zh-CN/getting-started/quick-start' },
|
||
{ text: '架构概览', link: '/zh-CN/getting-started/architecture-overview' }
|
||
]
|
||
}
|
||
],
|
||
|
||
'/zh-CN/core/': [
|
||
{
|
||
text: 'Core 核心框架',
|
||
items: [
|
||
{ text: '概览', link: '/zh-CN/core/' },
|
||
{ text: '架构组件', link: '/zh-CN/core/architecture' },
|
||
{ text: '命令系统', link: '/zh-CN/core/command' },
|
||
{ text: '查询系统', link: '/zh-CN/core/query' },
|
||
{ text: '事件系统', link: '/zh-CN/core/events' },
|
||
{ text: '属性系统', link: '/zh-CN/core/property' },
|
||
{ text: 'IoC容器', link: '/zh-CN/core/ioc' },
|
||
{ text: '对象池', link: '/zh-CN/core/pool' },
|
||
{ text: '日志系统', link: '/zh-CN/core/logging' },
|
||
{ text: '扩展方法', link: '/zh-CN/core/extensions' },
|
||
{ text: '工具类', link: '/zh-CN/core/utility' },
|
||
{ text: '模型层', link: '/zh-CN/core/model' },
|
||
{ text: '系统层', link: '/zh-CN/core/system' },
|
||
{ text: '控制器', link: '/zh-CN/core/controller' },
|
||
{ text: '规则系统', link: '/zh-CN/core/rule' },
|
||
{ text: '环境接口', link: '/zh-CN/core/environment' }
|
||
]
|
||
}
|
||
],
|
||
|
||
'/zh-CN/game/': [
|
||
{
|
||
text: 'Game 游戏模块',
|
||
items: [
|
||
{ text: '概览', link: '/zh-CN/game/' },
|
||
{ text: '场景管理', link: '/zh-CN/game/scene-management' },
|
||
{ text: '游戏设置', link: '/zh-CN/game/setting' }
|
||
]
|
||
}
|
||
],
|
||
|
||
'/zh-CN/godot/': [
|
||
{
|
||
text: 'Godot 集成',
|
||
items: [
|
||
{ text: '概览', link: '/zh-CN/godot/' },
|
||
{ text: '协程系统', link: '/zh-CN/godot/coroutine' },
|
||
{ text: '节点扩展', link: '/zh-CN/godot/extensions' },
|
||
{ text: '信号系统', link: '/zh-CN/godot/signal' },
|
||
{ text: '存储系统', link: '/zh-CN/godot/storage' },
|
||
{ text: '设置系统', link: '/zh-CN/godot/setting' }
|
||
]
|
||
}
|
||
],
|
||
|
||
'/zh-CN/source-generators/': [
|
||
{
|
||
text: '源码生成器',
|
||
items: [
|
||
{ text: '概览', link: '/zh-CN/source-generators/' },
|
||
{ text: '日志生成器', link: '/zh-CN/source-generators/logging-generator' },
|
||
{ text: '枚举扩展', link: '/zh-CN/source-generators/enum-generator' },
|
||
{ text: '规则生成器', link: '/zh-CN/source-generators/rule-generator' }
|
||
]
|
||
}
|
||
],
|
||
|
||
'/zh-CN/abstractions/': [
|
||
{
|
||
text: '抽象接口',
|
||
items: [
|
||
{ text: 'Core Abstractions', link: '/zh-CN/abstractions/core-abstractions' },
|
||
{ text: 'Game Abstractions', link: '/zh-CN/abstractions/game-abstractions' }
|
||
]
|
||
}
|
||
],
|
||
|
||
'/zh-CN/tutorials/': [
|
||
{
|
||
text: '教程',
|
||
items: [
|
||
{ text: '入门教程', link: '/zh-CN/tutorials/getting-started' },
|
||
{ text: '基础教程', link: '/zh-CN/tutorials/basic-tutorial' },
|
||
{ text: 'Godot集成', link: '/zh-CN/tutorials/godot-integration' },
|
||
{ text: '高级模式', link: '/zh-CN/tutorials/advanced-patterns' }
|
||
]
|
||
}
|
||
],
|
||
},
|
||
|
||
socialLinks: [
|
||
{ icon: 'github', link: 'https://github.com/GeWuYou/GFramework' }
|
||
],
|
||
|
||
footer: {
|
||
message: '基于 Apache 2.0 许可证发布',
|
||
copyright: 'Copyright © 2026 GeWuYou'
|
||
},
|
||
|
||
outlineTitle: '页面导航',
|
||
lastUpdatedText: '最后更新于',
|
||
darkModeSwitchLabel: '主题',
|
||
sidebarMenuLabel: '菜单',
|
||
returnToTopLabel: '回到顶部',
|
||
|
||
docFooter: {
|
||
prev: '上一页',
|
||
next: '下一页'
|
||
}
|
||
}
|
||
}
|
||
}
|
||
})
|
||
import { defineConfig } from 'vitepress'
|
||
|
||
function markdownEscapePlugin() {
|
||
return {
|
||
name: 'markdown-escape-plugin',
|
||
enforce: 'pre', // 在 vitepress 之前执行
|
||
transform(code: string, id: string) {
|
||
if (!id.endsWith('.md')) return
|
||
|
||
const codeBlocks: string[] = []
|
||
|
||
// 1️⃣ 替换代码块
|
||
const replaced = code.replace(/```[\s\S]*?```/g, (match) => {
|
||
const index = codeBlocks.length
|
||
codeBlocks.push(match)
|
||
return `__CODE_BLOCK_${index}__`
|
||
})
|
||
|
||
// 2️⃣ 转义普通文本中的 < >
|
||
let escaped = replaced
|
||
.replace(/</g, '<')
|
||
.replace(/>/g, '>')
|
||
|
||
// 3️⃣ 恢复代码块
|
||
codeBlocks.forEach((block, index) => {
|
||
escaped = escaped.replace(`__CODE_BLOCK_${index}__`, block)
|
||
})
|
||
|
||
return escaped
|
||
}
|
||
}
|
||
}
|