From fe3945ccc356bd78c1039fca456b23c97129c4da Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Fri, 27 Sep 2024 08:40:06 +0800 Subject: [PATCH] perf(theme): improve auto-frontmatter cache (#222) --- theme/src/node/autoFrontmatter/generator.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/theme/src/node/autoFrontmatter/generator.ts b/theme/src/node/autoFrontmatter/generator.ts index 8fb6c45d..6eb5ae8f 100644 --- a/theme/src/node/autoFrontmatter/generator.ts +++ b/theme/src/node/autoFrontmatter/generator.ts @@ -92,7 +92,12 @@ export async function generateAutoFrontmatter(app: App) { const cachePath = app.dir.cache(CACHE_FILE) if (fs.existsSync(cachePath)) { - generate.cache = JSON.parse(await fs.readFile(cachePath, 'utf-8')) + try { + generate.cache = JSON.parse(await fs.readFile(cachePath, 'utf-8')) + } + catch { + generate.cache = {} + } } const markdownList = await readMarkdownList(app, generate) await promiseParallel(