diff --git a/plugs/index/command.ts b/plugs/index/command.ts index c7663769..8200abbf 100644 --- a/plugs/index/command.ts +++ b/plugs/index/command.ts @@ -67,13 +67,13 @@ export async function parseIndexTextRepublish({ name, text }: IndexEvent) { const parsed = await markdown.parseMarkdown(text); if (isTemplate(text)) { - console.log("Indexing", name, "as template"); + // console.log("Indexing", name, "as template"); await events.dispatchEvent("page:indexTemplate", { name, tree: parsed, }); } else { - console.log("Indexing", name, "as page"); + // console.log("Indexing", name, "as page"); await events.dispatchEvent("page:index", { name, tree: parsed, diff --git a/plugs/index/style.ts b/plugs/index/style.ts index 00e0cac1..f19d7cc7 100644 --- a/plugs/index/style.ts +++ b/plugs/index/style.ts @@ -10,16 +10,27 @@ export type StyleObject = ObjectValue<{ origin: string; }>; +let customStylePages: string[] = []; +let lastCustomStyleRead: number | null = null; + export async function indexSpaceStyle({ name, tree }: IndexTreeEvent) { const allStyles: StyleObject[] = []; - // Also collect CSS from custom styles in settings - let customStylePages = await readSetting("customStyles", []); - if (!Array.isArray(customStylePages)) { - customStylePages = [customStylePages]; + // Cache the setting for 10s + if ( + lastCustomStyleRead === null || Date.now() > lastCustomStyleRead + 10000 + ) { + customStylePages = await readSetting("customStyles", []); + lastCustomStyleRead = Date.now(); + if (!Array.isArray(customStylePages)) { + customStylePages = [customStylePages]; + } + customStylePages = customStylePages.map((page: string) => + cleanPageRef(page) + ); } - customStylePages = customStylePages.map((page: string) => cleanPageRef(page)); + // Also collect CSS from custom styles in settings collectNodesOfType(tree, "FencedCode").map((t) => { const codeInfoNode = findNodeOfType(t, "CodeInfo"); if (!codeInfoNode) {