Stop loading settings on every single page index

pull/770/head^2
Zef Hemel 2024-03-11 20:14:49 +01:00
parent 26a7cd83c6
commit 73e5bb6672
2 changed files with 18 additions and 7 deletions

View File

@ -67,13 +67,13 @@ export async function parseIndexTextRepublish({ name, text }: IndexEvent) {
const parsed = await markdown.parseMarkdown(text); const parsed = await markdown.parseMarkdown(text);
if (isTemplate(text)) { if (isTemplate(text)) {
console.log("Indexing", name, "as template"); // console.log("Indexing", name, "as template");
await events.dispatchEvent("page:indexTemplate", { await events.dispatchEvent("page:indexTemplate", {
name, name,
tree: parsed, tree: parsed,
}); });
} else { } else {
console.log("Indexing", name, "as page"); // console.log("Indexing", name, "as page");
await events.dispatchEvent("page:index", { await events.dispatchEvent("page:index", {
name, name,
tree: parsed, tree: parsed,

View File

@ -10,16 +10,27 @@ export type StyleObject = ObjectValue<{
origin: string; origin: string;
}>; }>;
let customStylePages: string[] = [];
let lastCustomStyleRead: number | null = null;
export async function indexSpaceStyle({ name, tree }: IndexTreeEvent) { export async function indexSpaceStyle({ name, tree }: IndexTreeEvent) {
const allStyles: StyleObject[] = []; const allStyles: StyleObject[] = [];
// Also collect CSS from custom styles in settings // Cache the setting for 10s
let customStylePages = await readSetting("customStyles", []); if (
if (!Array.isArray(customStylePages)) { lastCustomStyleRead === null || Date.now() > lastCustomStyleRead + 10000
customStylePages = [customStylePages]; ) {
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) => { collectNodesOfType(tree, "FencedCode").map((t) => {
const codeInfoNode = findNodeOfType(t, "CodeInfo"); const codeInfoNode = findNodeOfType(t, "CodeInfo");
if (!codeInfoNode) { if (!codeInfoNode) {