1
0
silverbullet/plugs/index/builtins.ts
Ian Shehadeh 50105fd044
Index plug: index paragraph nodes (#528)
* index plug: index paragraph nodes

Includes attributes and tags in the paragraphs.
 Only considers top level paragraphs (right below Document node)

* keep ref and pos consistent with other objects

- most objects just store the starting position in the `pos` field.
- ref is usually `${page}@${pos}` so that it works as a link.

* cleanup and clarify comments

* add paragraph to builtins index
2023-10-12 20:30:47 +02:00

91 lines
1.9 KiB
TypeScript

import { ObjectValue } from "$sb/types.ts";
import { indexObjects } from "./api.ts";
import { AttributeObject } from "./attributes.ts";
import { TagObject } from "./tags.ts";
export const builtinPseudoPage = ":builtin:";
export const builtins: Record<string, Record<string, string>> = {
page: {
ref: "string",
name: "string",
lastModified: "date",
perm: "rw|ro",
contentType: "string",
size: "number",
tags: "array",
},
task: {
ref: "string",
name: "string",
done: "boolean",
page: "string",
state: "string",
deadline: "string",
pos: "number",
tags: "array",
},
tag: {
ref: "string",
name: "string",
page: "string",
context: "string",
},
attribute: {
ref: "string",
name: "string",
attributeType: "string",
type: "string",
page: "string",
},
anchor: {
ref: "string",
name: "string",
page: "string",
pos: "number",
},
link: {
ref: "string",
name: "string",
page: "string",
pos: "number",
alias: "string",
inDirective: "boolean",
asTemplate: "boolean",
},
paragraph: {
text: "string",
page: "string",
pos: "number",
},
};
export async function loadBuiltinsIntoIndex() {
console.log("Loading builtins attributes into index");
const allTags: ObjectValue<TagObject>[] = [];
for (const [tag, attributes] of Object.entries(builtins)) {
allTags.push({
ref: tag,
tags: ["tag"],
name: tag,
page: builtinPseudoPage,
parent: "builtin",
});
await indexObjects<AttributeObject>(
builtinPseudoPage,
Object.entries(attributes).map(([name, attributeType]) => {
return {
ref: `${tag}:${name}`,
tags: ["attribute"],
tag,
name,
attributeType,
builtinPseudoPage,
page: builtinPseudoPage,
};
}),
);
}
await indexObjects(builtinPseudoPage, allTags);
}