Skip to content

Commit

Permalink
Fix page tag indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
zefhemel committed Dec 22, 2023
1 parent 521a81d commit a49a65c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions plugs/index/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,36 @@ export async function indexPage({ name, tree }: IndexTreeEvent) {
// Don't index pages starting with _
return;
}
let pageMeta = await space.getPageMeta(name);

const pageMeta = await space.getPageMeta(name);
const frontmatter = await extractFrontmatter(tree);
const toplevelAttributes = await extractAttributes(tree, false);

// Push them all into the page object
// Note the order here, making sure that the actual page meta data overrules
// any attempt to manually set built-in attributes like 'name' or 'lastModified'
pageMeta = { ...frontmatter, ...toplevelAttributes, ...pageMeta };
// pageMeta appears at the beginning and the end due to the ordering behavior of ojects in JS (making builtin attributes appear first)
const combinedPageMeta = {
...pageMeta,
...frontmatter,
...toplevelAttributes,
...pageMeta,
};

pageMeta.tags = [...new Set(["page", ...pageMeta.tags || []])];
combinedPageMeta.tags = [
...new Set([
"page",
...frontmatter.tags || [],
...toplevelAttributes.tags || [],
]),
];

// if (pageMeta.tags.includes("template")) {
// // If this is a template, we don't want to index it as a page or anything else, just a template
// pageMeta.tags = ["template"];
// }

// console.log("Page object", pageObj);
await indexObjects<PageMeta>(name, [pageMeta]);
await indexObjects<PageMeta>(name, [combinedPageMeta]);
}

export async function lintFrontmatter(): Promise<LintDiagnostic[]> {
Expand Down

0 comments on commit a49a65c

Please sign in to comment.