@hamur/content 0.0.0-stage → 0.0.2
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/LICENSE +22 -0
- package/README.md +14 -2
- package/dist/chunks/bun-render-65mwzeq2.js +58 -0
- package/dist/chunks/bun-render-7jxnxg3v.js +714 -0
- package/dist/chunks/bun-render-mxhn5twt.js +130 -0
- package/dist/chunks/bun-render-w7fh3fg7.js +36 -0
- package/dist/src/adapters/html.js +134 -0
- package/dist/src/adapters/preact.js +126 -0
- package/dist/src/adapters/react.js +116 -0
- package/dist/src/adapters/solid.js +153 -0
- package/dist/src/adapters/svelte.js +90 -0
- package/dist/src/adapters/vue.js +166 -0
- package/dist/src/index.js +2732 -0
- package/dist/src/query.js +97 -0
- package/dist/src/render.js +12 -0
- package/dist/src/server/index.js +349 -0
- package/dist/types/src/adapters/html.d.ts +54 -0
- package/dist/types/src/adapters/page.d.ts +21 -0
- package/dist/types/src/adapters/preact.d.ts +53 -0
- package/dist/types/src/adapters/prose.d.ts +21 -0
- package/dist/types/src/adapters/react.d.ts +53 -0
- package/dist/types/src/adapters/search.d.ts +12 -0
- package/dist/types/src/adapters/solid.d.ts +54 -0
- package/dist/types/src/adapters/svelte-page.d.ts +9 -0
- package/dist/types/src/adapters/svelte-search.d.ts +9 -0
- package/dist/types/src/adapters/svelte.d.ts +24 -0
- package/dist/types/src/adapters/vue.d.ts +189 -0
- package/dist/types/src/build/api.d.ts +24 -0
- package/dist/types/src/build/dev-route.d.ts +4 -0
- package/dist/types/src/build/dev.d.ts +48 -0
- package/dist/types/src/build/graphql.d.ts +10 -0
- package/dist/types/src/build/image.d.ts +16 -0
- package/dist/types/src/build/index.d.ts +76 -0
- package/dist/types/src/build/live.d.ts +6 -0
- package/dist/types/src/build/prerender.d.ts +8 -0
- package/dist/types/src/build/query.d.ts +10 -0
- package/dist/types/src/build/raw.d.ts +23 -0
- package/dist/types/src/build/search.d.ts +9 -0
- package/dist/types/src/build/types.d.ts +16 -0
- package/dist/types/src/component.d.ts +10 -0
- package/dist/types/src/config.d.ts +6 -0
- package/dist/types/src/define.d.ts +14 -0
- package/dist/types/src/error.d.ts +4 -0
- package/dist/types/src/image.d.ts +15 -0
- package/dist/types/src/index.d.ts +64 -0
- package/dist/types/src/loaders/data.d.ts +12 -0
- package/dist/types/src/loaders/file.d.ts +3 -0
- package/dist/types/src/loaders/git.d.ts +27 -0
- package/dist/types/src/loaders/glob.d.ts +14 -0
- package/dist/types/src/module.d.ts +3 -0
- package/dist/types/src/query.d.ts +17 -0
- package/dist/types/src/render.d.ts +9 -0
- package/dist/types/src/runtime/client.d.ts +25 -0
- package/dist/types/src/runtime/dev-client.d.ts +4 -0
- package/dist/types/src/runtime/dev-plugin.d.ts +12 -0
- package/dist/types/src/runtime/dev-store.d.ts +5 -0
- package/dist/types/src/runtime/live.d.ts +36 -0
- package/dist/types/src/runtime/navigation.d.ts +35 -0
- package/dist/types/src/runtime/page-plugin.d.ts +2 -0
- package/dist/types/src/runtime/page-source.d.ts +12 -0
- package/dist/types/src/runtime/query.d.ts +100 -0
- package/dist/types/src/runtime/raw-path.d.ts +2 -0
- package/dist/types/src/runtime/refresh-body.d.ts +4 -0
- package/dist/types/src/runtime/search-loaders.d.ts +7 -0
- package/dist/types/src/runtime/search-plugin.d.ts +2 -0
- package/dist/types/src/runtime/search-store.d.ts +19 -0
- package/dist/types/src/runtime/search.d.ts +28 -0
- package/dist/types/src/runtime/sections.d.ts +36 -0
- package/dist/types/src/runtime/server-store.d.ts +4 -0
- package/dist/types/src/runtime/store.d.ts +31 -0
- package/dist/types/src/server/door-dev-static.d.ts +3 -0
- package/dist/types/src/server/door-dev.d.ts +4 -0
- package/dist/types/src/server/door-static.d.ts +2 -0
- package/dist/types/src/server/door.d.ts +3 -0
- package/dist/types/src/server/endpoint.d.ts +1 -0
- package/dist/types/src/server/graphql.d.ts +24 -0
- package/dist/types/src/server/index.d.ts +10 -0
- package/dist/types/src/server/install.d.ts +1 -0
- package/dist/types/src/server/live.d.ts +10 -0
- package/dist/types/src/server/query.d.ts +15 -0
- package/dist/types/src/server/refresh.d.ts +2 -0
- package/dist/types/src/server/rest.d.ts +62 -0
- package/dist/types/src/server/search.d.ts +5 -0
- package/dist/types/src/server-config.d.ts +12 -0
- package/dist/types/src/source.d.ts +24 -0
- package/dist/types/src/types.d.ts +293 -0
- package/package.json +140 -4
- package/src/adapters/ContentRenderer.svelte +27 -0
- package/src/adapters/ProseA.svelte +11 -0
- package/src/adapters/ProseBlockquote.svelte +7 -0
- package/src/adapters/ProseCode.svelte +7 -0
- package/src/adapters/ProseEm.svelte +7 -0
- package/src/adapters/ProseH1.svelte +7 -0
- package/src/adapters/ProseH2.svelte +7 -0
- package/src/adapters/ProseH3.svelte +7 -0
- package/src/adapters/ProseH4.svelte +7 -0
- package/src/adapters/ProseH5.svelte +7 -0
- package/src/adapters/ProseH6.svelte +7 -0
- package/src/adapters/ProseHr.svelte +5 -0
- package/src/adapters/ProseImg.svelte +5 -0
- package/src/adapters/ProseLi.svelte +7 -0
- package/src/adapters/ProseOl.svelte +7 -0
- package/src/adapters/ProseP.svelte +7 -0
- package/src/adapters/ProsePre.svelte +21 -0
- package/src/adapters/ProseStrong.svelte +7 -0
- package/src/adapters/ProseTable.svelte +7 -0
- package/src/adapters/ProseUl.svelte +7 -0
- package/src/adapters/html.ts +152 -0
- package/src/adapters/page.ts +52 -0
- package/src/adapters/preact.ts +154 -0
- package/src/adapters/prose.ts +55 -0
- package/src/adapters/react.ts +142 -0
- package/src/adapters/search.ts +32 -0
- package/src/adapters/solid.ts +183 -0
- package/src/adapters/svelte-defaults.ts +41 -0
- package/src/adapters/svelte-page.ts +29 -0
- package/src/adapters/svelte-search.ts +36 -0
- package/src/adapters/svelte.ts +30 -0
- package/src/adapters/test/OwnA.svelte +7 -0
- package/src/adapters/test/OwnH1.svelte +7 -0
- package/src/adapters/test/OwnPre.svelte +7 -0
- package/src/adapters/test/support.ts +106 -0
- package/src/adapters/vue.ts +182 -0
- package/src/build/api.ts +201 -0
- package/src/build/dev-route.ts +5 -0
- package/src/build/dev.ts +299 -0
- package/src/build/graphql.ts +197 -0
- package/src/build/image.ts +60 -0
- package/src/build/index.ts +597 -0
- package/src/build/live.ts +34 -0
- package/src/build/prerender.ts +34 -0
- package/src/build/query.ts +70 -0
- package/src/build/raw.ts +157 -0
- package/src/build/search.ts +64 -0
- package/src/build/types.ts +108 -0
- package/src/component.ts +86 -0
- package/src/config.ts +156 -0
- package/src/define.ts +33 -0
- package/src/env.d.ts +34 -0
- package/src/error.ts +4 -0
- package/src/image.ts +41 -0
- package/src/index.ts +103 -0
- package/src/loaders/data.ts +186 -0
- package/src/loaders/file.ts +53 -0
- package/src/loaders/git.ts +266 -0
- package/src/loaders/glob.ts +179 -0
- package/src/module.ts +26 -0
- package/src/query.ts +82 -0
- package/src/render.ts +16 -0
- package/src/runtime/client.ts +75 -0
- package/src/runtime/dev-client.ts +6 -0
- package/src/runtime/dev-plugin.ts +64 -0
- package/src/runtime/dev-store.ts +19 -0
- package/src/runtime/live.ts +331 -0
- package/src/runtime/navigation.ts +225 -0
- package/src/runtime/page-plugin.ts +13 -0
- package/src/runtime/page-source.ts +22 -0
- package/src/runtime/query.ts +605 -0
- package/src/runtime/raw-path.ts +2 -0
- package/src/runtime/refresh-body.ts +22 -0
- package/src/runtime/search-loaders.ts +14 -0
- package/src/runtime/search-plugin.ts +6 -0
- package/src/runtime/search-store.ts +73 -0
- package/src/runtime/search.ts +126 -0
- package/src/runtime/sections.ts +155 -0
- package/src/runtime/server-store.ts +12 -0
- package/src/runtime/store.ts +59 -0
- package/src/server/door-dev-static.ts +6 -0
- package/src/server/door-dev.ts +7 -0
- package/src/server/door-static.ts +4 -0
- package/src/server/door.ts +6 -0
- package/src/server/endpoint.ts +17 -0
- package/src/server/graphql.ts +59 -0
- package/src/server/index.ts +17 -0
- package/src/server/install.ts +6 -0
- package/src/server/live.ts +51 -0
- package/src/server/query.ts +46 -0
- package/src/server/refresh.ts +19 -0
- package/src/server/rest.ts +157 -0
- package/src/server/search.ts +22 -0
- package/src/server-config.ts +24 -0
- package/src/source.ts +99 -0
- package/src/types.ts +282 -0
|
@@ -0,0 +1,714 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/content/src/runtime/query.ts
|
|
3
|
+
class QueryError extends Error {
|
|
4
|
+
}
|
|
5
|
+
var OPERATORS = new Set([
|
|
6
|
+
"=",
|
|
7
|
+
"<>",
|
|
8
|
+
">",
|
|
9
|
+
">=",
|
|
10
|
+
"<",
|
|
11
|
+
"<=",
|
|
12
|
+
"IN",
|
|
13
|
+
"NOT IN",
|
|
14
|
+
"BETWEEN",
|
|
15
|
+
"NOT BETWEEN",
|
|
16
|
+
"IS NULL",
|
|
17
|
+
"IS NOT NULL",
|
|
18
|
+
"LIKE",
|
|
19
|
+
"NOT LIKE"
|
|
20
|
+
]);
|
|
21
|
+
var QUERY_KEYS = new Set(["where", "select", "order", "limit", "skip", "count"]);
|
|
22
|
+
var DATA_FIELDS = ["collection", "id", "stem", "extension"];
|
|
23
|
+
var PAGE_FIELDS = [
|
|
24
|
+
...DATA_FIELDS,
|
|
25
|
+
"path",
|
|
26
|
+
"title",
|
|
27
|
+
"description",
|
|
28
|
+
"seo",
|
|
29
|
+
"navigation",
|
|
30
|
+
"draft",
|
|
31
|
+
"navigationDirs",
|
|
32
|
+
"body",
|
|
33
|
+
"excerpt",
|
|
34
|
+
"headings",
|
|
35
|
+
"toc",
|
|
36
|
+
"readingTime"
|
|
37
|
+
];
|
|
38
|
+
var QUERY_LIMITS = {
|
|
39
|
+
conditions: 100,
|
|
40
|
+
depth: 8,
|
|
41
|
+
values: 1000,
|
|
42
|
+
select: 100,
|
|
43
|
+
order: 10,
|
|
44
|
+
field: 200,
|
|
45
|
+
pattern: 200
|
|
46
|
+
};
|
|
47
|
+
function fail(message) {
|
|
48
|
+
throw new QueryError(message);
|
|
49
|
+
}
|
|
50
|
+
var shown = (value) => typeof value === "function" ? "a function" : JSON.stringify(value) ?? String(value);
|
|
51
|
+
var isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
52
|
+
var FORBIDDEN_SEGMENTS = new Set(["__proto__", "constructor", "prototype"]);
|
|
53
|
+
function checkFieldPath(field) {
|
|
54
|
+
if (typeof field !== "string" || field === "" || field.length > QUERY_LIMITS.field || field.split(".").includes(""))
|
|
55
|
+
fail(`a field is a name or a dotted path (got ${shown(field)})`);
|
|
56
|
+
const segment = field.split(".").find((part) => FORBIDDEN_SEGMENTS.has(part));
|
|
57
|
+
if (segment !== undefined)
|
|
58
|
+
fail(`a field may not name ${shown(segment)} (got ${shown(field)})`);
|
|
59
|
+
}
|
|
60
|
+
var isScalar = (value) => value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value);
|
|
61
|
+
function checkCondition(field, operator, value) {
|
|
62
|
+
if (typeof operator !== "string" || !OPERATORS.has(operator))
|
|
63
|
+
fail(`unknown operator ${shown(operator)}`);
|
|
64
|
+
checkFieldPath(field);
|
|
65
|
+
switch (operator) {
|
|
66
|
+
case "IS NULL":
|
|
67
|
+
case "IS NOT NULL":
|
|
68
|
+
if (value !== undefined)
|
|
69
|
+
fail(`${operator} takes no value (got ${shown(value)})`);
|
|
70
|
+
return;
|
|
71
|
+
case "IN":
|
|
72
|
+
case "NOT IN":
|
|
73
|
+
if (!Array.isArray(value))
|
|
74
|
+
fail(`IN takes an array (got ${shown(value)})`);
|
|
75
|
+
if (value.length > QUERY_LIMITS.values)
|
|
76
|
+
fail(`IN takes at most ${QUERY_LIMITS.values} values (got ${value.length})`);
|
|
77
|
+
if (!value.every(isScalar))
|
|
78
|
+
fail(`IN takes strings, numbers, booleans or null (got ${shown(value)})`);
|
|
79
|
+
return;
|
|
80
|
+
case "BETWEEN":
|
|
81
|
+
case "NOT BETWEEN":
|
|
82
|
+
if (!Array.isArray(value) || value.length !== 2 || !value.every(isScalar))
|
|
83
|
+
fail(`BETWEEN takes [low, high] (got ${shown(value)})`);
|
|
84
|
+
return;
|
|
85
|
+
case "LIKE":
|
|
86
|
+
case "NOT LIKE":
|
|
87
|
+
if (typeof value !== "string")
|
|
88
|
+
fail(`LIKE takes a string (got ${shown(value)})`);
|
|
89
|
+
if (value.length > QUERY_LIMITS.pattern)
|
|
90
|
+
fail(`LIKE takes a pattern of at most ${QUERY_LIMITS.pattern} characters`);
|
|
91
|
+
return;
|
|
92
|
+
default:
|
|
93
|
+
if (isScalar(value) || (operator === "=" || operator === "<>") && Array.isArray(value) && value.length <= QUERY_LIMITS.values && value.every(isScalar))
|
|
94
|
+
return;
|
|
95
|
+
fail(`${operator} takes a string, number, boolean or null${operator === "=" || operator === "<>" ? ", or an array of them" : ""} (got ${shown(value)})`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function fieldsOf(type, entries) {
|
|
99
|
+
const fields = new Set(type === "page" ? PAGE_FIELDS : DATA_FIELDS);
|
|
100
|
+
for (const entry of entries)
|
|
101
|
+
for (const key of Object.keys(entry))
|
|
102
|
+
fields.add(key);
|
|
103
|
+
return fields;
|
|
104
|
+
}
|
|
105
|
+
var fieldCache = new WeakMap;
|
|
106
|
+
function knownFields(type, entries) {
|
|
107
|
+
let fields = fieldCache.get(entries);
|
|
108
|
+
if (!fields)
|
|
109
|
+
fieldCache.set(entries, fields = fieldsOf(type, entries));
|
|
110
|
+
return fields;
|
|
111
|
+
}
|
|
112
|
+
var nonNegative = (value, name) => {
|
|
113
|
+
if (!Number.isSafeInteger(value) || value < 0)
|
|
114
|
+
fail(`${name} must be a non-negative integer`);
|
|
115
|
+
};
|
|
116
|
+
function checkQuery(value, fields, collection) {
|
|
117
|
+
if (!isRecord(value))
|
|
118
|
+
fail(`query must be an object (got ${shown(value)})`);
|
|
119
|
+
const query = value;
|
|
120
|
+
for (const key of Object.keys(query))
|
|
121
|
+
if (!QUERY_KEYS.has(key))
|
|
122
|
+
fail(`unknown query key ${shown(key)}`);
|
|
123
|
+
const field = (name) => {
|
|
124
|
+
checkFieldPath(name);
|
|
125
|
+
if (!fields.has(name.split(".")[0]))
|
|
126
|
+
fail(`unknown field ${shown(name)} in collection ${shown(collection)}`);
|
|
127
|
+
};
|
|
128
|
+
let conditions = 0;
|
|
129
|
+
const clauses = (list, depth) => {
|
|
130
|
+
if (!Array.isArray(list))
|
|
131
|
+
fail(`where must be an array (got ${shown(list)})`);
|
|
132
|
+
if (depth > QUERY_LIMITS.depth)
|
|
133
|
+
fail(`groups nest at most ${QUERY_LIMITS.depth} deep`);
|
|
134
|
+
for (const clause of list) {
|
|
135
|
+
if (!isRecord(clause))
|
|
136
|
+
fail(`a where clause must be an object (got ${shown(clause)})`);
|
|
137
|
+
const { join, ...rest } = clause;
|
|
138
|
+
if (join !== "AND" && join !== "OR")
|
|
139
|
+
fail(`join must be "AND" or "OR" (got ${shown(join)})`);
|
|
140
|
+
if (++conditions > QUERY_LIMITS.conditions)
|
|
141
|
+
fail(`a query takes at most ${QUERY_LIMITS.conditions} conditions`);
|
|
142
|
+
if (Object.hasOwn(rest, "where")) {
|
|
143
|
+
for (const key of Object.keys(rest))
|
|
144
|
+
if (key !== "where")
|
|
145
|
+
fail(`unknown key ${shown(key)} in a where group`);
|
|
146
|
+
clauses(rest.where, depth + 1);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
for (const key of Object.keys(rest))
|
|
150
|
+
if (key !== "field" && key !== "operator" && key !== "value")
|
|
151
|
+
fail(`unknown key ${shown(key)} in a where condition`);
|
|
152
|
+
checkCondition(rest.field, rest.operator, rest.value);
|
|
153
|
+
field(rest.field);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
if (query.where !== undefined)
|
|
157
|
+
clauses(query.where, 1);
|
|
158
|
+
if (query.select !== undefined) {
|
|
159
|
+
if (!Array.isArray(query.select))
|
|
160
|
+
fail(`select must be an array of fields (got ${shown(query.select)})`);
|
|
161
|
+
if (query.select.length > QUERY_LIMITS.select)
|
|
162
|
+
fail(`select takes at most ${QUERY_LIMITS.select} fields`);
|
|
163
|
+
query.select.forEach(field);
|
|
164
|
+
}
|
|
165
|
+
if (query.order !== undefined) {
|
|
166
|
+
if (!Array.isArray(query.order))
|
|
167
|
+
fail(`order must be an array of [field, "ASC" | "DESC"] (got ${shown(query.order)})`);
|
|
168
|
+
if (query.order.length > QUERY_LIMITS.order)
|
|
169
|
+
fail(`order takes at most ${QUERY_LIMITS.order} fields`);
|
|
170
|
+
for (const item of query.order) {
|
|
171
|
+
if (!Array.isArray(item) || item.length !== 2)
|
|
172
|
+
fail(`order must be an array of [field, "ASC" | "DESC"] (got ${shown(item)})`);
|
|
173
|
+
const [name, direction] = item;
|
|
174
|
+
field(name);
|
|
175
|
+
if (direction !== "ASC" && direction !== "DESC")
|
|
176
|
+
fail(`order direction must be "ASC" or "DESC" (got ${shown(direction)})`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (query.limit !== undefined)
|
|
180
|
+
nonNegative(query.limit, "limit");
|
|
181
|
+
if (query.skip !== undefined)
|
|
182
|
+
nonNegative(query.skip, "skip");
|
|
183
|
+
if (query.count !== undefined && typeof query.count !== "boolean")
|
|
184
|
+
fail(`count must be a boolean (got ${shown(query.count)})`);
|
|
185
|
+
return query;
|
|
186
|
+
}
|
|
187
|
+
function valueAt(entry, field) {
|
|
188
|
+
let value = entry;
|
|
189
|
+
for (const key of field.split(".")) {
|
|
190
|
+
if (!isRecord(value) || !Object.hasOwn(value, key))
|
|
191
|
+
return null;
|
|
192
|
+
value = value[key];
|
|
193
|
+
}
|
|
194
|
+
return value ?? null;
|
|
195
|
+
}
|
|
196
|
+
var kind = (value) => typeof value === "boolean" ? 1 : typeof value === "number" ? 2 : typeof value === "string" ? 3 : Array.isArray(value) ? 4 : 5;
|
|
197
|
+
function compareText(a, b) {
|
|
198
|
+
if (a === b)
|
|
199
|
+
return 0;
|
|
200
|
+
const left = a[Symbol.iterator]();
|
|
201
|
+
const right = b[Symbol.iterator]();
|
|
202
|
+
for (;; ) {
|
|
203
|
+
const x = left.next();
|
|
204
|
+
const y = right.next();
|
|
205
|
+
if (x.done || y.done)
|
|
206
|
+
return x.done ? y.done ? 0 : -1 : 1;
|
|
207
|
+
const delta = x.value.codePointAt(0) - y.value.codePointAt(0);
|
|
208
|
+
if (delta)
|
|
209
|
+
return delta < 0 ? -1 : 1;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function compare(a, b) {
|
|
213
|
+
const ka = kind(a);
|
|
214
|
+
const kb = kind(b);
|
|
215
|
+
if (ka !== kb)
|
|
216
|
+
return ka - kb;
|
|
217
|
+
if (ka === 1)
|
|
218
|
+
return Number(a) - Number(b);
|
|
219
|
+
if (ka === 2)
|
|
220
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
221
|
+
if (ka === 3)
|
|
222
|
+
return compareText(a, b);
|
|
223
|
+
return compareText(JSON.stringify(a), JSON.stringify(b));
|
|
224
|
+
}
|
|
225
|
+
var equal = (a, b) => a !== null && b !== null && compare(a, b) === 0;
|
|
226
|
+
var ordered = (a, b, test) => a === null || b === null ? null : test(compare(a, b));
|
|
227
|
+
var textOf = (value) => typeof value === "string" ? value : typeof value === "boolean" ? value ? "1" : "0" : typeof value === "number" ? String(value) : JSON.stringify(value);
|
|
228
|
+
var foldAscii = (char) => char.length === 1 && char >= "A" && char <= "Z" ? String.fromCharCode(char.charCodeAt(0) + 32) : char;
|
|
229
|
+
function like(text, pattern) {
|
|
230
|
+
const s = Array.from(text, foldAscii);
|
|
231
|
+
const p = Array.from(pattern, foldAscii);
|
|
232
|
+
let i = 0;
|
|
233
|
+
let j = 0;
|
|
234
|
+
let star = -1;
|
|
235
|
+
let mark = 0;
|
|
236
|
+
while (i < s.length) {
|
|
237
|
+
if (j < p.length && p[j] !== "%" && (p[j] === "_" || p[j] === s[i])) {
|
|
238
|
+
i++;
|
|
239
|
+
j++;
|
|
240
|
+
} else if (j < p.length && p[j] === "%") {
|
|
241
|
+
star = j++;
|
|
242
|
+
mark = i;
|
|
243
|
+
} else if (star !== -1) {
|
|
244
|
+
j = star + 1;
|
|
245
|
+
i = ++mark;
|
|
246
|
+
} else
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
while (p[j] === "%")
|
|
250
|
+
j++;
|
|
251
|
+
return j === p.length;
|
|
252
|
+
}
|
|
253
|
+
function matches(entry, { field, operator, value }) {
|
|
254
|
+
const actual = valueAt(entry, field);
|
|
255
|
+
switch (operator) {
|
|
256
|
+
case "IS NULL":
|
|
257
|
+
return actual === null;
|
|
258
|
+
case "IS NOT NULL":
|
|
259
|
+
return actual !== null;
|
|
260
|
+
case "=":
|
|
261
|
+
return equal(actual, value ?? null);
|
|
262
|
+
case "<>":
|
|
263
|
+
return actual !== null && value !== null && !equal(actual, value);
|
|
264
|
+
case ">":
|
|
265
|
+
return ordered(actual, value ?? null, (order) => order > 0) === true;
|
|
266
|
+
case ">=":
|
|
267
|
+
return ordered(actual, value ?? null, (order) => order >= 0) === true;
|
|
268
|
+
case "<":
|
|
269
|
+
return ordered(actual, value ?? null, (order) => order < 0) === true;
|
|
270
|
+
case "<=":
|
|
271
|
+
return ordered(actual, value ?? null, (order) => order <= 0) === true;
|
|
272
|
+
case "IN":
|
|
273
|
+
case "NOT IN": {
|
|
274
|
+
const list = value;
|
|
275
|
+
if (list.length === 0)
|
|
276
|
+
return operator === "NOT IN";
|
|
277
|
+
if (actual === null)
|
|
278
|
+
return false;
|
|
279
|
+
const items = Array.isArray(actual) ? actual : [actual];
|
|
280
|
+
const found = items.some((item) => list.some((candidate) => equal(item, candidate)));
|
|
281
|
+
if (operator === "IN")
|
|
282
|
+
return found;
|
|
283
|
+
return !found && !list.includes(null);
|
|
284
|
+
}
|
|
285
|
+
case "BETWEEN":
|
|
286
|
+
case "NOT BETWEEN": {
|
|
287
|
+
const [low, high] = value;
|
|
288
|
+
const above = ordered(actual, low, (order) => order >= 0);
|
|
289
|
+
const below = ordered(actual, high, (order) => order <= 0);
|
|
290
|
+
const inside = above === false || below === false ? false : above === null || below === null ? null : true;
|
|
291
|
+
return inside === null ? false : operator === "BETWEEN" ? inside : !inside;
|
|
292
|
+
}
|
|
293
|
+
case "LIKE":
|
|
294
|
+
case "NOT LIKE":
|
|
295
|
+
return actual !== null && like(textOf(actual), value) === (operator === "LIKE");
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function passes(entry, clauses) {
|
|
299
|
+
let result = true;
|
|
300
|
+
clauses.forEach((clause, index) => {
|
|
301
|
+
const term = "where" in clause ? passes(entry, clause.where) : matches(entry, clause);
|
|
302
|
+
result = index === 0 ? term : clause.join === "AND" ? result && term : result || term;
|
|
303
|
+
});
|
|
304
|
+
return result;
|
|
305
|
+
}
|
|
306
|
+
function sorter(order) {
|
|
307
|
+
return (a, b) => {
|
|
308
|
+
for (const [field, direction] of order) {
|
|
309
|
+
const x = valueAt(a, field);
|
|
310
|
+
const y = valueAt(b, field);
|
|
311
|
+
const result = x === null ? y === null ? 0 : -1 : y === null ? 1 : compare(x, y);
|
|
312
|
+
if (result)
|
|
313
|
+
return direction === "DESC" ? -result : result;
|
|
314
|
+
}
|
|
315
|
+
return 0;
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
function pick(entry, select) {
|
|
319
|
+
const out = { id: entry.id };
|
|
320
|
+
const whole = ["id"];
|
|
321
|
+
for (const field of select.toSorted((a, b) => a.length - b.length)) {
|
|
322
|
+
if (whole.some((taken) => field === taken || field.startsWith(`${taken}.`)))
|
|
323
|
+
continue;
|
|
324
|
+
const value = valueAt(entry, field);
|
|
325
|
+
whole.push(field);
|
|
326
|
+
const keys = field.split(".");
|
|
327
|
+
let target = out;
|
|
328
|
+
for (const key of keys.slice(0, -1)) {
|
|
329
|
+
if (!Object.hasOwn(target, key) || !isRecord(target[key]))
|
|
330
|
+
Object.defineProperty(target, key, { value: {}, writable: true, enumerable: true, configurable: true });
|
|
331
|
+
target = target[key];
|
|
332
|
+
}
|
|
333
|
+
Object.defineProperty(target, keys.at(-1), {
|
|
334
|
+
value: structuredClone(value),
|
|
335
|
+
writable: true,
|
|
336
|
+
enumerable: true,
|
|
337
|
+
configurable: true
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
return out;
|
|
341
|
+
}
|
|
342
|
+
function runQuery(name, collection, entries, value) {
|
|
343
|
+
const query = checkQuery(value, knownFields(collection.type, entries), name);
|
|
344
|
+
const where = query.where ?? [];
|
|
345
|
+
const found = where.length ? entries.filter((entry) => passes(entry, where)) : [...entries];
|
|
346
|
+
if (query.count)
|
|
347
|
+
return found.length;
|
|
348
|
+
const order = query.order ?? (collection.order ? [collection.order] : []);
|
|
349
|
+
const sorted = order.length ? found.sort(sorter(order)) : found;
|
|
350
|
+
const skip = query.skip ?? 0;
|
|
351
|
+
const page = sorted.slice(skip, query.limit === undefined ? undefined : skip + query.limit);
|
|
352
|
+
return query.select ? page.map((entry) => pick(entry, query.select)) : page.map((entry) => structuredClone(entry));
|
|
353
|
+
}
|
|
354
|
+
async function queryStore(store, name, query) {
|
|
355
|
+
const collection = Object.hasOwn(store.collections, name) ? store.collections[name] : fail(`unknown collection ${shown(name)}`);
|
|
356
|
+
return runQuery(name, collection, await store.entries(name), query);
|
|
357
|
+
}
|
|
358
|
+
var prefixed = (error) => error instanceof QueryError ? new QueryError(`queryCollection: ${error.message}`) : error;
|
|
359
|
+
function clauseAdder(clauses, join) {
|
|
360
|
+
return (field, operator, value) => {
|
|
361
|
+
if (typeof field === "function") {
|
|
362
|
+
const group = [];
|
|
363
|
+
field(groupBuilder(group));
|
|
364
|
+
clauses.push({ join, where: group });
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
try {
|
|
368
|
+
checkCondition(field, operator, value);
|
|
369
|
+
} catch (error) {
|
|
370
|
+
throw prefixed(error);
|
|
371
|
+
}
|
|
372
|
+
clauses.push(value === undefined ? { join, field, operator } : { join, field, operator, value });
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
function groupBuilder(clauses) {
|
|
376
|
+
const builder = {};
|
|
377
|
+
const chain = (add) => (field, operator, value) => {
|
|
378
|
+
add(field, operator, value);
|
|
379
|
+
return builder;
|
|
380
|
+
};
|
|
381
|
+
builder.where = chain(clauseAdder(clauses, "AND"));
|
|
382
|
+
builder.andWhere = builder.where;
|
|
383
|
+
builder.orWhere = chain(clauseAdder(clauses, "OR"));
|
|
384
|
+
return builder;
|
|
385
|
+
}
|
|
386
|
+
function createQuery(run) {
|
|
387
|
+
const where = [];
|
|
388
|
+
const state = {};
|
|
389
|
+
const execute = async (query) => {
|
|
390
|
+
try {
|
|
391
|
+
return await run(query);
|
|
392
|
+
} catch (error) {
|
|
393
|
+
throw prefixed(error);
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
const paging = (value, name) => {
|
|
397
|
+
if (!Number.isSafeInteger(value) || value < 0)
|
|
398
|
+
throw new QueryError(`queryCollection: ${name} must be a non-negative integer`);
|
|
399
|
+
state[name] = value;
|
|
400
|
+
};
|
|
401
|
+
const listed = () => ({ ...where.length ? { where } : {}, ...state });
|
|
402
|
+
const builder = {
|
|
403
|
+
where: undefined,
|
|
404
|
+
andWhere: undefined,
|
|
405
|
+
orWhere: undefined,
|
|
406
|
+
path: (path) => builder.where("path", "=", path),
|
|
407
|
+
select(...fields) {
|
|
408
|
+
state.select = [...state.select ?? [], ...fields];
|
|
409
|
+
return builder;
|
|
410
|
+
},
|
|
411
|
+
order(field, direction) {
|
|
412
|
+
(state.order ??= []).push([field, direction]);
|
|
413
|
+
return builder;
|
|
414
|
+
},
|
|
415
|
+
limit(value) {
|
|
416
|
+
paging(value, "limit");
|
|
417
|
+
return builder;
|
|
418
|
+
},
|
|
419
|
+
skip(value) {
|
|
420
|
+
paging(value, "skip");
|
|
421
|
+
return builder;
|
|
422
|
+
},
|
|
423
|
+
all: () => execute(listed()),
|
|
424
|
+
first: async () => (await execute({ ...listed(), limit: 1 }))[0],
|
|
425
|
+
count: () => execute(where.length ? { where, count: true } : { count: true })
|
|
426
|
+
};
|
|
427
|
+
const chain = (add) => (field, operator, value) => {
|
|
428
|
+
add(field, operator, value);
|
|
429
|
+
return builder;
|
|
430
|
+
};
|
|
431
|
+
builder.where = chain(clauseAdder(where, "AND"));
|
|
432
|
+
builder.andWhere = builder.where;
|
|
433
|
+
builder.orWhere = chain(clauseAdder(where, "OR"));
|
|
434
|
+
return builder;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// packages/content/src/runtime/navigation.ts
|
|
438
|
+
var PREFIX = /^(\d+)\./;
|
|
439
|
+
var BASE_KEYS = new Set(["title", "path", "stem", "icon", "children"]);
|
|
440
|
+
var isRecord2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
441
|
+
var strip = (segment) => segment.replace(PREFIX, "");
|
|
442
|
+
function humanize(segment) {
|
|
443
|
+
const text = strip(segment).replace(/-/g, " ");
|
|
444
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
445
|
+
}
|
|
446
|
+
function newNode(segment, stem) {
|
|
447
|
+
return { segment, stem, pages: [], dirs: new Map, rows: [] };
|
|
448
|
+
}
|
|
449
|
+
function rankOf(segment, data) {
|
|
450
|
+
if (typeof data?.order === "number")
|
|
451
|
+
return data.order;
|
|
452
|
+
const prefix = PREFIX.exec(segment);
|
|
453
|
+
return prefix ? Number(prefix[1]) : undefined;
|
|
454
|
+
}
|
|
455
|
+
function compareRank(a, b) {
|
|
456
|
+
if (a.rank !== undefined && b.rank === undefined)
|
|
457
|
+
return -1;
|
|
458
|
+
if (a.rank === undefined && b.rank !== undefined)
|
|
459
|
+
return 1;
|
|
460
|
+
if (a.rank !== undefined && a.rank !== b.rank)
|
|
461
|
+
return a.rank - b.rank;
|
|
462
|
+
return a.segment < b.segment ? -1 : a.segment > b.segment ? 1 : 0;
|
|
463
|
+
}
|
|
464
|
+
function extras(target, source, fields) {
|
|
465
|
+
if (!source)
|
|
466
|
+
return;
|
|
467
|
+
for (const field of fields) {
|
|
468
|
+
const head = field.split(".")[0];
|
|
469
|
+
if (!BASE_KEYS.has(head) && source[head] !== null && source[head] !== undefined)
|
|
470
|
+
target[head] = structuredClone(source[head]);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
var navOf = (row) => isRecord2(row?.navigation) ? row.navigation : {};
|
|
474
|
+
var text = (value) => typeof value === "string" && value !== "" ? value : undefined;
|
|
475
|
+
function pathOfDir(node, depth) {
|
|
476
|
+
const row = node.rows[0];
|
|
477
|
+
const stemSegments = String(row.stem).split("/");
|
|
478
|
+
const own = strip(stemSegments.at(-1)) === "index" ? stemSegments.length - 1 : stemSegments.length;
|
|
479
|
+
const segments = String(row.path).split("/").filter(Boolean);
|
|
480
|
+
const prefix = segments.length - own;
|
|
481
|
+
return prefix >= 0 && segments.length >= prefix + depth ? `/${segments.slice(0, prefix + depth).join("/")}` : `/${node.stem.split("/").map(strip).join("/")}`;
|
|
482
|
+
}
|
|
483
|
+
function leaf(row, segment, fields) {
|
|
484
|
+
const nav = navOf(row);
|
|
485
|
+
const item = { title: "", path: "", stem: "" };
|
|
486
|
+
extras(item, row, fields);
|
|
487
|
+
item.title = text(nav.title) ?? text(row.title) ?? humanize(segment);
|
|
488
|
+
item.path = String(row.path);
|
|
489
|
+
item.stem = String(row.stem);
|
|
490
|
+
const icon = text(nav.icon);
|
|
491
|
+
if (icon !== undefined)
|
|
492
|
+
item.icon = icon;
|
|
493
|
+
return item;
|
|
494
|
+
}
|
|
495
|
+
function itemsOf(node, depth, fields) {
|
|
496
|
+
const entries = [];
|
|
497
|
+
for (const { segment, row } of node.pages) {
|
|
498
|
+
if (row.navigation !== false)
|
|
499
|
+
entries.push({ segment, rank: rankOf(segment, undefined), item: leaf(row, segment, fields) });
|
|
500
|
+
}
|
|
501
|
+
for (const dir of node.dirs.values()) {
|
|
502
|
+
if (dir.index?.navigation === false)
|
|
503
|
+
continue;
|
|
504
|
+
const children = itemsOf(dir, depth + 1, fields);
|
|
505
|
+
if (!dir.index && !children.length)
|
|
506
|
+
continue;
|
|
507
|
+
const nav = navOf(dir.index);
|
|
508
|
+
const item = { title: "", path: "", stem: "" };
|
|
509
|
+
extras(item, dir.index, fields);
|
|
510
|
+
extras(item, dir.data, fields);
|
|
511
|
+
item.title = text(dir.data?.title) ?? text(nav.title) ?? text(dir.index?.title) ?? humanize(dir.segment);
|
|
512
|
+
item.path = dir.index ? String(dir.index.path) : pathOfDir(dir, depth + 1);
|
|
513
|
+
item.stem = dir.stem;
|
|
514
|
+
const icon = text(dir.data?.icon) ?? text(nav.icon);
|
|
515
|
+
if (icon !== undefined)
|
|
516
|
+
item.icon = icon;
|
|
517
|
+
if (children.length)
|
|
518
|
+
item.children = children;
|
|
519
|
+
entries.push({ segment: dir.segment, rank: rankOf(dir.segment, dir.data), item });
|
|
520
|
+
}
|
|
521
|
+
return entries.toSorted(compareRank).map(({ item }) => item);
|
|
522
|
+
}
|
|
523
|
+
function buildNavigation(rows, fields = []) {
|
|
524
|
+
const root = newNode("", "");
|
|
525
|
+
for (const row of rows) {
|
|
526
|
+
const segments = String(row.stem).split("/");
|
|
527
|
+
let node = root;
|
|
528
|
+
segments.slice(0, -1).forEach((segment, index) => {
|
|
529
|
+
let next = node.dirs.get(segment);
|
|
530
|
+
if (!next)
|
|
531
|
+
node.dirs.set(segment, next = newNode(segment, segments.slice(0, index + 1).join("/")));
|
|
532
|
+
next.rows.push(row);
|
|
533
|
+
const data = isRecord2(row.navigationDirs) ? row.navigationDirs[next.stem] : undefined;
|
|
534
|
+
if (isRecord2(data))
|
|
535
|
+
next.data = { ...next.data, ...data };
|
|
536
|
+
node = next;
|
|
537
|
+
});
|
|
538
|
+
const last = segments.at(-1);
|
|
539
|
+
if (strip(last) === "index")
|
|
540
|
+
node.index = row;
|
|
541
|
+
else
|
|
542
|
+
node.pages.push({ segment: last, row });
|
|
543
|
+
}
|
|
544
|
+
const items = itemsOf(root, 0, fields);
|
|
545
|
+
if (root.index && root.index.navigation !== false)
|
|
546
|
+
items.unshift(leaf(root.index, "index", fields));
|
|
547
|
+
return items;
|
|
548
|
+
}
|
|
549
|
+
async function navigationOf(query, extraFields = []) {
|
|
550
|
+
if (!Array.isArray(extraFields) || !extraFields.every((field) => typeof field === "string"))
|
|
551
|
+
throw new QueryError("queryCollectionNavigation: extraFields must be an array of field names");
|
|
552
|
+
const rows = await query().select("stem", "path", "title", "navigation", "navigationDirs", ...extraFields).all();
|
|
553
|
+
return buildNavigation(rows, extraFields);
|
|
554
|
+
}
|
|
555
|
+
var count = (value, name) => {
|
|
556
|
+
if (value === undefined)
|
|
557
|
+
return 1;
|
|
558
|
+
if (!Number.isSafeInteger(value) || value < 0)
|
|
559
|
+
throw new QueryError(`queryCollectionItemSurroundings: ${name} must be a non-negative integer`);
|
|
560
|
+
return value;
|
|
561
|
+
};
|
|
562
|
+
async function surroundingsOf(query, path, options = {}) {
|
|
563
|
+
const before = count(options.before, "before");
|
|
564
|
+
const after = count(options.after, "after");
|
|
565
|
+
const fields = options.fields ?? [];
|
|
566
|
+
if (!Array.isArray(fields))
|
|
567
|
+
throw new QueryError("queryCollectionItemSurroundings: fields must be an array of field names");
|
|
568
|
+
const rows = await query().select("path", ...fields).all();
|
|
569
|
+
const at = rows.findIndex((row) => row.path === path);
|
|
570
|
+
const around = (from, to) => Array.from({ length: to - from }, (_, index) => at < 0 ? null : rows[at + from + index] ?? null);
|
|
571
|
+
return [...around(-before, 0), ...around(1, after + 1)];
|
|
572
|
+
}
|
|
573
|
+
function walk(items, path, trail = []) {
|
|
574
|
+
for (const item of items) {
|
|
575
|
+
if (item.path === path)
|
|
576
|
+
return [...trail, item];
|
|
577
|
+
const found = item.children && walk(item.children, path, [...trail, item]);
|
|
578
|
+
if (found)
|
|
579
|
+
return found;
|
|
580
|
+
}
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
var bare = ({ children: _, ...item }) => item;
|
|
584
|
+
function findPageHeadline2(tree, path) {
|
|
585
|
+
return walk(tree, path)?.at(-2)?.title;
|
|
586
|
+
}
|
|
587
|
+
function findPageBreadcrumb2(tree, path) {
|
|
588
|
+
return (walk(tree, path) ?? []).map(bare);
|
|
589
|
+
}
|
|
590
|
+
function findPageChildren2(tree, path) {
|
|
591
|
+
return walk(tree, path)?.at(-1)?.children ?? [];
|
|
592
|
+
}
|
|
593
|
+
function findPageSiblings2(tree, path) {
|
|
594
|
+
const trail = walk(tree, path);
|
|
595
|
+
if (!trail)
|
|
596
|
+
return [];
|
|
597
|
+
const parent = trail.at(-2);
|
|
598
|
+
return (parent ? parent.children : tree).filter((item) => item.path !== path);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// packages/content/src/runtime/sections.ts
|
|
602
|
+
var BLOCKS = new Set([
|
|
603
|
+
"root",
|
|
604
|
+
"p",
|
|
605
|
+
"h1",
|
|
606
|
+
"h2",
|
|
607
|
+
"h3",
|
|
608
|
+
"h4",
|
|
609
|
+
"h5",
|
|
610
|
+
"h6",
|
|
611
|
+
"blockquote",
|
|
612
|
+
"ul",
|
|
613
|
+
"ol",
|
|
614
|
+
"li",
|
|
615
|
+
"pre",
|
|
616
|
+
"hr",
|
|
617
|
+
"br",
|
|
618
|
+
"html",
|
|
619
|
+
"table",
|
|
620
|
+
"thead",
|
|
621
|
+
"tbody",
|
|
622
|
+
"tr",
|
|
623
|
+
"th",
|
|
624
|
+
"td"
|
|
625
|
+
]);
|
|
626
|
+
var HEADING = /^h([1-6])$/;
|
|
627
|
+
function depthOf(value, name) {
|
|
628
|
+
const match = typeof value === "string" ? HEADING.exec(value) : null;
|
|
629
|
+
if (!match)
|
|
630
|
+
throw new QueryError(`${name} must be "h1" to "h6" (got ${JSON.stringify(value)})`);
|
|
631
|
+
return Number(match[1]);
|
|
632
|
+
}
|
|
633
|
+
function resolveSectionOptions(options = {}) {
|
|
634
|
+
const { ignoredTags = [], minHeading = "h1", maxHeading = "h6" } = options;
|
|
635
|
+
if (!Array.isArray(ignoredTags) || !ignoredTags.every((tag) => typeof tag === "string"))
|
|
636
|
+
throw new QueryError(`ignoredTags must be an array of tag names (got ${JSON.stringify(ignoredTags)})`);
|
|
637
|
+
const min = depthOf(minHeading, "minHeading");
|
|
638
|
+
const max = depthOf(maxHeading, "maxHeading");
|
|
639
|
+
if (min > max)
|
|
640
|
+
throw new QueryError(`minHeading ${minHeading} is deeper than maxHeading ${maxHeading}`);
|
|
641
|
+
return { ignored: new Set(ignoredTags), min, max };
|
|
642
|
+
}
|
|
643
|
+
function collect(node, ignored, out) {
|
|
644
|
+
if (typeof node === "string")
|
|
645
|
+
return void out.push(node);
|
|
646
|
+
const tag = node[0];
|
|
647
|
+
if (ignored.has(tag) || tag === "html")
|
|
648
|
+
return void out.push(" ");
|
|
649
|
+
const block = BLOCKS.has(tag);
|
|
650
|
+
if (block)
|
|
651
|
+
out.push(" ");
|
|
652
|
+
for (let i = 2;i < node.length; i++)
|
|
653
|
+
collect(node[i], ignored, out);
|
|
654
|
+
if (block)
|
|
655
|
+
out.push(" ");
|
|
656
|
+
}
|
|
657
|
+
var plain = (parts) => parts.join("").replace(/\s+/g, " ").trim();
|
|
658
|
+
function sectionsOf(page, { ignored, min, max }) {
|
|
659
|
+
const out = [];
|
|
660
|
+
const stack = [];
|
|
661
|
+
let current = {
|
|
662
|
+
id: page.path,
|
|
663
|
+
title: page.title ?? "",
|
|
664
|
+
titles: [],
|
|
665
|
+
level: 1,
|
|
666
|
+
parts: [],
|
|
667
|
+
lead: true
|
|
668
|
+
};
|
|
669
|
+
const close = () => {
|
|
670
|
+
const content = plain(current.parts);
|
|
671
|
+
if (!current.lead || content !== "" || current.title !== "" && min > 1)
|
|
672
|
+
out.push({ id: current.id, title: current.title, titles: current.titles, content, level: current.level });
|
|
673
|
+
};
|
|
674
|
+
for (let i = 2;i < page.body.length; i++) {
|
|
675
|
+
const node = page.body[i];
|
|
676
|
+
const depth = typeof node === "string" ? 0 : Number(HEADING.exec(node[0])?.[1] ?? 0);
|
|
677
|
+
if (depth >= min && depth <= max) {
|
|
678
|
+
const element = node;
|
|
679
|
+
const text = [];
|
|
680
|
+
for (let j = 2;j < element.length; j++)
|
|
681
|
+
collect(element[j], new Set, text);
|
|
682
|
+
const title = plain(text);
|
|
683
|
+
close();
|
|
684
|
+
while (stack.length && stack[stack.length - 1].depth >= depth)
|
|
685
|
+
stack.pop();
|
|
686
|
+
const id = element[1]?.id;
|
|
687
|
+
current = {
|
|
688
|
+
id: typeof id === "string" && id !== "" ? `${page.path}#${id}` : page.path,
|
|
689
|
+
title,
|
|
690
|
+
titles: stack.map((item) => item.text),
|
|
691
|
+
level: depth,
|
|
692
|
+
parts: [],
|
|
693
|
+
lead: false
|
|
694
|
+
};
|
|
695
|
+
stack.push({ depth, text: title });
|
|
696
|
+
} else {
|
|
697
|
+
collect(node, ignored, current.parts);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
close();
|
|
701
|
+
return out;
|
|
702
|
+
}
|
|
703
|
+
async function searchSectionsOf(query, options) {
|
|
704
|
+
let resolved;
|
|
705
|
+
try {
|
|
706
|
+
resolved = resolveSectionOptions(options);
|
|
707
|
+
} catch (error) {
|
|
708
|
+
throw error instanceof QueryError ? new QueryError(`queryCollectionSearchSections: ${error.message}`) : error;
|
|
709
|
+
}
|
|
710
|
+
const rows = await query().select("path", "title", "body").all();
|
|
711
|
+
return rows.flatMap((row) => sectionsOf(row, resolved));
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
export { QueryError, runQuery, queryStore, createQuery, navigationOf, surroundingsOf, findPageHeadline2, findPageBreadcrumb2, findPageChildren2, findPageSiblings2, searchSectionsOf };
|