|
| 1 | +import { defineConfig } from 'vitepress' |
| 2 | +import { readdirSync, statSync } from 'node:fs' |
| 3 | +import { join } from 'node:path' |
| 4 | +import type { DefaultTheme } from 'vitepress' |
| 5 | + |
| 6 | +function getSidebar(): DefaultTheme.Sidebar { |
| 7 | + const docsDir = join(import.meta.dirname, '..') |
| 8 | + const sidebar: DefaultTheme.Sidebar = {} |
| 9 | + |
| 10 | + const dirLabels: Record<string, string> = { |
| 11 | + guides: '使用指南', |
| 12 | + adr: '架构决策记录', |
| 13 | + dev: '开发文档', |
| 14 | + prd: '产品需求文档', |
| 15 | + } |
| 16 | + |
| 17 | + for (const dir of ['guides', 'adr', 'dev', 'prd']) { |
| 18 | + const fullDir = join(docsDir, dir) |
| 19 | + const items: DefaultTheme.SidebarItem[] = [] |
| 20 | + const entries = readdirSync(fullDir).sort() |
| 21 | + for (const entry of entries) { |
| 22 | + if (entry.startsWith('.')) continue |
| 23 | + const fullPath = join(fullDir, entry) |
| 24 | + if (entry.endsWith('.md')) { |
| 25 | + const name = entry.replace('.md', '') |
| 26 | + items.push({ |
| 27 | + text: name.replace(/-/g, ' ').replace(/\b\w/g, c => c.toUpperCase()), |
| 28 | + link: `/${dir}/${name}`, |
| 29 | + }) |
| 30 | + } else if (statSync(fullPath).isDirectory()) { |
| 31 | + const subEntries = readdirSync(fullPath).sort().filter(e => e.endsWith('.md')) |
| 32 | + if (subEntries.length > 0) { |
| 33 | + items.push({ |
| 34 | + text: entry.replace(/-/g, ' ').replace(/\b\w/g, c => c.toUpperCase()), |
| 35 | + collapsed: dir === 'dev' && entry === 'tasks', |
| 36 | + items: subEntries.map(e => ({ |
| 37 | + text: e.replace('.md', '').replace(/-/g, ' ').replace(/\b\w/g, c => c.toUpperCase()), |
| 38 | + link: `/${dir}/${entry}/${e.replace('.md', '')}`, |
| 39 | + })), |
| 40 | + }) |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + if (items.length > 0) { |
| 45 | + sidebar[`/${dir}/`] = [{ text: dirLabels[dir] || dir, items }] |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + return sidebar |
| 50 | +} |
| 51 | + |
| 52 | +export default defineConfig({ |
| 53 | + title: 'opencode-cabbage', |
| 54 | + description: '全流程开发 OpenCode 插件 — 需求→设计→任务→编码→测试→审查→自动合并', |
| 55 | + srcDir: '.', |
| 56 | + outDir: '../.vitepress-dist', |
| 57 | + lastUpdated: true, |
| 58 | + cleanUrls: true, |
| 59 | + |
| 60 | + themeConfig: { |
| 61 | + nav: [ |
| 62 | + { text: '首页', link: '/' }, |
| 63 | + { text: '快速开始', link: '/guides/quickstart' }, |
| 64 | + { |
| 65 | + text: '使用指南', |
| 66 | + items: [ |
| 67 | + { text: '快速开始', link: '/guides/quickstart' }, |
| 68 | + { text: '配置指南', link: '/guides/configuration' }, |
| 69 | + { text: '使用指南', link: '/guides/usage' }, |
| 70 | + { text: '架构概览', link: '/guides/architecture' }, |
| 71 | + ], |
| 72 | + }, |
| 73 | + { |
| 74 | + text: '开发', |
| 75 | + items: [ |
| 76 | + { text: '贡献指南', link: '/dev/guides/contributing' }, |
| 77 | + { text: '技术方案', link: '/dev/specs/opencode-cabbage-docs-and-pages' }, |
| 78 | + { text: 'VitePress 迁移', link: '/dev/specs/vitepress-docs-migration' }, |
| 79 | + { text: 'Out of Scope', link: '/dev/out-of-scope' }, |
| 80 | + ], |
| 81 | + }, |
| 82 | + { |
| 83 | + text: 'ADR', |
| 84 | + items: [ |
| 85 | + { text: '0001 - 替换 OpenSpec', link: '/adr/0001-replace-openspec-with-full-flow' }, |
| 86 | + { text: '0002 - Jekyll 文档站', link: '/adr/2026-07-10-jekyll-github-pages-docs' }, |
| 87 | + { text: '0003 - 迁移 VitePress', link: '/adr/2026-07-10-jekyll-to-vitepress' }, |
| 88 | + ], |
| 89 | + }, |
| 90 | + { |
| 91 | + text: 'PRD', |
| 92 | + items: [ |
| 93 | + { text: 'Docs & Pages', link: '/prd/opencode-cabbage-docs-and-pages' }, |
| 94 | + { text: 'VitePress 迁移', link: '/prd/vitepress-docs-migration' }, |
| 95 | + ], |
| 96 | + }, |
| 97 | + ], |
| 98 | + |
| 99 | + sidebar: getSidebar(), |
| 100 | + |
| 101 | + search: { |
| 102 | + provider: 'local', |
| 103 | + options: { |
| 104 | + translations: { |
| 105 | + button: { |
| 106 | + buttonText: '搜索', |
| 107 | + buttonAriaLabel: '搜索文档', |
| 108 | + }, |
| 109 | + modal: { |
| 110 | + displayDetails: '显示详情', |
| 111 | + noResultsText: '未找到相关结果', |
| 112 | + resetButtonTitle: '清除搜索', |
| 113 | + footer: { |
| 114 | + selectText: '选择', |
| 115 | + navigateText: '切换', |
| 116 | + closeText: '关闭', |
| 117 | + }, |
| 118 | + }, |
| 119 | + }, |
| 120 | + }, |
| 121 | + }, |
| 122 | + |
| 123 | + socialLinks: [ |
| 124 | + { icon: 'github', link: 'https://github.com/devcxl/opencode-cabbage' }, |
| 125 | + ], |
| 126 | + |
| 127 | + editLink: { |
| 128 | + pattern: 'https://github.com/devcxl/opencode-cabbage/edit/main/docs/:path', |
| 129 | + }, |
| 130 | + |
| 131 | + lastUpdated: { |
| 132 | + text: '最后更新', |
| 133 | + }, |
| 134 | + |
| 135 | + docFooter: { |
| 136 | + prev: '上一页', |
| 137 | + next: '下一页', |
| 138 | + }, |
| 139 | + }, |
| 140 | +}) |
0 commit comments