perf: 调整主题配置
This commit is contained in:
parent
a81947aca4
commit
15d9265b21
@ -1,4 +1,4 @@
|
||||
import { createRequire } from 'node:module'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import type { App } from '@vuepress/core'
|
||||
import { resolveLocalePath } from '@vuepress/shared'
|
||||
@ -16,11 +16,11 @@ import type {
|
||||
} from '../shared/index.js'
|
||||
|
||||
const nanoid = customAlphabet('0123456789abcdefghijklmnopqrstuvwxyz', 8)
|
||||
const require = createRequire(process.cwd())
|
||||
const getPackage = () => {
|
||||
let pkg = {} as any
|
||||
try {
|
||||
pkg = require('package.json') || {}
|
||||
const content = fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf-8')
|
||||
pkg = JSON.parse(content)
|
||||
} catch {}
|
||||
return pkg
|
||||
}
|
||||
@ -92,7 +92,7 @@ export default function autoFrontmatter(
|
||||
return dirList.length > 0 ? dirList[dirList.length - 1] : ''
|
||||
}
|
||||
return {
|
||||
include: options.frontmatter?.include ?? ['**/*.{md,MD}'],
|
||||
include: options.frontmatter?.include ?? ['**/*.md'],
|
||||
exclude: options.frontmatter?.exclude ?? ['.vuepress/**/*', 'node_modules'],
|
||||
frontmatter: options.frontmatter?.frontmatter ?? [
|
||||
localesNotesDirs.length
|
||||
|
||||
@ -3,22 +3,38 @@ import type { PlumeThemeLocaleOptions } from '../shared/index.js'
|
||||
export const defaultLocaleOption: Partial<PlumeThemeLocaleOptions> = {
|
||||
article: '/article',
|
||||
notes: { link: '/note', dir: 'notes', notes: [] },
|
||||
blog: {
|
||||
include: ['**/*.md'],
|
||||
exclude: ['.vuepress/', 'node_modules/', '{README,index}.md'],
|
||||
link: '/blog/',
|
||||
},
|
||||
footer: {
|
||||
message:
|
||||
'Power by <a target="_blank" href="https://v2.vuepress.vuejs.org/">Vuepress</a> & <a target="_blank" href="https://github.com/pengzhanbo/vuepress-theme-plume">vuepress-theme-plume</a>',
|
||||
'Power by <a target="_blank" href="https://v2.vuepress.vuejs.org/">vuepress</a> & <a target="_blank" href="https://github.com/pengzhanbo/vuepress-theme-plume">vuepress-theme-plume</a>',
|
||||
},
|
||||
appearance: true,
|
||||
// page meta
|
||||
editLink: true,
|
||||
editLinkText: 'Edit this page',
|
||||
lastUpdated: true,
|
||||
lastUpdatedText: 'Last Updated',
|
||||
contributors: true,
|
||||
contributorsText: 'Contributors',
|
||||
}
|
||||
|
||||
export const mergeLocaleOptions = (options: PlumeThemeLocaleOptions) => {
|
||||
if (!options.locales) {
|
||||
options.locales = {}
|
||||
}
|
||||
if (options.notes) {
|
||||
options.notes = {
|
||||
...defaultLocaleOption.notes,
|
||||
...(options.notes ?? {}),
|
||||
}
|
||||
}
|
||||
|
||||
if (options.footer) {
|
||||
options.footer = {
|
||||
...defaultLocaleOption.footer,
|
||||
...options.footer,
|
||||
}
|
||||
}
|
||||
|
||||
const { locales, ...otherOptions } = options
|
||||
|
||||
if (!locales['/']) {
|
||||
@ -30,7 +46,7 @@ export const mergeLocaleOptions = (options: PlumeThemeLocaleOptions) => {
|
||||
})
|
||||
|
||||
Object.assign(locales['/'], {
|
||||
...defaultLocaleOption,
|
||||
...{ selectLanguageName: 'English' },
|
||||
...JSON.parse(JSON.stringify(otherOptions)),
|
||||
...locales['/'],
|
||||
})
|
||||
|
||||
@ -51,6 +51,7 @@ export const setupPlugins = (
|
||||
|
||||
return [
|
||||
palettePlugin({ preset: 'sass' }),
|
||||
|
||||
themeDataPlugin({
|
||||
themeData: {
|
||||
...localeOptions,
|
||||
@ -60,12 +61,14 @@ export const setupPlugins = (
|
||||
} as any,
|
||||
}),
|
||||
autoFrontmatterPlugin(autoFrontmatter(app, options, localeOptions)),
|
||||
|
||||
blogDataPlugin({
|
||||
include: localeOptions.blog?.include,
|
||||
include: localeOptions.blog?.include ?? ['**/*.md'],
|
||||
exclude: [
|
||||
'**/{README,readme,index}.md',
|
||||
'.vuepress/',
|
||||
...(localeOptions.blog?.exclude || []),
|
||||
'node_modules/',
|
||||
...(localeOptions.blog?.exclude ?? []),
|
||||
...localeNotesDirs,
|
||||
].filter(Boolean),
|
||||
sortBy: 'createTime',
|
||||
|
||||
@ -21,7 +21,7 @@ export async function setupPage(
|
||||
const defaultBlog = localeOption.blog
|
||||
const link = blog?.link
|
||||
? blog.link
|
||||
: normalizePath(path.join('/', locale, defaultBlog?.link || ''))
|
||||
: normalizePath(path.join('/', locale, defaultBlog?.link || '/blog/'))
|
||||
const blogPage = await createPage(app, {
|
||||
path: link,
|
||||
frontmatter: {
|
||||
|
||||
@ -38,12 +38,6 @@ export type SocialLinkIcon =
|
||||
| { svg: string }
|
||||
|
||||
export interface PlumeThemeBlog {
|
||||
/**
|
||||
* blog 文章读取目录
|
||||
*
|
||||
* @default './' 即 vuepress 配置的 source 目录
|
||||
*/
|
||||
dir?: string
|
||||
|
||||
/**
|
||||
* blog list link
|
||||
@ -53,14 +47,14 @@ export interface PlumeThemeBlog {
|
||||
link?: string
|
||||
|
||||
/**
|
||||
* 在 `blog.dir` 目录中,通过 glob string 配置包含文件
|
||||
* 通过 glob string 配置包含文件
|
||||
*
|
||||
* @default - ['**\*.md']
|
||||
*/
|
||||
include?: string[]
|
||||
|
||||
/**
|
||||
* 在 `blog.dir` 目录中,通过 glob string 配置排除的文件
|
||||
* 通过 glob string 配置排除的文件
|
||||
*
|
||||
* _README.md 文件一般作为主页或者某个目录下的主页,不应该被读取为 blog文章_
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user