perf: 调整主题配置

This commit is contained in:
pengzhanbo 2023-12-27 01:09:42 +08:00
parent a81947aca4
commit 15d9265b21
5 changed files with 35 additions and 22 deletions

View File

@ -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

View File

@ -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['/'],
})

View File

@ -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',

View File

@ -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: {

View File

@ -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文章_
*