mirror of
https://github.com/pengzhanbo/vuepress-theme-plume.git
synced 2026-04-23 10:58:13 +08:00
perf(theme): optimize auto frontmatter I/O, #124
This commit is contained in:
parent
95f739fc39
commit
8d07dab951
@ -1,4 +1,4 @@
|
||||
import { fs } from 'vuepress/utils'
|
||||
import { fs, hash } from 'vuepress/utils'
|
||||
import chokidar from 'chokidar'
|
||||
import { createFilter } from 'create-filter'
|
||||
import grayMatter from 'gray-matter'
|
||||
@ -99,11 +99,16 @@ async function generator(file: AutoFrontmatterMarkdownFile): Promise<void> {
|
||||
const formatter = current?.frontmatter || generate.global
|
||||
const { data, content } = grayMatter(file.content)
|
||||
|
||||
const beforeHash = hash(data)
|
||||
|
||||
for (const key in formatter) {
|
||||
const value = await formatter[key](data[key], file, data)
|
||||
data[key] = value ?? data[key]
|
||||
}
|
||||
|
||||
if (beforeHash === hash(data))
|
||||
return
|
||||
|
||||
try {
|
||||
const yaml = isEmptyObject(data)
|
||||
? ''
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user