From 2175d7145652a6f8324601065ca91aadd749f719 Mon Sep 17 00:00:00 2001 From: luckyasme <807254037@qq.com> Date: Thu, 13 Mar 2025 20:27:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E5=AD=97=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/.vitepress/src/assets/style/markdown.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/.vitepress/src/assets/style/markdown.scss b/docs/.vitepress/src/assets/style/markdown.scss index 0233682..57a96d9 100644 --- a/docs/.vitepress/src/assets/style/markdown.scss +++ b/docs/.vitepress/src/assets/style/markdown.scss @@ -110,7 +110,7 @@ color: var(--o-color-info1); padding: 0; border: none; - font-weight: 500; + font-weight: 600; } h1 { -- Gitee From 6ca91fe436081f35846173bbaa632998c63757e7 Mon Sep 17 00:00:00 2001 From: luckyasme <807254037@qq.com> Date: Thu, 13 Mar 2025 20:28:04 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96404=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 7 +++- docs/.vitepress/src/App.vue | 16 ++------- .../src/components/DocBreadCrumb.vue | 34 ++++++------------- docs/.vitepress/src/config/home.ts | 24 ++++++------- docs/.vitepress/src/layouts/LayoutDoc.vue | 8 +++-- scripts/build.js | 32 +++++++++++++++-- 6 files changed, 65 insertions(+), 56 deletions(-) diff --git a/.gitignore b/.gitignore index 53eb3c2..f9d0743 100644 --- a/.gitignore +++ b/.gitignore @@ -125,4 +125,9 @@ docs/.vitepress/cache docs/.vitepress/public/menu/menu.json docs/.vitepress/public/menu/menu-en.json -temp-docs \ No newline at end of file +temp-docs + +docs/zh/*/index.md +docs/en/*/index.md +docs/zh/Tools/*/index.md +docs/en/Tools/*/index.md \ No newline at end of file diff --git a/docs/.vitepress/src/App.vue b/docs/.vitepress/src/App.vue index 4fe772d..4df67b7 100644 --- a/docs/.vitepress/src/App.vue +++ b/docs/.vitepress/src/App.vue @@ -28,28 +28,18 @@ const menuStore = useMenuStore(); const route = useRoute(); const router = useRouter(); +const data = useData(); // -------------------- 判断页面url -------------------- -const nodeVisible = ref(); -const pageType = () => { - const pathHref = route.path.replace('.html', ''); - nodeVisible.value = menuStore.allNodes.some((item) => item.href === pathHref); - if (!nodeVisible.value) { - const moduleMenu = menuStore.allNodes.find((item) => item?.href && pathHref.includes(item.href)); - nodeVisible.value = moduleMenu?.children.some((item) => item.href === pathHref); - } +const nodeVisible = computed(() => data.frontmatter.value.overview); - return nodeVisible.value; -}; // -------------------- 判断布局类型 -------------------- const { frontmatter } = useData(); const isCustomLayout = computed(() => { - // 判断是否是文档节点页面 - const isModule = pageType(); // 判断是否是首页 const isHome = route.component?.name?.includes(`${locale.value}/index`); - return (frontmatter.value.layout === 'page' && !isModule) || isHome; + return (frontmatter.value.layout === 'page' && !nodeVisible.value) || isHome; }); router.onBeforeRouteChange = () => { diff --git a/docs/.vitepress/src/components/DocBreadCrumb.vue b/docs/.vitepress/src/components/DocBreadCrumb.vue index 0920a77..0e682f8 100644 --- a/docs/.vitepress/src/components/DocBreadCrumb.vue +++ b/docs/.vitepress/src/components/DocBreadCrumb.vue @@ -26,19 +26,16 @@ const props = defineProps({ const menuStore = useMenuStore(); // -------------------- 文档模块节点标题 -------------------- -const moduleMenu = ref(); const moduleNode = computed(() => { const pathHref = route.path.replace('.html', ''); - const flag = pathHref.includes('/zh/Tools') || pathHref.includes('/en/Tools'); - const nodeMenu = menuStore.allNodes.find((item) => item?.href && pathHref.includes(item?.href)); - const childMenu = nodeMenu?.children?.find((item) => item?.href && pathHref.includes(item?.href)); + const nodeMenu = menuStore.allNodes.find((item) => item?.href && pathHref.includes(item.href.replace('index.html', ''))); - moduleMenu.value = flag ? childMenu : nodeMenu; - - return { - title: moduleMenu.value?.label, - href: moduleMenu.value?.href?.includes('.html') ? moduleMenu.value?.href : `${moduleMenu.value?.href}.html`, - }; + if (pathHref.includes('/Tools/')) { + const childMenu = nodeMenu?.children?.find((item) => item?.href && pathHref.includes(item.href.replace('index.html', ''))); + return childMenu; + } + + return nodeMenu; }); // 是否是贡献指南手册,直接显示 文档中心 > 贡献指南的具体章节 @@ -50,22 +47,11 @@ const isContribute = computed(() => { // -------------------- 当前节点标题 -------------------- const currentTitle = computed(() => { if (props.nodeVisible) { - // 修改页签的标题 - if (isClient) { - document.title = `${moduleNode.value.title} | ${t('docs.document')} | openEuler社区`; - } - - return moduleNode.value.title; + return moduleNode.value?.label; } return menuStore.currentNode?.href?.includes('#') ? menuStore.currentNode?.parent?.label : menuStore.currentNode?.label; }); -onMounted(() => { - // 页面加载完成后 浏览器页签的标题 - if (props.nodeVisible) { - document.title = `${moduleNode.value.title} | ${t('docs.document')} | openEuler社区`; - } -}); // -------------------- 跳转 -------------------- const router = useRouter(); @@ -85,8 +71,8 @@ const goToPage = (href: string) => { 文档中心 - {{ moduleNode.title }} - {{ moduleNode.title }} + {{ moduleNode?.label }} + {{ moduleNode?.label }} {{ searchStore.isSearching ? '搜索结果' : currentTitle }} diff --git a/docs/.vitepress/src/config/home.ts b/docs/.vitepress/src/config/home.ts index f601988..9431da4 100644 --- a/docs/.vitepress/src/config/home.ts +++ b/docs/.vitepress/src/config/home.ts @@ -90,35 +90,35 @@ export const businessScenarioList = [ background: BgServer, title: '服务器', desc: '提供服务器场景的安装升级、管理运维、性能调优、应用开发等操作指南。', - href: '/zh/Server.html', + href: '/zh/Server/index.html', }, { icon: IconVirtualization, background: BgVirtualization, title: '虚拟化', desc: '提供虚拟化场景(云计算)的用户指南,帮助用户了解虚拟化,以及安装和使用虚拟化。', - href: '/zh/Virtualization.html', + href: '/zh/Virtualization/index.html', }, { icon: IconCloud, background: BgCloud, title: '云原生', desc: '提供云原生场景(云计算)的用户指南,帮助用户安装和使用容器,部署集群等。', - href: '/zh/Cloud.html', + href: '/zh/Cloud/index.html', }, { icon: IconEdgeComputing, background: BgEdgeComputing, title: '边缘计算', desc: '提供KubeEdge、K3S的安装和使用介绍。', - href: '/zh/EdgeComputing.html', + href: '/zh/EdgeComputing/index.html', }, { icon: IconEmbedded, background: BgEmbedded, title: '嵌入式', desc: '提供嵌入式场景的镜像构建、应用开发、系统管理等操作指南。', - href: '/zh/Embedded.html', + href: '/zh/Embedded/index.html', }, ]; @@ -126,36 +126,36 @@ export const toolList = [ { title: '社区工具', desc: '提供镜像构建、编译、测试、性能优化、迁移、发布、软件包构建、虚拟化工具使用指南,如isocut、imageTailor、A-Tune、oeA…', - href: '/zh/Tools/CommunityTools.html', + href: '/zh/Tools/CommunityTools/index.html', }, { title: 'DevOps(社区服务)', desc: '提供社区服务使用指南,包括patch-tracking、pkgship、EulerMaker、EulerDev…', - href: '/zh/Tools/DevOps.html', + href: '/zh/Tools/DevOps/index.html', }, { title: 'AI', desc: '提供EulerCopilot智能问答使用指南、AI大模型服务镜像使用指南。', - href: '/zh/Tools/AI.html', + href: '/zh/Tools/AI/index.html', }, { title: '图形桌面使用', desc: '提供桌面环境的安装和使用指南,包括UKUI、DDE、XFCE、Gnome、Kiran、I3', - href: '/zh/Tools/desktop.html', + href: '/zh/Tools/desktop/index.html', }, { title: '云原生', desc: '提供虚拟户场景下常用工具用户指南,包含虚拟机数据收集和分析工具vmtop,qemu热补丁框架工具LibcarePlus', - href: '/zh/Tools/Cloud.html', + href: '/zh/Tools/Cloud/index.html', }, { title: '系统运维', desc: '提供服务器运维常用工具使用指南,包含智能运维框架Aops,异常监控服务sysmonitor', - href: '/zh/Tools/Maintenance.html', + href: '/zh/Tools/Maintenance/index.html', }, { title: '安全', desc: '提供服务器安全配置常用工具使用指南,包含机密计算统一开发框架secGear、OS内构入侵检测系统secDetector、安全防护系统safeg…', - href: '/zh/Tools/Security.html', + href: '/zh/Tools/Security/index.html', }, ]; diff --git a/docs/.vitepress/src/layouts/LayoutDoc.vue b/docs/.vitepress/src/layouts/LayoutDoc.vue index 5f68d1d..b78ba45 100644 --- a/docs/.vitepress/src/layouts/LayoutDoc.vue +++ b/docs/.vitepress/src/layouts/LayoutDoc.vue @@ -255,9 +255,8 @@ const moduleNode = computed(() => { // -------------------- 文档模块menu -------------------- const docsMenu = computed(() => { - const pathHref = route.path.replace('.html', ''); if (props.nodeVisible) { - const flag = menuStore.allNodes.some((item) => item?.href && item.href === pathHref); + /* const flag = menuStore.allNodes.some((item) => item?.href && item.href === pathHref); // 最外层的子节点可以匹配到url if (flag) { const moduleMenu = menuStore.allNodes.find((item) => item?.href && item.href === pathHref); @@ -268,7 +267,10 @@ const docsMenu = computed(() => { const nodeMenu = childMenu?.children?.find((item) => item?.href && item.href === pathHref); return nodeMenu?.children || []; - } + } */ + const href = route.path.endsWith('/') ? `${route.path}index.html` : route.path; + const node = menuStore.rootTree.getNodeByHref(menuStore.rootTree.root, href); + return node?.children || []; } else if (menuStore.bookNodes.length > 0) { return menuStore.bookNodes; } diff --git a/scripts/build.js b/scripts/build.js index 469da72..5330dba 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -265,14 +265,19 @@ async function mergeReferences(filePath) { }); } + const currenDirName = path.dirname(filePath); + if (frontmatter.href) { // 处理当前文件的 href 字段 frontmatter.href = frontmatter.href.startsWith('http') ? frontmatter.href - : parseHref(path.resolve(path.dirname(filePath), frontmatter.href), frontmatter.label || ''); + : parseHref(path.resolve(currenDirName, frontmatter.href), frontmatter.label || ''); + frontmatter.type = 'page'; + } else if (fs.existsSync(path.join(currenDirName, 'index.md'))) { + frontmatter.href = parseHref(path.join(currenDirName, 'index.md'), frontmatter.label || ''); frontmatter.type = 'page'; } else { - frontmatter.href = parseHref(path.dirname(filePath), frontmatter.label || ''); + frontmatter.href = parseHref(currenDirName, frontmatter.label || ''); frontmatter.type = 'path'; } @@ -281,7 +286,7 @@ async function mergeReferences(filePath) { // 处理 children if (frontmatter.children) { - frontmatter.children = await parseNodeChildren(path.dirname(filePath), frontmatter.children); + frontmatter.children = await parseNodeChildren(currenDirName, frontmatter.children); } return frontmatter; @@ -296,6 +301,24 @@ async function mergeReferences(filePath) { return null; } +/** + * 创建index.md + */ +function createOverviewIndexMd(targetPath) { + const indexMdContent = `--- +title +overview: true +---`; + + fs.readdirSync(targetPath).forEach((item) => { + if (item !== 'Tools' && fs.statSync(path.join(targetPath, item)).isDirectory() && fs.existsSync(path.join(targetPath, item, '_menu.md'))) { + const content = fs.readFileSync(path.join(targetPath, item, '_menu.md'), 'utf-8'); + const { data: frontmatter } = matter(content); + fs.outputFileSync(path.join(targetPath, item, 'index.md'), indexMdContent.replace('title', `title: ${frontmatter.label}`)); + } + }); +} + /** * 处理文件 */ @@ -303,6 +326,9 @@ async function processMenuFile() { const menuFilePath = path.join(__dirname, './docs/zh/_menu.md'); const outputPath = path.join(__dirname, './docs/.vitepress/public/menu/menu.json'); + createOverviewIndexMd(path.join(__dirname, './docs/zh')); + createOverviewIndexMd(path.join(__dirname, './docs/zh/Tools')); + const updatedContent = await mergeReferences(menuFilePath); if (errors.length > 0) { console.table(errors); -- Gitee