From 5b780c28d0ef7b63d3d524d9912e36db56153f56 Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Tue, 18 Nov 2025 21:08:22 +0800 Subject: [PATCH] docs: update llms config --- docs/.vuepress/collections/en/index.ts | 3 ++ docs/.vuepress/collections/zh/index.ts | 3 ++ docs/.vuepress/config.ts | 7 +++- docs/.vuepress/llmstxtTOC.ts | 55 +++++++++++++++++++------- docs/.vuepress/plume.config.ts | 16 +------- docs/package.json | 1 + 6 files changed, 56 insertions(+), 29 deletions(-) diff --git a/docs/.vuepress/collections/en/index.ts b/docs/.vuepress/collections/en/index.ts index e4e70677..6c0c90b7 100644 --- a/docs/.vuepress/collections/en/index.ts +++ b/docs/.vuepress/collections/en/index.ts @@ -4,6 +4,9 @@ import { themeGuide } from './theme-guide.js' import { tools } from './tools.js' export const enCollections: ThemeCollections = defineCollections([ + // 博客 + { type: 'post', dir: '/blog/', link: '/blog/', title: 'Blog' }, + // 文档 themeGuide, themeConfig, tools, diff --git a/docs/.vuepress/collections/zh/index.ts b/docs/.vuepress/collections/zh/index.ts index 9ec13e7a..c81e07c7 100644 --- a/docs/.vuepress/collections/zh/index.ts +++ b/docs/.vuepress/collections/zh/index.ts @@ -4,6 +4,9 @@ import { themeGuide } from './theme-guide.js' import { tools } from './tools.js' export const zhCollections: ThemeCollections = defineCollections([ + // 博客 + { type: 'post', dir: '/blog/', link: '/blog/', title: '博客' }, + // 文档 themeGuide, themeConfig, tools, diff --git a/docs/.vuepress/config.ts b/docs/.vuepress/config.ts index c981be5e..62752ba8 100644 --- a/docs/.vuepress/config.ts +++ b/docs/.vuepress/config.ts @@ -50,10 +50,15 @@ export default defineUserConfig({ plugins: [ llmsPlugin({ llmsTxtTemplateGetter: { - description: '一个简约易用的,功能丰富的 vuepress 文档&博客 主题', + description: (_, { currentLocale }) => { + return currentLocale === '/' + ? '一个简约易用的,功能丰富的 vuepress 文档&博客 主题' + : 'An easy-to-use and feature-rich vuepress documentation and blog theme' + }, details: '', toc: tocGetter, }, + locale: 'all', }), ], diff --git a/docs/.vuepress/llmstxtTOC.ts b/docs/.vuepress/llmstxtTOC.ts index c8cef9ac..653184a7 100644 --- a/docs/.vuepress/llmstxtTOC.ts +++ b/docs/.vuepress/llmstxtTOC.ts @@ -2,7 +2,8 @@ import type { LLMPage, LLMState } from '@vuepress/plugin-llms' import type { ThemeSidebarItem } from 'vuepress-theme-plume' import { generateTOCLink as rawGenerateTOCLink } from '@vuepress/plugin-llms' import { ensureEndingSlash, ensureLeadingSlash } from 'vuepress/shared' -import { zhCollections } from './collections/zh/index.js' +import { path } from 'vuepress/utils' +import { enCollections, zhCollections } from './collections/index.js' function normalizePath(prefix: string, path = ''): string { if (path.startsWith('/')) @@ -11,20 +12,46 @@ function normalizePath(prefix: string, path = ''): string { return `${ensureEndingSlash(prefix)}${path}` } +function withBase(url = '', base = '/'): string { + if (!url) + return '' + if (url.startsWith(base)) + return normalizePath(url) + return path.join(base, url) +} + +function genStarsWith(stars: string | undefined, locale: string) { + return (url: string): boolean => { + if (!stars) + return false + return url.startsWith(withBase(stars, locale)) + } +} + export function tocGetter(llmPages: LLMPage[], llmState: LLMState): string { + const { currentLocale } = llmState + const isZh = currentLocale === '/' + const collections = isZh ? zhCollections : enCollections + let tableOfContent = '' const usagePages: LLMPage[] = [] - // Blog - tableOfContent += `### 博客\n\n` - const blogList: string[] = [] - llmPages.forEach((page) => { - if (page.path.startsWith('/article/') || page.path.startsWith('/blog/')) { - usagePages.push(page) - blogList.push(rawGenerateTOCLink(page, llmState)) - } - }) - tableOfContent += `${blogList.filter(Boolean).join('')}\n` + collections + .filter(item => item.type === 'post') + .forEach(({ title, linkPrefix, link }) => { + tableOfContent += `### ${title}\n\n` + const withLinkPrefix = genStarsWith(linkPrefix, currentLocale) + const withLink = genStarsWith(link, currentLocale) + const withFallback = genStarsWith('/article/', currentLocale) + const list: string[] = [] + llmPages.forEach((page) => { + if (withLinkPrefix(page.path) || withLink(page.path) || withFallback(page.path)) { + usagePages.push(page) + list.push(rawGenerateTOCLink(page, llmState)) + } + }) + tableOfContent += `${list.filter(Boolean).join('')}\n` + }) const generateTOCLink = (path: string): string => { const filepath = path.endsWith('/') ? `${path}README.md` : path.endsWith('.md') ? path : `${path || 'README'}.md` @@ -72,12 +99,12 @@ export function tocGetter(llmPages: LLMPage[], llmState: LLMState): string { return result } - // Notes - zhCollections + // Collections + collections .filter(collection => collection.type === 'doc') .forEach(({ dir, title, sidebar = [] }) => { tableOfContent += `### ${title}\n\n` - const prefix = normalizePath(ensureLeadingSlash(dir)) + const prefix = normalizePath(ensureLeadingSlash(withBase(dir, currentLocale))) if (sidebar === 'auto') { tableOfContent += `${processAutoSidebar(prefix).join('')}\n` } diff --git a/docs/.vuepress/plume.config.ts b/docs/.vuepress/plume.config.ts index 00e57f36..06ae67c1 100644 --- a/docs/.vuepress/plume.config.ts +++ b/docs/.vuepress/plume.config.ts @@ -29,24 +29,12 @@ export default defineThemeConfig({ locales: { '/': { - // notes: zhNotes, navbar: zhNavbar, - collections: [ - // 博客 - { type: 'post', dir: '/blog/', link: '/blog/', title: '博客' }, - // 文档 - ...zhCollections, - ], + collections: zhCollections, }, '/en/': { - // notes: enNotes, navbar: enNavbar, - collections: [ - // 博客 - { type: 'post', dir: '/blog/', link: '/blog/', title: 'Blog' }, - // 文档 - ...enCollections, - ], + collections: enCollections, }, }, diff --git a/docs/package.json b/docs/package.json index c5f5b52c..75915694 100644 --- a/docs/package.json +++ b/docs/package.json @@ -4,6 +4,7 @@ "private": true, "scripts": { "docs:build": "vuepress build --clean-cache --clean-temp && pnpm lunaria:build", + "docs:build-local": "NODE_OPTIONS=\"--max_old_space_size=8192\" vuepress build --clean-cache --clean-temp", "docs:clean": "rimraf .vuepress/.temp .vuepress/.cache .vuepress/dist", "docs:dev": "vuepress dev", "docs:serve": "http-server .vuepress/dist -d 0",