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'
|
import { tools } from './tools.js'
|
||||||
|
|
||||||
export const enCollections: ThemeCollections = defineCollections([
|
export const enCollections: ThemeCollections = defineCollections([
|
||||||
|
// 博客
|
||||||
|
{ type: 'post', dir: '/blog/', link: '/blog/', title: 'Blog' },
|
||||||
|
// 文档
|
||||||
themeGuide,
|
themeGuide,
|
||||||
themeConfig,
|
themeConfig,
|
||||||
tools,
|
tools,
|
||||||
|
|||||||
@ -4,6 +4,9 @@ import { themeGuide } from './theme-guide.js'
|
|||||||
import { tools } from './tools.js'
|
import { tools } from './tools.js'
|
||||||
|
|
||||||
export const zhCollections: ThemeCollections = defineCollections([
|
export const zhCollections: ThemeCollections = defineCollections([
|
||||||
|
// 博客
|
||||||
|
{ type: 'post', dir: '/blog/', link: '/blog/', title: '博客' },
|
||||||
|
// 文档
|
||||||
themeGuide,
|
themeGuide,
|
||||||
themeConfig,
|
themeConfig,
|
||||||
tools,
|
tools,
|
||||||
|
|||||||
@ -50,10 +50,15 @@ export default defineUserConfig({
|
|||||||
plugins: [
|
plugins: [
|
||||||
llmsPlugin({
|
llmsPlugin({
|
||||||
llmsTxtTemplateGetter: {
|
llmsTxtTemplateGetter: {
|
||||||
description: '一个简约易用的,功能丰富的 vuepress 文档&博客 主题',
|
description: (_, { currentLocale }) => {
|
||||||
|
return currentLocale === '/'
|
||||||
|
? '一个简约易用的,功能丰富的 vuepress 文档&博客 主题'
|
||||||
|
: 'An easy-to-use and feature-rich vuepress documentation and blog theme'
|
||||||
|
},
|
||||||
details: '',
|
details: '',
|
||||||
toc: tocGetter,
|
toc: tocGetter,
|
||||||
},
|
},
|
||||||
|
locale: 'all',
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,8 @@ import type { LLMPage, LLMState } from '@vuepress/plugin-llms'
|
|||||||
import type { ThemeSidebarItem } from 'vuepress-theme-plume'
|
import type { ThemeSidebarItem } from 'vuepress-theme-plume'
|
||||||
import { generateTOCLink as rawGenerateTOCLink } from '@vuepress/plugin-llms'
|
import { generateTOCLink as rawGenerateTOCLink } from '@vuepress/plugin-llms'
|
||||||
import { ensureEndingSlash, ensureLeadingSlash } from 'vuepress/shared'
|
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 {
|
function normalizePath(prefix: string, path = ''): string {
|
||||||
if (path.startsWith('/'))
|
if (path.startsWith('/'))
|
||||||
@ -11,20 +12,46 @@ function normalizePath(prefix: string, path = ''): string {
|
|||||||
return `${ensureEndingSlash(prefix)}${path}`
|
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 {
|
export function tocGetter(llmPages: LLMPage[], llmState: LLMState): string {
|
||||||
|
const { currentLocale } = llmState
|
||||||
|
const isZh = currentLocale === '/'
|
||||||
|
const collections = isZh ? zhCollections : enCollections
|
||||||
|
|
||||||
let tableOfContent = ''
|
let tableOfContent = ''
|
||||||
const usagePages: LLMPage[] = []
|
const usagePages: LLMPage[] = []
|
||||||
|
|
||||||
// Blog
|
collections
|
||||||
tableOfContent += `### 博客\n\n`
|
.filter(item => item.type === 'post')
|
||||||
const blogList: string[] = []
|
.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) => {
|
llmPages.forEach((page) => {
|
||||||
if (page.path.startsWith('/article/') || page.path.startsWith('/blog/')) {
|
if (withLinkPrefix(page.path) || withLink(page.path) || withFallback(page.path)) {
|
||||||
usagePages.push(page)
|
usagePages.push(page)
|
||||||
blogList.push(rawGenerateTOCLink(page, llmState))
|
list.push(rawGenerateTOCLink(page, llmState))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
tableOfContent += `${blogList.filter(Boolean).join('')}\n`
|
tableOfContent += `${list.filter(Boolean).join('')}\n`
|
||||||
|
})
|
||||||
|
|
||||||
const generateTOCLink = (path: string): string => {
|
const generateTOCLink = (path: string): string => {
|
||||||
const filepath = path.endsWith('/') ? `${path}README.md` : path.endsWith('.md') ? path : `${path || 'README'}.md`
|
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
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notes
|
// Collections
|
||||||
zhCollections
|
collections
|
||||||
.filter(collection => collection.type === 'doc')
|
.filter(collection => collection.type === 'doc')
|
||||||
.forEach(({ dir, title, sidebar = [] }) => {
|
.forEach(({ dir, title, sidebar = [] }) => {
|
||||||
tableOfContent += `### ${title}\n\n`
|
tableOfContent += `### ${title}\n\n`
|
||||||
const prefix = normalizePath(ensureLeadingSlash(dir))
|
const prefix = normalizePath(ensureLeadingSlash(withBase(dir, currentLocale)))
|
||||||
if (sidebar === 'auto') {
|
if (sidebar === 'auto') {
|
||||||
tableOfContent += `${processAutoSidebar(prefix).join('')}\n`
|
tableOfContent += `${processAutoSidebar(prefix).join('')}\n`
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,24 +29,12 @@ export default defineThemeConfig({
|
|||||||
|
|
||||||
locales: {
|
locales: {
|
||||||
'/': {
|
'/': {
|
||||||
// notes: zhNotes,
|
|
||||||
navbar: zhNavbar,
|
navbar: zhNavbar,
|
||||||
collections: [
|
collections: zhCollections,
|
||||||
// 博客
|
|
||||||
{ type: 'post', dir: '/blog/', link: '/blog/', title: '博客' },
|
|
||||||
// 文档
|
|
||||||
...zhCollections,
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
'/en/': {
|
'/en/': {
|
||||||
// notes: enNotes,
|
|
||||||
navbar: enNavbar,
|
navbar: enNavbar,
|
||||||
collections: [
|
collections: enCollections,
|
||||||
// 博客
|
|
||||||
{ type: 'post', dir: '/blog/', link: '/blog/', title: 'Blog' },
|
|
||||||
// 文档
|
|
||||||
...enCollections,
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"docs:build": "vuepress build --clean-cache --clean-temp && pnpm lunaria:build",
|
"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:clean": "rimraf .vuepress/.temp .vuepress/.cache .vuepress/dist",
|
||||||
"docs:dev": "vuepress dev",
|
"docs:dev": "vuepress dev",
|
||||||
"docs:serve": "http-server .vuepress/dist -d 0",
|
"docs:serve": "http-server .vuepress/dist -d 0",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user