From 3479d5a0ceb6eee476473a1c24c04a766750a0f9 Mon Sep 17 00:00:00 2001 From: buqiyuan <1743369777@qq.com> Date: Sat, 30 Sep 2023 20:41:38 +0800 Subject: [PATCH] update code --- src/node/plugins/localSearchPlugin.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/node/plugins/localSearchPlugin.ts b/src/node/plugins/localSearchPlugin.ts index 398efc07..9b01cf6a 100644 --- a/src/node/plugins/localSearchPlugin.ts +++ b/src/node/plugins/localSearchPlugin.ts @@ -25,7 +25,7 @@ interface IndexObject { title: string titles: string[] } -let mdEnv: MarkdownEnv +let mdEnv: MarkdownEnv | null export async function localSearchPlugin( siteConfig: SiteConfig ): Promise { @@ -276,6 +276,7 @@ function splitPageIntoSections(html: string) { parentTitles[level] = title } } + mdEnv = null return sections } @@ -289,13 +290,13 @@ function clearHtmlTags(str: string) { } function replaceInterpolation(str: string) { - if (!mdEnv.frontmatter) { + if (!mdEnv?.frontmatter) { return str } return str.replace(/{{\s*([^}]+)\s*}}/g, (_, expression: string) => { const properties = expression.trim().split('.') - let value: Record = { $frontmatter: { ...mdEnv.frontmatter } } + let value: Record = { $frontmatter: { ...mdEnv?.frontmatter } } for (let prop of properties) { value = value?.[prop]