wiki-vitepress
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWiki VitePress Packager
Wiki VitePress 打包工具
Transform generated wiki Markdown files into a polished VitePress static site with dark theme and interactive Mermaid diagrams.
将生成的维基Markdown文件转换为带有深色主题和交互式Mermaid图表的精致VitePress静态站点。
When to Activate
激活场景
- User asks to "build a site" or "package as VitePress"
- User runs the command
/deep-wiki:build - User wants a browsable HTML output from generated wiki pages
- 用户要求“构建网站”或“打包为VitePress”
- 用户运行命令
/deep-wiki:build - 用户希望从生成的维基页面得到可浏览的HTML输出
VitePress Scaffolding
VitePress 脚手架结构
Generate the following structure in a directory:
wiki-site/wiki-site/
├── .vitepress/
│ ├── config.mts
│ └── theme/
│ ├── index.ts
│ └── custom.css
├── public/
├── [generated .md pages]
├── package.json
└── index.md在目录中生成以下结构:
wiki-site/wiki-site/
├── .vitepress/
│ ├── config.mts
│ └── theme/
│ ├── index.ts
│ └── custom.css
├── public/
├── [生成的.md页面]
├── package.json
└── index.mdConfig Requirements (config.mts
)
config.mts配置要求 (config.mts
)
config.mts- Use wrapper from
withMermaidvitepress-plugin-mermaid - Set for dark-only theme
appearance: 'dark' - Configure and
themeConfig.navfrom the catalogue structurethemeConfig.sidebar - Mermaid config must set dark theme variables:
typescript
mermaid: {
theme: 'dark',
themeVariables: {
primaryColor: '#1e3a5f',
primaryTextColor: '#e0e0e0',
primaryBorderColor: '#4a9eed',
lineColor: '#4a9eed',
secondaryColor: '#2d4a3e',
tertiaryColor: '#2d2d3d',
background: '#1a1a2e',
mainBkg: '#1e3a5f',
nodeBorder: '#4a9eed',
clusterBkg: '#16213e',
titleColor: '#e0e0e0',
edgeLabelBackground: '#1a1a2e'
}
}- 使用中的
vitepress-plugin-mermaid包装器withMermaid - 设置以启用纯深色主题
appearance: 'dark' - 根据目录结构配置和
themeConfig.navthemeConfig.sidebar - Mermaid配置必须设置深色主题变量:
typescript
mermaid: {
theme: 'dark',
themeVariables: {
primaryColor: '#1e3a5f',
primaryTextColor: '#e0e0e0',
primaryBorderColor: '#4a9eed',
lineColor: '#4a9eed',
secondaryColor: '#2d4a3e',
tertiaryColor: '#2d2d3d',
background: '#1a1a2e',
mainBkg: '#1e3a5f',
nodeBorder: '#4a9eed',
clusterBkg: '#16213e',
titleColor: '#e0e0e0',
edgeLabelBackground: '#1a1a2e'
}
}Dark-Mode Mermaid: Three-Layer Fix
深色模式Mermaid:三层修复方案
Layer 1: Theme Variables (in config.mts)
第一层:主题变量(在config.mts中)
Set via as shown above.
mermaid.themeVariables通过上述进行设置。
mermaid.themeVariablesLayer 2: CSS Overrides (custom.css
)
custom.css第二层:CSS覆盖 (custom.css
)
custom.cssTarget Mermaid SVG elements with :
!importantcss
.mermaid .node rect,
.mermaid .node circle,
.mermaid .node polygon { fill: #1e3a5f !important; stroke: #4a9eed !important; }
.mermaid .edgeLabel { background-color: #1a1a2e !important; color: #e0e0e0 !important; }
.mermaid text { fill: #e0e0e0 !important; }
.mermaid .label { color: #e0e0e0 !important; }使用定位Mermaid SVG元素:
!importantcss
.mermaid .node rect,
.mermaid .node circle,
.mermaid .node polygon { fill: #1e3a5f !important; stroke: #4a9eed !important; }
.mermaid .edgeLabel { background-color: #1a1a2e !important; color: #e0e0e0 !important; }
.mermaid text { fill: #e0e0e0 !important; }
.mermaid .label { color: #e0e0e0 !important; }Layer 3: Inline Style Replacement (theme/index.ts
)
theme/index.ts第三层:内联样式替换 (theme/index.ts
)
theme/index.tsMermaid inline attributes override everything. Use + polling to replace them:
styleonMountedtypescript
import { onMounted } from 'vue'
// In setup()
onMounted(() => {
let attempts = 0
const fix = setInterval(() => {
document.querySelectorAll('.mermaid svg [style]').forEach(el => {
const s = (el as HTMLElement).style
if (s.fill && !s.fill.includes('#1e3a5f')) s.fill = '#1e3a5f'
if (s.stroke && !s.stroke.includes('#4a9eed')) s.stroke = '#4a9eed'
if (s.color) s.color = '#e0e0e0'
})
if (++attempts >= 20) clearInterval(fix)
}, 500)
})Use with , NOT — DOM doesn't exist during SSR.
setup()onMountedenhanceApp()Mermaid的内联属性会覆盖所有样式。使用 + 轮询来替换这些样式:
styleonMountedtypescript
import { onMounted } from 'vue'
// 在setup()中
onMounted(() => {
let attempts = 0
const fix = setInterval(() => {
document.querySelectorAll('.mermaid svg [style]').forEach(el => {
const s = (el as HTMLElement).style
if (s.fill && !s.fill.includes('#1e3a5f')) s.fill = '#1e3a5f'
if (s.stroke && !s.stroke.includes('#4a9eed')) s.stroke = '#4a9eed'
if (s.color) s.color = '#e0e0e0'
})
if (++attempts >= 20) clearInterval(fix)
}, 500)
})使用配合,不要使用——SSR期间DOM不存在。
setup()onMountedenhanceApp()Click-to-Zoom for Mermaid Diagrams
Mermaid图表的点击缩放功能
Wrap each container in a clickable wrapper that opens a fullscreen modal:
.mermaidtypescript
document.querySelectorAll('.mermaid').forEach(el => {
el.style.cursor = 'zoom-in'
el.addEventListener('click', () => {
const modal = document.createElement('div')
modal.className = 'mermaid-zoom-modal'
modal.innerHTML = el.outerHTML
modal.addEventListener('click', () => modal.remove())
document.body.appendChild(modal)
})
})Modal CSS:
css
.mermaid-zoom-modal {
position: fixed; inset: 0;
background: rgba(0,0,0,0.9);
display: flex; align-items: center; justify-content: center;
z-index: 9999; cursor: zoom-out;
}
.mermaid-zoom-modal .mermaid { transform: scale(1.5); }将每个容器包裹在可点击的容器中,点击后打开全屏模态框:
.mermaidtypescript
document.querySelectorAll('.mermaid').forEach(el => {
el.style.cursor = 'zoom-in'
el.addEventListener('click', () => {
const modal = document.createElement('div')
modal.className = 'mermaid-zoom-modal'
modal.innerHTML = el.outerHTML
modal.addEventListener('click', () => modal.remove())
document.body.appendChild(modal)
})
})模态框CSS:
css
.mermaid-zoom-modal {
position: fixed; inset: 0;
background: rgba(0,0,0,0.9);
display: flex; align-items: center; justify-content: center;
z-index: 9999; cursor: zoom-out;
}
.mermaid-zoom-modal .mermaid { transform: scale(1.5); }Post-Processing Rules
后处理规则
Before VitePress build, scan all files and fix:
.md- Replace with
<br/>(Vue template compiler compatibility)<br> - Wrap bare generic parameters in backticks outside code fences
<T> - Ensure every page has YAML frontmatter with and
titledescription
在VitePress构建前,扫描所有文件并修复以下问题:
.md- 将替换为
<br/>(兼容Vue模板编译器)<br> - 在代码块外的裸泛型参数前后添加反引号
<T> - 确保每个页面都包含带有和
title的YAML前置元数据description
Build
构建步骤
bash
cd wiki-site && npm install && npm run docs:buildOutput goes to .
wiki-site/.vitepress/dist/bash
cd wiki-site && npm install && npm run docs:build构建产物输出到目录。
wiki-site/.vitepress/dist/Known Gotchas
已知问题
- Mermaid renders async — SVGs don't exist when fires. Must poll.
onMounted - compiler option for bare
isCustomElementcauses worse crashes — do NOT use it<T> - Node text in Mermaid uses inline with highest specificity — CSS alone won't fix it
style - runs during SSR where
enhanceApp()doesn't exist — usedocumentonlysetup()
- Mermaid是异步渲染的——触发时SVG还不存在,必须使用轮询。
onMounted - 为裸设置
<T>编译器选项会导致更严重的崩溃——请勿使用。isCustomElement - Mermaid中的节点文本使用具有最高优先级的内联——仅靠CSS无法修复。
style - 在SSR期间运行,此时
enhanceApp()不存在——仅使用document。setup()