mirror of
https://github.com/pengzhanbo/vuepress-theme-plume.git
synced 2026-04-23 10:58:13 +08:00
docs: update llms config
This commit is contained in:
parent
e8fa516b2e
commit
5b780c28d0
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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',
|
||||
}),
|
||||
],
|
||||
|
||||
|
||||
@ -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`
|
||||
}
|
||||
|
||||
@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
@ -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",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user