From 159578ab90f505b650609577353ce20feaca21c4 Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Sun, 29 Mar 2026 20:08:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(docs):=20=E6=B7=BB=E5=8A=A0=E6=B3=9B?= =?UTF-8?q?=E5=9E=8B=E5=AE=89=E5=85=A8=E8=BD=AC=E4=B9=89=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=B9=B6=E5=A2=9E=E5=8A=A0=E6=BA=90=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=99=A8=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 实现 safeGenericEscapePlugin 插件保护 Markdown 中的泛型语法 - 配置 Vite 构建选项提高代码块大小警告阈值至 1000 - 添加 Priority 生成器和 Context Get 注入文档链接 - 重构配置文件结构将插件函数移至顶部定义 - 确保代码块和 HTML 标签在转义过程中得到正确保护 --- docs/.vitepress/config.mts | 105 +++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 50 deletions(-) diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index c67fe56..51c1d68 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -1,7 +1,53 @@ import { defineConfig } from 'vitepress' +function safeGenericEscapePlugin() { + return { + name: 'safe-generic-escape', + enforce: 'pre', + + transform(code: string, id: string) { + if (!id.endsWith('.md')) return + + const codeBlocks: string[] = [] + const htmlBlocks: string[] = [] + + // 1️⃣ 保护代码块 ``` ``` + let processed = code.replace(/```[\s\S]*?```/g, (match) => { + const i = codeBlocks.length + codeBlocks.push(match) + return `__CODE_BLOCK_${i}__` + }) + + // 2️⃣ 保护 HTML 标签(避免破坏 Vue SFC) + processed = processed.replace(/<\/?[a-zA-Z][^>]*>/g, (match) => { + const i = htmlBlocks.length + htmlBlocks.push(match) + return `__HTML_BLOCK_${i}__` + }) + + // 3️⃣ 只转义"泛型形式"的 + processed = processed.replace( + /<([A-Z][A-Za-z0-9_,\s]*)>/g, + (_, inner) => `<${inner}>` + ) + + // 4️⃣ 恢复 HTML + htmlBlocks.forEach((block, i) => { + processed = processed.replace(`__HTML_BLOCK_${i}__`, block) + }) + + // 5️⃣ 恢复代码块 + codeBlocks.forEach((block, i) => { + processed = processed.replace(`__CODE_BLOCK_${i}__`, block) + }) + + return processed + } + } +} + export default defineConfig({ - + title: 'GFramework', description: '面向游戏开发场景的模块化 C# 框架', head: [ @@ -10,7 +56,11 @@ export default defineConfig({ /** GitHub Pages / 子路径部署 */ base: '/GFramework/', vite: { - plugins: [safeGenericEscapePlugin()] + plugins: [safeGenericEscapePlugin()], + build: { + // 提高代码块大小警告阈值(文档包含大量代码示例) + chunkSizeWarningLimit: 1000 + } }, /** 多语言 */ locales: { @@ -162,7 +212,9 @@ export default defineConfig({ { text: '概览', link: '/zh-CN/source-generators/' }, { text: '日志生成器', link: '/zh-CN/source-generators/logging-generator' }, { text: '枚举扩展', link: '/zh-CN/source-generators/enum-generator' }, - { text: 'ContextAware 生成器', link: '/zh-CN/source-generators/context-aware-generator' } + { text: 'ContextAware 生成器', link: '/zh-CN/source-generators/context-aware-generator' }, + { text: 'Priority 生成器', link: '/zh-CN/source-generators/priority-generator' }, + { text: 'Context Get 注入', link: '/zh-CN/source-generators/context-get-generator' } ] } ], @@ -251,50 +303,3 @@ export default defineConfig({ } } }) -import { defineConfig } from 'vitepress' - -function safeGenericEscapePlugin() { - return { - name: 'safe-generic-escape', - enforce: 'pre', - - transform(code: string, id: string) { - if (!id.endsWith('.md')) return - - const codeBlocks: string[] = [] - const htmlBlocks: string[] = [] - - // 1️⃣ 保护代码块 ``` ``` - let processed = code.replace(/```[\s\S]*?```/g, (match) => { - const i = codeBlocks.length - codeBlocks.push(match) - return `__CODE_BLOCK_${i}__` - }) - - // 2️⃣ 保护 HTML 标签(避免破坏 Vue SFC) - processed = processed.replace(/<\/?[a-zA-Z][^>]*>/g, (match) => { - const i = htmlBlocks.length - htmlBlocks.push(match) - return `__HTML_BLOCK_${i}__` - }) - - // 3️⃣ 只转义“泛型形式”的 - processed = processed.replace( - /<([A-Z][A-Za-z0-9_,\s]*)>/g, - (_, inner) => `<${inner}>` - ) - - // 4️⃣ 恢复 HTML - htmlBlocks.forEach((block, i) => { - processed = processed.replace(`__HTML_BLOCK_${i}__`, block) - }) - - // 5️⃣ 恢复代码块 - codeBlocks.forEach((block, i) => { - processed = processed.replace(`__CODE_BLOCK_${i}__`, block) - }) - - return processed - } - } -}