1
0
silverbullet/plugs/index/page.ts

29 lines
957 B
TypeScript
Raw Normal View History

import type { IndexTreeEvent } from "$sb/app_event.ts";
import { space } from "$sb/syscalls.ts";
2023-11-06 08:14:16 +00:00
import type { PageMeta } from "$sb/types.ts";
import { extractFrontmatter } from "$sb/lib/frontmatter.ts";
import { extractAttributes } from "$sb/lib/attribute.ts";
import { indexObjects } from "./api.ts";
export async function indexPage({ name, tree }: IndexTreeEvent) {
2023-10-31 09:33:38 +00:00
if (name.startsWith("_")) {
// Don't index pages starting with _
return;
}
2023-11-06 08:14:16 +00:00
let pageMeta = await space.getPageMeta(name);
2023-11-06 08:14:16 +00:00
const frontmatter = await extractFrontmatter(tree);
const toplevelAttributes = await extractAttributes(tree, false);
// Push them all into the page object
2023-11-06 08:14:16 +00:00
pageMeta = { ...pageMeta, ...frontmatter, ...toplevelAttributes };
2023-11-06 08:14:16 +00:00
pageMeta.tags = [...new Set(["page", ...pageMeta.tags || []])];
// console.log("Page object", pageObj);
// console.log("Extracted page meta data", pageMeta);
2023-11-06 08:14:16 +00:00
await indexObjects<PageMeta>(name, [pageMeta]);
2023-08-28 15:12:15 +00:00
}