From 86296b26b9e60ce9c1f64da4908dd49ea6a38f68 Mon Sep 17 00:00:00 2001 From: Ri-Nai Date: Thu, 25 Sep 2025 11:55:17 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=20'images'=20?= =?UTF-8?q?=E5=92=8C=20'docker=5Fsupport'=20=E5=88=B0=E6=8E=92=E9=99=A4?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vitepress/navSidebar.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.vitepress/navSidebar.ts b/.vitepress/navSidebar.ts index 2212fa6..935cf1e 100644 --- a/.vitepress/navSidebar.ts +++ b/.vitepress/navSidebar.ts @@ -10,6 +10,8 @@ const EXCLUDED_DIRS = new Set([ '.github', '.vitepress', 'node_modules', + 'images', + 'docker_support', 'public', 'docs', 'images', From ca6fa28d0f0bcf057d83a7454493c039968d5662 Mon Sep 17 00:00:00 2001 From: Ri-Nai Date: Thu, 25 Sep 2025 11:56:48 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E7=94=9F?= =?UTF-8?q?=E6=88=90=E7=9A=84=E4=BE=A7=E8=BE=B9=E6=A0=8F=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E6=AF=8F=E4=B8=80=E7=B1=BB=E7=9A=84?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E4=BC=9A=E8=87=AA=E5=8A=A8=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E5=88=B0=20README=20=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vitepress/navSidebar.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.vitepress/navSidebar.ts b/.vitepress/navSidebar.ts index 935cf1e..d4b225f 100644 --- a/.vitepress/navSidebar.ts +++ b/.vitepress/navSidebar.ts @@ -65,7 +65,8 @@ export function generateNavAndSidebar(rootDir: string) { sidebar[`/${dir}/`] = [ { text: dir, - items, + link: readme ? `/${encodeURI(dir)}/${encodeURI(readme)}` : undefined, + items: items.filter((i) => i.link !== (readme ? `/${encodeURI(dir)}/${encodeURI(readme)}` : undefined)), }, ] if (readme) { From 09ed73b1590b9d850b0040f43aaa1fedd95c2995 Mon Sep 17 00:00:00 2001 From: Ri-Nai Date: Thu, 25 Sep 2025 12:01:36 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E5=AE=9A=E4=B9=89=E5=8F=98=E9=87=8F?= =?UTF-8?q?=EF=BC=8C=E5=87=8F=E5=B0=91=E9=87=8D=E5=A4=8D=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vitepress/navSidebar.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.vitepress/navSidebar.ts b/.vitepress/navSidebar.ts index d4b225f..613a810 100644 --- a/.vitepress/navSidebar.ts +++ b/.vitepress/navSidebar.ts @@ -60,17 +60,17 @@ export function generateNavAndSidebar(rootDir: string) { // Find README.md、readme.md、index.md const readme = ['README.md', 'readme.md', 'index.md'].find((n) => fs.existsSync(path.join(abs, n))) - + const readmeURI = readme ? `/${encodeURI(dir)}/${encodeURI(readme)}` : "/"; if (items.length > 0) { sidebar[`/${dir}/`] = [ { text: dir, - link: readme ? `/${encodeURI(dir)}/${encodeURI(readme)}` : undefined, - items: items.filter((i) => i.link !== (readme ? `/${encodeURI(dir)}/${encodeURI(readme)}` : undefined)), + link: readmeURI, + items: items.filter((i) => i.link !== readmeURI), }, ] if (readme) { - nav.push({ text: dir, link: `/${encodeURI(dir)}/${encodeURI(readme)}` }) + nav.push({ text: dir, link: readmeURI }) } else { nav.push({ text: dir, link: items[0].link! }) } From 9a80036d6647aa7de3b98878443bf302dccfd5b7 Mon Sep 17 00:00:00 2001 From: Ri-Nai Date: Thu, 25 Sep 2025 12:16:19 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8=20VitePress=20?= =?UTF-8?q?=E7=9A=84=E7=B1=BB=E5=9E=8B=E5=AE=9A=E4=B9=89=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=AF=BC=E8=88=AA=E5=92=8C=E4=BE=A7=E8=BE=B9=E6=A0=8F=E7=94=9F?= =?UTF-8?q?=E6=88=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vitepress/navSidebar.ts | 48 +++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/.vitepress/navSidebar.ts b/.vitepress/navSidebar.ts index 613a810..8b2a2a4 100644 --- a/.vitepress/navSidebar.ts +++ b/.vitepress/navSidebar.ts @@ -1,8 +1,10 @@ import fs from 'node:fs' import path from 'node:path' +import type { DefaultTheme } from 'vitepress' -export type SidebarItem = { text: string; link?: string; items?: SidebarItem[] } -export type Sidebar = Record +export type SidebarItem = DefaultTheme.SidebarItem +export type NavItem = DefaultTheme.NavItem +export type Sidebar = DefaultTheme.Sidebar const DOC_EXT = ['.md'] const EXCLUDED_DIRS = new Set([ @@ -42,9 +44,13 @@ export function generateNavAndSidebar(rootDir: string) { .filter((e) => !EXCLUDED_DIRS.has(e) && !e.startsWith('.')) sections.sort(sortByPinyinOrName) - const nav: { text: string; link: string }[] = [] + const nav: NavItem[] = [] const sidebar: Sidebar = {} + // This is the item type we generate from files. It has a required text and link. + // It is compatible with both NavItem and SidebarItem. + type LinkItem = { text: string; link: string } + for (const dir of sections) { const abs = path.join(rootDir, dir) const files = fs @@ -52,28 +58,40 @@ export function generateNavAndSidebar(rootDir: string) { .filter((f) => isMarkdown(path.join(abs, f))) .sort(sortByPinyinOrName) - // Build sidebar for this section - const items: SidebarItem[] = files.map((f) => ({ + const items: LinkItem[] = files.map((f) => ({ text: titleFromName(f), link: `/${encodeURI(dir)}/${encodeURI(f)}`, })) - // Find README.md、readme.md、index.md - const readme = ['README.md', 'readme.md', 'index.md'].find((n) => fs.existsSync(path.join(abs, n))) - const readmeURI = readme ? `/${encodeURI(dir)}/${encodeURI(readme)}` : "/"; if (items.length > 0) { + const readme = ['README.md', 'readme.md', 'index.md'].find((n) => + fs.existsSync(path.join(abs, n)), + ) + const readmeURI = readme ? `/${encodeURI(dir)}/${encodeURI(readme)}` : undefined + + let sectionLink: string + let sectionItems: LinkItem[] + + if (readmeURI) { + sectionLink = readmeURI + sectionItems = items.filter((i) => i.link !== readmeURI) + } else { + sectionLink = items[0].link! + sectionItems = items.slice(1) + } + sidebar[`/${dir}/`] = [ { text: dir, - link: readmeURI, - items: items.filter((i) => i.link !== readmeURI), + link: sectionLink, + items: sectionItems, }, ] - if (readme) { - nav.push({ text: dir, link: readmeURI }) - } else { - nav.push({ text: dir, link: items[0].link! }) - } + + nav.push({ + text: dir, + link: sectionLink, + }) } else { nav.push({ text: dir, link: `/${encodeURI(dir)}/` }) }