From 118f57c791d4c3971df63d8ef2d31e4bee2a84dd Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Sat, 14 Jun 2025 17:27:35 +0800 Subject: [PATCH] docs: improve `llms` toc --- docs/.vuepress/llmstxtTOC.ts | 19 ++++++++++--------- docs/README.md | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/.vuepress/llmstxtTOC.ts b/docs/.vuepress/llmstxtTOC.ts index 1b89f129..e296c026 100644 --- a/docs/.vuepress/llmstxtTOC.ts +++ b/docs/.vuepress/llmstxtTOC.ts @@ -38,6 +38,7 @@ export function tocGetter(llmPages: LLMPage[], llmState: LLMState): string { const page = llmPages.find((item) => { return ensureLeadingSlash(item.filePathRelative || '') === filepath || link === item.path }) + if (page) { usagePages.push(page) return rawGenerateTOCLink(page, llmState) @@ -48,9 +49,9 @@ export function tocGetter(llmPages: LLMPage[], llmState: LLMState): string { const processAutoSidebar = (prefix: string): string[] => { const list: string[] = [] llmPages.forEach((page) => { - if (page.path.startsWith(prefix)) { + if (ensureLeadingSlash(page.filePathRelative || '').startsWith(prefix)) { usagePages.push(page) - list.push(generateTOCLink(page.path)) + list.push(rawGenerateTOCLink(page, llmState)) } }) return list.filter(Boolean) @@ -80,17 +81,17 @@ export function tocGetter(llmPages: LLMPage[], llmState: LLMState): string { // Notes zhNotes.notes.forEach(({ dir, link, sidebar = [] }) => { tableOfContent += `### ${noteNames[link]}\n\n` - + const prefix = normalizePath('/notes/', dir) if (sidebar === 'auto') { - tableOfContent += `${processAutoSidebar(link).join('')}\n` + tableOfContent += `${processAutoSidebar(prefix).join('')}\n` } else if (sidebar.length) { - const index = llmPages.findIndex(page => page.path === link) - if (index !== -1) { - usagePages.push(llmPages[index]) - tableOfContent += rawGenerateTOCLink(llmPages[index], llmState) + const home = generateTOCLink(ensureEndingSlash(prefix)) + const list = processSidebar(sidebar, prefix) + if (home && !list.includes(home)) { + list.unshift(home) } - tableOfContent += `${processSidebar(sidebar, normalizePath('/notes/', dir)).join('')}\n` + tableOfContent += `${list.join('')}\n` } }) diff --git a/docs/README.md b/docs/README.md index 8d716083..364f0246 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,5 +1,6 @@ --- pageLayout: home +title: Vuepress Theme Plume config: - type: hero