perf(theme): 优化 frontmatter 自动生成
This commit is contained in:
parent
766285e8f8
commit
8714d76a0e
@ -69,7 +69,7 @@ export async function generateAFrontmatter(app: App) {
|
||||
)
|
||||
}
|
||||
|
||||
export async function watchAutoFrontmatter(app: App, watchers: any[]) {
|
||||
export async function watchAutoFrontmatter(app: App, watchers: any[], enable?: () => boolean) {
|
||||
if (!generate)
|
||||
return
|
||||
|
||||
@ -80,7 +80,8 @@ export async function watchAutoFrontmatter(app: App, watchers: any[]) {
|
||||
})
|
||||
|
||||
watcher.on('add', async (relativePath) => {
|
||||
if (!generate!.globFilter(relativePath))
|
||||
const enabled = enable ? enable() : true
|
||||
if (!generate!.globFilter(relativePath) || !enabled)
|
||||
return
|
||||
const file = await readMarkdown(app.dir.source(), relativePath)
|
||||
await generator(file)
|
||||
|
||||
@ -41,13 +41,11 @@ export async function initConfigLoader(
|
||||
defaultConfig: ThemeConfig,
|
||||
{ configFile, onChange }: InitConfigLoaderOptions = {},
|
||||
) {
|
||||
configFile = await findConfigPath(app, configFile)
|
||||
|
||||
const { encrypt, autoFrontmatter, ...localeOptions } = defaultConfig
|
||||
loader = {
|
||||
configFile,
|
||||
dependencies: [],
|
||||
load: () => compiler(configFile),
|
||||
load: () => compiler(loader!.configFile),
|
||||
loaded: false,
|
||||
watcher: null,
|
||||
changeEvents: [],
|
||||
@ -60,6 +58,8 @@ export async function initConfigLoader(
|
||||
},
|
||||
}
|
||||
|
||||
loader.configFile = await findConfigPath(app, configFile)
|
||||
|
||||
onChange && loader.changeEvents.push(onChange)
|
||||
|
||||
const { config, dependencies = [] } = await loader.load()
|
||||
|
||||
@ -79,10 +79,10 @@ export function plumeTheme(options: PlumeThemeOptions = {}): Theme {
|
||||
onWatched: (app, watchers) => {
|
||||
watchConfigFile(app, watchers)
|
||||
watchPrepare(app, watchers)
|
||||
const autoFrontmatter = getResolvedThemeConfig().autoFrontmatter ?? pluginOptions.frontmatter
|
||||
if (autoFrontmatter !== false) {
|
||||
watchAutoFrontmatter(app, watchers)
|
||||
}
|
||||
watchAutoFrontmatter(app, watchers, () => {
|
||||
const autoFrontmatter = getResolvedThemeConfig().autoFrontmatter ?? pluginOptions.frontmatter
|
||||
return autoFrontmatter !== false
|
||||
})
|
||||
},
|
||||
|
||||
extendsPage: async (page) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user