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);
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,

View File

@ -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) {