@backmatter/core 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/doc.ts +2 -0
- package/src/node/fs-loader.ts +10 -0
- package/src/query.ts +15 -2
package/package.json
CHANGED
package/src/doc.ts
CHANGED
package/src/node/fs-loader.ts
CHANGED
|
@@ -53,10 +53,20 @@ export async function listDocsFromFs(
|
|
|
53
53
|
const rel = path.relative(siteRoot, full).split(path.sep).join("/");
|
|
54
54
|
const hit = matchAnyModelPath(models, rel);
|
|
55
55
|
if (!hit) continue;
|
|
56
|
+
const model = models.find((m) => m.type === hit.type);
|
|
57
|
+
let frontmatter: Record<string, unknown> | undefined;
|
|
58
|
+
if (model) {
|
|
59
|
+
try {
|
|
60
|
+
frontmatter = parseDoc(await readFile(full, "utf-8"), modelFormat(model)).frontmatter;
|
|
61
|
+
} catch {
|
|
62
|
+
frontmatter = undefined;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
56
65
|
docs.push({
|
|
57
66
|
locale: hit.locale,
|
|
58
67
|
type: hit.type,
|
|
59
68
|
slug: hit.slug,
|
|
69
|
+
frontmatter,
|
|
60
70
|
});
|
|
61
71
|
}
|
|
62
72
|
return docs.sort((a, b) => {
|
package/src/query.ts
CHANGED
|
@@ -103,8 +103,21 @@ export function createQuery<const Models extends readonly ModelDef[]>(
|
|
|
103
103
|
docs = doc ? [doc] : [];
|
|
104
104
|
} else {
|
|
105
105
|
const summaries = await loader.listDocs({ type, locale: opts?.locale });
|
|
106
|
-
const
|
|
107
|
-
|
|
106
|
+
const fromList = summaries.filter((s) => s.frontmatter != null);
|
|
107
|
+
const missing = summaries.filter((s) => s.frontmatter == null);
|
|
108
|
+
const loaded = await Promise.all(missing.map((s) => get(type, s.locale, s.slug)));
|
|
109
|
+
docs = [
|
|
110
|
+
...fromList.map((s) => ({
|
|
111
|
+
locale: s.locale,
|
|
112
|
+
type: s.type,
|
|
113
|
+
slug: s.slug,
|
|
114
|
+
source: "head" as const,
|
|
115
|
+
frontmatter: normalizeFrontmatter(s.frontmatter ?? {}),
|
|
116
|
+
body: "",
|
|
117
|
+
raw: "",
|
|
118
|
+
})),
|
|
119
|
+
...loaded.filter((d): d is BackmatterDoc => d !== null),
|
|
120
|
+
];
|
|
108
121
|
}
|
|
109
122
|
|
|
110
123
|
const filtered = opts?.where ? docs.filter((d) => matchesWhere(d, opts.where!)) : docs;
|