wiki-vitepress
microsoft/skills
该软件包将生成的维基 Markdown 内容转换为采用深色主题的 VitePress 静态网站,其中包含支持点击缩放的深色模式 Mermaid 图表,并提供生产环境构建输出。
...展开全部Wiki VitePress 打包工具
将生成的维基 Markdown 文件转换为采用深色主题并包含交互式 Mermaid 图表的精美 VitePress 静态网站。
何时启用
- 用户请求“构建网站”或“打包为 VitePress”
- 用户执行
/deep-wiki:build命令 - 用户希望将生成的维基页面导出为可浏览的 HTML 文件
VitePress 框架
在wiki-site/目录中生成以下结构:
wiki-site/
├── .vitepress/
│ ├── config.mts
│ └── theme/
│ ├── index.ts
│ └── custom.css
├── public/
├── [生成的 .md 页面]
├── package.json
└── index.md
配置要求(config.mts)
- 请使用
vitepress-plugin-mermaid提供的withMermaid封装器 - 若要使用纯深色主题
,请将appearance设置为 'dark' - 根据目录结构配置
themeConfig.nav和themeConfig.sidebar - Mermaid 配置必须设置深色主题变量:
mermaid: {
theme: 'dark',
themeVariables: {
primaryColor: '#1e3a5f',
primaryTextColor: '#e0e0e0',
primaryBorderColor: '#4a9eed',
lineColor: '#4a9eed',
secondaryColor: '#2d4a3e',
tertiaryColor: '#2d2d3d',
background: '#1a1a2e',
主背景色: '#1e3a5f',
节点边框色: '#4a9eed',
簇背景色: '#16213e',
标题色: '#e0e0e0',
边标签背景色: '#1a1a2e'
}
}
深色模式 Mermaid:三层修复方案
第 1 层:主题变量(位于 config.mts 中)
如上所示,通过mermaid.themeVariables进行设置。
第二层:CSS 覆盖(custom.css)
使用!important 针对 Mermaid 的 SVG 元素进行样式覆盖:
.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; }
第 3 层:内联样式替换(theme/index.ts)
Mermaid 的内联样式属性会覆盖所有设置。使用onMounted结合轮询机制来替换它们:
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)
})
请在onMounted 钩子中使用setup(),而非enhanceApp()—— 服务器端渲染(SSR)期间 DOM 尚未存在。
Mermaid 图表的点击缩放功能
将每个.mermaid容器包裹在一个可点击的包装器中,点击后会打开全屏模态框:
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:
.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); }
后处理规则
在 VitePress 构建之前,扫描所有.md文件并修复:
- 替换
为(兼容 Vue 模板编译器) - 将裸露的
泛型参数用反引号包裹,并置于代码围栏之外 - 确保每个页面都有包含
标题和描述的YAML 前置信息
构建
cd wiki-site && npm install && npm run docs:build
输出结果位于wiki-site/.vitepress/dist/ 目录下。
已知问题
- Mermaid 渲染是异步进行的——当
onMounted触发时,SVG 文件尚不存在。必须进行轮询。 - 对于裸元素,
isCustomElement编译器选项会导致更严重的崩溃——请勿使用 - Mermaid 中的 Node 文本使用特异性最高的内联
样式——仅靠 CSS 无法解决此问题 enhanceApp()在服务器端渲染(SSR)期间运行,此时文档不存在——请仅使用setup()
---
name: wiki-vitepress
description: Packages generated wiki Markdown into a VitePress static site with dark theme, dark-mode Mermaid diagrams with click-to-zoom, and production build output.
license: MIT
---
# Wiki VitePress Packager
Transform generated wiki Markdown files into a polished VitePress static site with dark theme and interactive Mermaid diagrams.
## When to Activate
- User asks to "build a site" or "package as VitePress"
- User runs the `/deep-wiki:build` command
- User wants a browsable HTML output from generated wiki pages
## VitePress Scaffolding
Generate the following structure in a `wiki-site/` directory:
```
wiki-site/
├── .vitepress/
│ ├── config.mts
│ └── theme/
│ ├── index.ts
│ └── custom.css
├── public/
├── [generated .md pages]
├── package.json
└── index.md
```
## Config Requirements (`config.mts`)
- Use `withMermaid` wrapper from `vitepress-plugin-mermaid`
- Set `appearance: 'dark'` for dark-only theme
- Configure `themeConfig.nav` and `themeConfig.sidebar` from the catalogue structure
- 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'
}
}
```
## Dark-Mode Mermaid: Three-Layer Fix
### Layer 1: Theme Variables (in config.mts)
Set via `mermaid.themeVariables` as shown above.
### Layer 2: CSS Overrides (`custom.css`)
Target Mermaid SVG elements with `!important`:
```css
.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`)
Mermaid inline `style` attributes override everything. Use `onMounted` + polling to replace them:
```typescript
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 `setup()` with `onMounted`, NOT `enhanceApp()` — DOM doesn't exist during SSR.
## Click-to-Zoom for Mermaid Diagrams
Wrap each `.mermaid` container in a clickable wrapper that opens a fullscreen modal:
```typescript
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); }
```
## Post-Processing Rules
Before VitePress build, scan all `.md` files and fix:
- Replace `<br/>` with `<br>` (Vue template compiler compatibility)
- Wrap bare `<T>` generic parameters in backticks outside code fences
- Ensure every page has YAML frontmatter with `title` and `description`
## Build
```bash
cd wiki-site && npm install && npm run docs:build
```
Output goes to `wiki-site/.vitepress/dist/`.
## Known Gotchas
- Mermaid renders async — SVGs don't exist when `onMounted` fires. Must poll.
- `isCustomElement` compiler option for bare `<T>` causes worse crashes — do NOT use it
- Node text in Mermaid uses inline `style` with highest specificity — CSS alone won't fix it
- `enhanceApp()` runs during SSR where `document` doesn't exist — use `setup()` only





首页
