diff --git a/.vitepress/sidebar.ts b/.vitepress/sidebar.ts index 4aa57654..66c84626 100644 --- a/.vitepress/sidebar.ts +++ b/.vitepress/sidebar.ts @@ -6,24 +6,34 @@ // - 英文:CI 构建时 translate/translated 会被合并进 docs/,故优先读 docs/ // 下的编号目录,本地 dev 回退读 translate/translated // - downloadFile.json 中声明的 CI 下载页面(如 Agent 配置)静态并入 +// - 各级目录(分区与子目录分组)的展示名取自仓库根 LOCALES/{zh,en}.json import fs from 'node:fs' import path from 'node:path' import rewrites from './rewrites.generated.json' const ROOT = path.resolve(import.meta.dirname, '..') -/** 分区清单:文档信息架构的唯一人工维护来源 */ -const SECTIONS: Record = { - '01-about': { en: 'About', zh: '关于 DeepFlow' }, - '02-ce-install': { en: 'Community Edition Installation', zh: '社区版安装' }, - '03-ee-install': { en: 'Enterprise Edition Installation', zh: '企业版安装' }, - '04-best-practice': { en: 'Best Practices', zh: '最佳实践' }, - '05-features': { en: 'Features', zh: '功能特性' }, - '06-guide': { en: 'Guide', zh: '使用指南' }, - '07-configuration': { en: 'Configuration', zh: '配置说明' }, - '08-integration': { en: 'Integration', zh: '集成' }, - '09-diagnose': { en: 'Troubleshooting', zh: '故障诊断' }, - '10-release-notes': { en: 'Release Notes', zh: '版本发布笔记' } +/** 分区目录清单:文档信息架构的唯一人工维护来源,数组顺序即分区顺序, + * 展示名见 LOCALES/{zh,en}.json 中的一级 key */ +const SECTION_DIRS = [ + '01-about', + '02-ce-install', + '03-ee-install', + '04-best-practice', + '05-features', + '06-guide', + '07-configuration', + '08-integration', + '09-diagnose', + '10-release-notes' +] + +// 目录展示名的翻译存于仓库根 LOCALES/{zh,en}.json(迁移前旧 vdoing 主题的 +// 原文件原样恢复),key 为去掉数字前缀的逻辑路径,覆盖顶级分区与子目录分组: +// 目录重新编号无需同步改 key,查不到回退 humanizeDir +const dirTitles: Record<'en' | 'zh', Record> = { + en: JSON.parse(fs.readFileSync(path.join(ROOT, 'LOCALES/en.json'), 'utf8')), + zh: JSON.parse(fs.readFileSync(path.join(ROOT, 'LOCALES/zh.json'), 'utf8')) } /** 常见缩写,避免 humanize 出现 "Ee Tenant" 这类展示名 */ @@ -84,15 +94,18 @@ function linkFor(relPath: string): string | null { return '/' + target.replace(/\.md$/, '') } -function walkDir(dir: string, relBase: string): (LinkItem | GroupItem)[] { +function walkDir(dir: string, relBase: string, logicalBase: string, lang: 'en' | 'zh'): (LinkItem | GroupItem)[] { const items: (LinkItem | GroupItem)[] = [] const entries = fs.readdirSync(dir).filter((n) => !n.startsWith('.')).sort(byNumericPrefix) for (const name of entries) { const full = path.join(dir, name) const rel = `${relBase}/${name}` if (fs.statSync(full).isDirectory()) { - const children = walkDir(full, rel) - if (children.length) items.push({ text: humanizeDir(name), collapsed: true, items: children }) + const logical = `${logicalBase}/${name.replace(/^\d+-/, '')}` + const children = walkDir(full, rel, logical, lang) + if (children.length) { + items.push({ text: dirTitles[lang][logical] ?? humanizeDir(name), collapsed: true, items: children }) + } continue } if (!name.endsWith('.md') || name === 'README.md' || name === 'index.md') continue @@ -109,29 +122,35 @@ function walkDir(dir: string, relBase: string): (LinkItem | GroupItem)[] { function buildSidebar(treeRoot: string, prefix: string, lang: 'en' | 'zh'): GroupItem[] { const result: GroupItem[] = [] - for (const [dir, labels] of Object.entries(SECTIONS)) { + for (const dir of SECTION_DIRS) { const sectionDir = path.join(treeRoot, dir) if (!fs.existsSync(sectionDir)) continue - const items = walkDir(sectionDir, `${prefix}${dir}`) - if (items.length) result.push({ text: labels[lang], collapsed: true, items }) + const logical = dir.replace(/^\d+-/, '') + const items = walkDir(sectionDir, `${prefix}${dir}`, logical, lang) + if (items.length) { + result.push({ text: dirTitles[lang][logical] ?? humanizeDir(dir), collapsed: true, items }) + } } return result } /** downloadFile.json 声明的 CI 下载页面静态并入(本地 dev 时文件尚不存在) */ -function mergeDownloadedPages(items: GroupItem[]): void { +function mergeDownloadedPages(items: GroupItem[], lang: 'en' | 'zh'): void { const jsonPath = path.join(ROOT, 'downloadFile.json') if (!fs.existsSync(jsonPath)) return for (const { output, meta } of JSON.parse(fs.readFileSync(jsonPath, 'utf8'))) { const rel = output.replace(/^\.\//, '').replace(/^docs\//, '') const section = rel.replace(/^zh\//, '').split('/')[0] - let group = items.find((g) => g.text === SECTIONS[section]?.en || g.text === SECTIONS[section]?.zh) + const title = dirTitles[lang][section.replace(/^\d+-/, '')] ?? humanizeDir(section) + let group = items.find((g) => g.text === title) if (!group) { - group = { text: SECTIONS[section]?.en ?? section, collapsed: true, items: [] } + group = { text: title, collapsed: true, items: [] } items.push(group) } const link = linkFor(rel) if (!link) continue + // CI 构建时该文件已存在并被上方 walkDir 收录,避免重复条目 + if (group.items.some((i) => 'link' in i && i.link === link)) continue group.items.push({ text: meta.title || humanizeDir(path.basename(rel)), link }) } } @@ -142,9 +161,9 @@ const enRoot = fs.existsSync(path.join(ROOT, 'docs/01-about')) : path.join(ROOT, 'translate/translated') const enSidebar = buildSidebar(enRoot, '', 'en') -mergeDownloadedPages(enSidebar) +mergeDownloadedPages(enSidebar, 'en') const zhSidebar = buildSidebar(path.join(ROOT, 'docs/zh'), 'zh/', 'zh') -mergeDownloadedPages(zhSidebar) +mergeDownloadedPages(zhSidebar, 'zh') export const sidebar = { '/zh/': zhSidebar, diff --git a/LOCALES/en.json b/LOCALES/en.json new file mode 100644 index 00000000..9b7e32ca --- /dev/null +++ b/LOCALES/en.json @@ -0,0 +1,44 @@ +{ + "about": "About DeepFlow", + "ce-install": "Install (Community Edition)", + "ee-install": "Install (Enterprise Edition)", + "ee-install/saas": "SaaS", + "ee-install/on-prem": "On-Prem", + "best-practice": "Best Practice", + "features": "Features", + "features/l7-protocols": "Application Protocols", + "features/universal-map": "Universal Map", + "features/distributed-tracing": "Distributed Tracing", + "features/continuous-profiling": "Continuous Profiling", + "features/auto-tagging": "AutoTagging", + "guide": "User Guide", + "guide/quick-start": "Quick Start", + "guide/ee-tenant": "Tenant (Enterprise Edition)", + "guide/ee-tenant/query": "Data Query", + "guide/ee-tenant/dashboard": "Dashboard", + "guide/ee-tenant/dashboard/panel": "Panel", + "guide/ee-tenant/universal-map": "Universal Map", + "guide/ee-tenant/tracing": "Tracing", + "guide/ee-tenant/profiling": "Profiling", + "guide/ee-tenant/network": "Network", + "guide/ee-tenant/metrics": "Metrics", + "guide/ee-tenant/log": "Log", + "guide/ee-tenant/alert": "Alert", + "guide/ee-tenant/report": "Report", + "guide/ee-tenant/resources": "Resources", + "guide/ee-tenant/system": "System", + "guide/ee-tenant/configuration": "Configuration", + "configuration": "Configuration", + "integration": "Integration", + "integration/process": "Process", + "integration/input": "Input", + "integration/input/metrics": "Metrics Collector", + "integration/input/tracing": "Tracing Collector", + "integration/input/profile": "Profile Collector", + "integration/input/log": "Log Collector", + "integration/output": "Output", + "integration/output/query": "Query API", + "integration/output/export": "Exporter", + "diagnose": "Diagnose", + "release-notes": "Release Notes" +} diff --git a/LOCALES/zh.json b/LOCALES/zh.json new file mode 100644 index 00000000..73637af5 --- /dev/null +++ b/LOCALES/zh.json @@ -0,0 +1,44 @@ +{ + "about": "关于 DeepFlow", + "ce-install": "安装社区版", + "ee-install": "安装企业版", + "ee-install/saas": "SaaS", + "ee-install/on-prem": "On-Prem", + "best-practice": "最佳实践", + "features": "核心特性", + "features/l7-protocols": "应用协议", + "features/universal-map": "服务全景图", + "features/distributed-tracing": "分布式追踪", + "features/continuous-profiling": "持续性能剖析", + "features/auto-tagging": "AutoTagging", + "guide": "使用帮助", + "guide/quick-start": "快速上手", + "guide/ee-tenant": "企业版租户页面", + "guide/ee-tenant/query": "数据搜索", + "guide/ee-tenant/dashboard": "视图列表", + "guide/ee-tenant/dashboard/panel": "图表", + "guide/ee-tenant/universal-map": "业务观测", + "guide/ee-tenant/tracing": "应用观测", + "guide/ee-tenant/profiling": "代码观测", + "guide/ee-tenant/network": "网络观测", + "guide/ee-tenant/metrics": "指标中心", + "guide/ee-tenant/log": "日志中心", + "guide/ee-tenant/alert": "告警管理", + "guide/ee-tenant/report": "报表管理", + "guide/ee-tenant/resources": "资产列表", + "guide/ee-tenant/system": "系统管理", + "guide/ee-tenant/configuration": "个人设置", + "configuration": "配置手册", + "integration": "开发与集成", + "integration/process": "数据处理", + "integration/input": "数据输入", + "integration/input/metrics": "导入 Metrics", + "integration/input/tracing": "导入 Tracing", + "integration/input/profile": "导入 Profile", + "integration/input/log": "导入 Log", + "integration/output": "数据输出", + "integration/output/query": "查询 API", + "integration/output/export": "导出输出", + "diagnose": "故障处理", + "release-notes": "发行注记" +}