Expose file and page meta data directly

This commit is contained in:
Zef Hemel
2022-11-20 10:24:42 +01:00
parent 7a627c2f35
commit 89f27f9e9c
6 changed files with 114 additions and 40 deletions
+1 -14
View File
@@ -60,20 +60,7 @@ export async function indexLinks({ name, tree }: IndexTreeEvent) {
export async function pageQueryProvider({
query,
}: QueryProviderEvent): Promise<any[]> {
let allPages = await space.listPages();
const allPageMap: Map<string, any> = new Map(
allPages.map((pm) => [pm.name, pm]),
);
for (const { page, value } of await index.queryPrefix("meta:")) {
const p = allPageMap.get(page);
if (p) {
for (const [k, v] of Object.entries(value)) {
p[k] = v;
}
}
}
allPages = [...allPageMap.values()];
return applyQuery(query, allPages);
return applyQuery(query, await space.listPages());
}
export async function linkQueryProvider({
+9 -1
View File
@@ -5,10 +5,18 @@ import { space } from "$sb/silverbullet-syscall/mod.ts";
import { niceDate } from "$sb/lib/dates.ts";
const maxWidth = 70;
export function defaultJsonTransformer(_k: string, v: any) {
if (v === undefined) {
return "";
}
return "" + v;
}
// Nicely format an array of JSON objects as a Markdown table
export function jsonToMDTable(
jsonArray: any[],
valueTransformer: (k: string, v: any) => string = (_k, v) => "" + v,
valueTransformer: (k: string, v: any) => string = defaultJsonTransformer,
): string {
const fieldWidths = new Map<string, number>();
for (const entry of jsonArray) {