perf(theme): optimize auto frontmatter
This commit is contained in:
parent
0af1391496
commit
4b2739bff0
@ -12,6 +12,7 @@ import type {
|
||||
AutoFrontmatterObject,
|
||||
PlumeThemeLocaleOptions,
|
||||
} from '../../shared/index.js'
|
||||
import { getThemeConfig } from '../loadConfig/index.js'
|
||||
import { readMarkdown, readMarkdownList } from './readFile.js'
|
||||
import { resolveOptions } from './resolveOptions.js'
|
||||
|
||||
@ -69,7 +70,7 @@ export async function generateAutoFrontmatter(app: App) {
|
||||
)
|
||||
}
|
||||
|
||||
export async function watchAutoFrontmatter(app: App, watchers: any[], enable?: () => boolean) {
|
||||
export async function watchAutoFrontmatter(app: App, watchers: any[]) {
|
||||
if (!generate)
|
||||
return
|
||||
|
||||
@ -80,7 +81,7 @@ export async function watchAutoFrontmatter(app: App, watchers: any[], enable?: (
|
||||
})
|
||||
|
||||
watcher.on('add', async (relativePath) => {
|
||||
const enabled = enable ? enable() : true
|
||||
const enabled = getThemeConfig().autoFrontmatter !== false
|
||||
if (!generate!.globFilter(relativePath) || !enabled)
|
||||
return
|
||||
const file = await readMarkdown(app.dir.source(), relativePath)
|
||||
|
||||
@ -17,10 +17,8 @@ export function plumeTheme(options: PlumeThemeOptions = {}): Theme {
|
||||
initConfigLoader(app, localeOptions, {
|
||||
configFile,
|
||||
onChange: ({ localeOptions, autoFrontmatter }) => {
|
||||
autoFrontmatter ??= pluginOptions.frontmatter
|
||||
if (autoFrontmatter !== false) {
|
||||
if (autoFrontmatter !== false)
|
||||
initAutoFrontmatter(localeOptions, autoFrontmatter)
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@ -43,7 +41,7 @@ export function plumeTheme(options: PlumeThemeOptions = {}): Theme {
|
||||
|
||||
extendsMarkdown: async (_, app) => {
|
||||
const { autoFrontmatter } = await waitForConfigLoaded()
|
||||
if ((autoFrontmatter ?? pluginOptions.frontmatter) !== false) {
|
||||
if (autoFrontmatter !== false) {
|
||||
await generateAutoFrontmatter(app)
|
||||
// wait for autoFrontmatter generated
|
||||
// i/o performance
|
||||
@ -73,11 +71,7 @@ export function plumeTheme(options: PlumeThemeOptions = {}): Theme {
|
||||
await prepareThemeData(app, localeOptions)
|
||||
await prepareData(app)
|
||||
})
|
||||
watchAutoFrontmatter(app, watchers, () => {
|
||||
const autoFrontmatter = getThemeConfig().autoFrontmatter
|
||||
?? pluginOptions.frontmatter
|
||||
return autoFrontmatter !== false
|
||||
})
|
||||
watchAutoFrontmatter(app, watchers)
|
||||
watchPrepare(app, watchers)
|
||||
},
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ import type { MarkdownEnhancePluginOptions } from 'vuepress-plugin-md-enhance'
|
||||
import type { ReadingTimePluginOptions } from '@vuepress/plugin-reading-time'
|
||||
import type { MarkdownPowerPluginOptions } from 'vuepress-plugin-md-power'
|
||||
import type { WatermarkPluginOptions } from '@vuepress/plugin-watermark'
|
||||
import type { AutoFrontmatter } from '../auto-frontmatter.js'
|
||||
|
||||
export interface PlumeThemePluginOptions {
|
||||
/**
|
||||
@ -62,11 +61,6 @@ export interface PlumeThemePluginOptions {
|
||||
*/
|
||||
baiduTongji?: false | { key: string }
|
||||
|
||||
/**
|
||||
* @deprecated 使用 `autoFrontmatter` 代替
|
||||
*/
|
||||
frontmatter?: Omit<AutoFrontmatter, 'frontmatter'>
|
||||
|
||||
/**
|
||||
* 阅读时间、字数统计
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user