@hamur/content 0.0.0-stage → 0.0.1
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 +110 -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,97 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
QueryError,
|
|
4
|
+
runQuery,
|
|
5
|
+
queryStore,
|
|
6
|
+
createQuery,
|
|
7
|
+
navigationOf,
|
|
8
|
+
surroundingsOf,
|
|
9
|
+
findPageHeadline2,
|
|
10
|
+
findPageBreadcrumb2,
|
|
11
|
+
findPageChildren2,
|
|
12
|
+
findPageSiblings2,
|
|
13
|
+
searchSectionsOf
|
|
14
|
+
} from "../chunks/bun-render-7jxnxg3v.js";
|
|
15
|
+
|
|
16
|
+
// packages/content/src/query.ts
|
|
17
|
+
import client from "#hamur/content/client";
|
|
18
|
+
import { noteDependency } from "hamur/app";
|
|
19
|
+
|
|
20
|
+
// packages/content/src/runtime/client.ts
|
|
21
|
+
import { $fetch, FetchError } from "hamur/app";
|
|
22
|
+
var QUERY_PATH = "/_hamur/content/query";
|
|
23
|
+
async function postQuery(body) {
|
|
24
|
+
try {
|
|
25
|
+
return await $fetch(QUERY_PATH, { method: "POST", body, retry: 0 });
|
|
26
|
+
} catch (error) {
|
|
27
|
+
const message = error instanceof FetchError && error.status === 400 ? error.data?.message : undefined;
|
|
28
|
+
throw typeof message === "string" ? new QueryError(message) : error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
var caches = new Set;
|
|
32
|
+
function createClientQuery(config, post = postQuery) {
|
|
33
|
+
const loaded = new Map;
|
|
34
|
+
caches.add(loaded);
|
|
35
|
+
const entries = (name, load) => {
|
|
36
|
+
let promise = loaded.get(name);
|
|
37
|
+
if (!promise) {
|
|
38
|
+
promise = load().then((chunk) => chunk.default);
|
|
39
|
+
loaded.set(name, promise);
|
|
40
|
+
promise.catch(() => loaded.get(name) === promise && loaded.delete(name));
|
|
41
|
+
}
|
|
42
|
+
return promise;
|
|
43
|
+
};
|
|
44
|
+
return (name) => {
|
|
45
|
+
const collection = Object.hasOwn(config.collections, name) ? config.collections[name] : undefined;
|
|
46
|
+
if (!collection)
|
|
47
|
+
throw new QueryError(`queryCollection: unknown collection ${JSON.stringify(name)}`);
|
|
48
|
+
if (!collection.expose)
|
|
49
|
+
throw new QueryError(`queryCollection(${JSON.stringify(name)}): the collection is not exposed to the client (expose: false)`);
|
|
50
|
+
const { load } = collection;
|
|
51
|
+
if (config.mode === "local" && load)
|
|
52
|
+
return createQuery(async (query) => runQuery(name, collection, await entries(name, load), query));
|
|
53
|
+
return createQuery((query) => post({ collection: name, query }));
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// packages/content/src/runtime/server-store.ts
|
|
58
|
+
var current;
|
|
59
|
+
function serverStore() {
|
|
60
|
+
return current;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// packages/content/src/query.ts
|
|
64
|
+
var inBrowser = createClientQuery(client);
|
|
65
|
+
function queryCollection(name) {
|
|
66
|
+
noteDependency(`content:${name}`);
|
|
67
|
+
if (!import.meta.server)
|
|
68
|
+
return inBrowser(name);
|
|
69
|
+
return createQuery((query) => {
|
|
70
|
+
const store = serverStore();
|
|
71
|
+
if (!store)
|
|
72
|
+
throw new QueryError("the content store is not loaded; add @hamur/content to modules");
|
|
73
|
+
return queryStore(store, name, query);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function queryCollectionNavigation(name, extraFields) {
|
|
77
|
+
noteDependency(`content:${name}`);
|
|
78
|
+
return navigationOf(() => queryCollection(name), extraFields);
|
|
79
|
+
}
|
|
80
|
+
function queryCollectionItemSurroundings(name, path, options) {
|
|
81
|
+
noteDependency(`content:${name}`);
|
|
82
|
+
return surroundingsOf(() => queryCollection(name), path, options);
|
|
83
|
+
}
|
|
84
|
+
function queryCollectionSearchSections(name, options) {
|
|
85
|
+
noteDependency(`content:${name}`);
|
|
86
|
+
return searchSectionsOf(() => queryCollection(name), options);
|
|
87
|
+
}
|
|
88
|
+
export {
|
|
89
|
+
findPageBreadcrumb2 as findPageBreadcrumb,
|
|
90
|
+
findPageChildren2 as findPageChildren,
|
|
91
|
+
findPageHeadline2 as findPageHeadline,
|
|
92
|
+
findPageSiblings2 as findPageSiblings,
|
|
93
|
+
queryCollection,
|
|
94
|
+
queryCollectionItemSurroundings,
|
|
95
|
+
queryCollectionNavigation,
|
|
96
|
+
queryCollectionSearchSections
|
|
97
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/content/src/render.ts
|
|
3
|
+
import { renderMarkdownAst } from "hamur/markdown";
|
|
4
|
+
async function renderEntry(entry) {
|
|
5
|
+
if (!Array.isArray(entry.body))
|
|
6
|
+
throw new TypeError(`renderEntry needs a page collection entry (got data collection "${String(entry.collection)}")`);
|
|
7
|
+
const page = entry;
|
|
8
|
+
return { html: renderMarkdownAst(page.body), headings: page.headings, ast: page.body };
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
renderEntry
|
|
12
|
+
};
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
queryStore,
|
|
4
|
+
createQuery,
|
|
5
|
+
navigationOf,
|
|
6
|
+
surroundingsOf,
|
|
7
|
+
findPageHeadline2,
|
|
8
|
+
findPageBreadcrumb2,
|
|
9
|
+
findPageChildren2,
|
|
10
|
+
findPageSiblings2,
|
|
11
|
+
searchSectionsOf
|
|
12
|
+
} from "../../chunks/bun-render-7jxnxg3v.js";
|
|
13
|
+
import {
|
|
14
|
+
searchIndex
|
|
15
|
+
} from "../../chunks/bun-render-65mwzeq2.js";
|
|
16
|
+
|
|
17
|
+
// packages/content/src/server/index.ts
|
|
18
|
+
import"hamur/server-only";
|
|
19
|
+
|
|
20
|
+
// packages/content/src/server/query.ts
|
|
21
|
+
import store from "#hamur/content/store";
|
|
22
|
+
function queryCollection(_event, name) {
|
|
23
|
+
return createQuery((query) => queryStore(store, name, query));
|
|
24
|
+
}
|
|
25
|
+
function queryCollectionNavigation(event, name, extraFields) {
|
|
26
|
+
return navigationOf(() => queryCollection(event, name), extraFields);
|
|
27
|
+
}
|
|
28
|
+
function queryCollectionItemSurroundings(event, name, path, options) {
|
|
29
|
+
return surroundingsOf(() => queryCollection(event, name), path, options);
|
|
30
|
+
}
|
|
31
|
+
function queryCollectionSearchSections(event, name, options) {
|
|
32
|
+
return searchSectionsOf(() => queryCollection(event, name), options);
|
|
33
|
+
}
|
|
34
|
+
// packages/content/src/server/search.ts
|
|
35
|
+
import searches from "#hamur/content/search";
|
|
36
|
+
async function searchCollection(_event, name, query, { limit = 20 } = {}) {
|
|
37
|
+
const load = Object.hasOwn(searches, name) ? searches[name] : undefined;
|
|
38
|
+
if (!load)
|
|
39
|
+
throw new Error(`searchCollection(${JSON.stringify(name)}): add ${JSON.stringify(name)} to content.search.collections`);
|
|
40
|
+
if (typeof query !== "string")
|
|
41
|
+
throw new TypeError(`search: the query is a string (got ${JSON.stringify(query)})`);
|
|
42
|
+
if (!Number.isSafeInteger(limit) || limit < 0)
|
|
43
|
+
throw new TypeError("search: limit must be a non-negative integer");
|
|
44
|
+
return searchIndex((await load()).default, query, limit);
|
|
45
|
+
}
|
|
46
|
+
// packages/content/src/server/live.ts
|
|
47
|
+
import collections, { names } from "#hamur/content/live";
|
|
48
|
+
import { useLogger, useStorage } from "hamur/server";
|
|
49
|
+
|
|
50
|
+
// packages/content/src/runtime/live.ts
|
|
51
|
+
class LiveError extends Error {
|
|
52
|
+
}
|
|
53
|
+
var isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
54
|
+
var isPlain = (value) => isObject(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
55
|
+
var pathOf = (path) => (path ?? []).map((segment) => String(typeof segment === "object" ? segment.key : segment)).join(".");
|
|
56
|
+
var messageOf = (error) => error instanceof Error ? error.message : String(error);
|
|
57
|
+
var kindOf = (value) => {
|
|
58
|
+
if (typeof value === "number")
|
|
59
|
+
return String(value);
|
|
60
|
+
if (typeof value !== "object" || value === null)
|
|
61
|
+
return typeof value;
|
|
62
|
+
return value.constructor?.name ?? "object";
|
|
63
|
+
};
|
|
64
|
+
function stable(value, path, seen) {
|
|
65
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
66
|
+
return JSON.stringify(value);
|
|
67
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
68
|
+
return JSON.stringify(value);
|
|
69
|
+
if (typeof value === "object" && (Array.isArray(value) || isPlain(value))) {
|
|
70
|
+
if (seen.has(value))
|
|
71
|
+
throw new TypeError(`the filter must be plain JSON (${path} refers to itself)`);
|
|
72
|
+
seen.add(value);
|
|
73
|
+
let text;
|
|
74
|
+
if (Array.isArray(value)) {
|
|
75
|
+
text = `[${value.map((item, index) => item === undefined ? refuse(item, `${path}[${index}]`) : stable(item, `${path}[${index}]`, seen)).join(",")}]`;
|
|
76
|
+
} else {
|
|
77
|
+
const keys = Object.keys(value).filter((key) => value[key] !== undefined).sort();
|
|
78
|
+
text = `{${keys.map((key) => `${JSON.stringify(key)}:${stable(value[key], `${path}.${key}`, seen)}`).join(",")}}`;
|
|
79
|
+
}
|
|
80
|
+
seen.delete(value);
|
|
81
|
+
return text;
|
|
82
|
+
}
|
|
83
|
+
return refuse(value, path);
|
|
84
|
+
}
|
|
85
|
+
function refuse(value, path) {
|
|
86
|
+
throw new TypeError(`the filter must be plain JSON (got ${kindOf(value)} at ${path})`);
|
|
87
|
+
}
|
|
88
|
+
async function hashOf(text) {
|
|
89
|
+
const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text)));
|
|
90
|
+
return Array.from(digest.subarray(0, 16), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
91
|
+
}
|
|
92
|
+
var liveKeyPrefix = (collection) => `content:live:${collection}`;
|
|
93
|
+
async function liveKey(collection, kind, filter) {
|
|
94
|
+
return `${liveKeyPrefix(collection)}:${await hashOf(`${kind}\x00${filter === undefined ? "" : stable(filter, "filter", new Set)}`)}`;
|
|
95
|
+
}
|
|
96
|
+
function hintOf(value) {
|
|
97
|
+
if (!isObject(value))
|
|
98
|
+
return {};
|
|
99
|
+
const hint = {};
|
|
100
|
+
if (Array.isArray(value.tags))
|
|
101
|
+
hint.tags = value.tags.filter((tag) => typeof tag === "string");
|
|
102
|
+
if (typeof value.maxAge === "number" && Number.isFinite(value.maxAge) && value.maxAge >= 0)
|
|
103
|
+
hint.maxAge = value.maxAge;
|
|
104
|
+
const modified = value.lastModified instanceof Date ? value.lastModified : typeof value.lastModified === "string" || typeof value.lastModified === "number" ? new Date(value.lastModified) : undefined;
|
|
105
|
+
if (modified && !Number.isNaN(modified.getTime()))
|
|
106
|
+
hint.lastModified = modified;
|
|
107
|
+
return hint;
|
|
108
|
+
}
|
|
109
|
+
function mergeHints(hints) {
|
|
110
|
+
const merged = {};
|
|
111
|
+
const tags = new Set;
|
|
112
|
+
for (const hint of hints) {
|
|
113
|
+
if (!hint)
|
|
114
|
+
continue;
|
|
115
|
+
for (const tag of hint.tags ?? [])
|
|
116
|
+
tags.add(tag);
|
|
117
|
+
if (hint.maxAge !== undefined)
|
|
118
|
+
merged.maxAge = Math.min(merged.maxAge ?? Infinity, hint.maxAge);
|
|
119
|
+
if (hint.lastModified && (!merged.lastModified || hint.lastModified > merged.lastModified))
|
|
120
|
+
merged.lastModified = hint.lastModified;
|
|
121
|
+
}
|
|
122
|
+
if (tags.size)
|
|
123
|
+
merged.tags = [...tags];
|
|
124
|
+
return merged;
|
|
125
|
+
}
|
|
126
|
+
function createLiveContent({
|
|
127
|
+
collections,
|
|
128
|
+
names,
|
|
129
|
+
storage,
|
|
130
|
+
parseMarkdown,
|
|
131
|
+
warn = () => {}
|
|
132
|
+
}) {
|
|
133
|
+
const generations = new Map;
|
|
134
|
+
const refreshing = new Map;
|
|
135
|
+
const generationOf = (name) => generations.get(name) ?? 0;
|
|
136
|
+
let warned = false;
|
|
137
|
+
const cacheFailed = (doing, error) => {
|
|
138
|
+
if (warned)
|
|
139
|
+
return;
|
|
140
|
+
warned = true;
|
|
141
|
+
warn(`content: live results are not cached: ${doing} the cache storage failed: ${messageOf(error)}`);
|
|
142
|
+
};
|
|
143
|
+
function definitionOf(call, name) {
|
|
144
|
+
if (typeof name !== "string" || !Object.hasOwn(collections, name))
|
|
145
|
+
throw new TypeError(`${call}: ${JSON.stringify(name)} is not a live collection of content.config.ts`);
|
|
146
|
+
return collections[name];
|
|
147
|
+
}
|
|
148
|
+
async function entryOf(call, definition, raw) {
|
|
149
|
+
if (!isObject(raw) || typeof raw.id !== "string" || !isObject(raw.data))
|
|
150
|
+
throw new LiveError(`${call}: an entry must be { id: string, data: object }`);
|
|
151
|
+
const where = `${call}: entry ${JSON.stringify(raw.id)}`;
|
|
152
|
+
let data = raw.data;
|
|
153
|
+
if (definition.schema) {
|
|
154
|
+
let result;
|
|
155
|
+
try {
|
|
156
|
+
result = await definition.schema["~standard"].validate(data);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
throw new LiveError(`${where}: ${messageOf(error)}`, { cause: error });
|
|
159
|
+
}
|
|
160
|
+
if (result.issues)
|
|
161
|
+
throw new LiveError(result.issues.map((issue) => `${where}: ${pathOf(issue.path) ? `${pathOf(issue.path)}: ` : ""}${issue.message}`).join(`
|
|
162
|
+
`), { cause: result.issues });
|
|
163
|
+
data = result.value;
|
|
164
|
+
}
|
|
165
|
+
if (!isObject(data))
|
|
166
|
+
throw new LiveError(`${where}: a schema output must be an object`);
|
|
167
|
+
let json;
|
|
168
|
+
try {
|
|
169
|
+
json = JSON.parse(JSON.stringify(data));
|
|
170
|
+
} catch (error) {
|
|
171
|
+
throw new LiveError(`${where}: data must be JSON (${messageOf(error)})`, { cause: error });
|
|
172
|
+
}
|
|
173
|
+
const entry = { id: raw.id, data: json };
|
|
174
|
+
if (typeof raw.body === "string") {
|
|
175
|
+
if (!parseMarkdown)
|
|
176
|
+
throw new LiveError(`${where} has a Markdown body, which only the bun preset parses at run time; return a Markdown AST`);
|
|
177
|
+
try {
|
|
178
|
+
entry.body = await parseMarkdown(raw.body);
|
|
179
|
+
} catch (error) {
|
|
180
|
+
throw new LiveError(`${where}: ${messageOf(error)}`, { cause: error });
|
|
181
|
+
}
|
|
182
|
+
} else if (raw.body !== undefined)
|
|
183
|
+
entry.body = raw.body;
|
|
184
|
+
if (raw.cacheHint !== undefined)
|
|
185
|
+
entry.cacheHint = hintOf(raw.cacheHint);
|
|
186
|
+
return entry;
|
|
187
|
+
}
|
|
188
|
+
const failed = (call, definition, error) => error instanceof LiveError ? error : new Error(`${call}: ${definition.loader.name ? `loader ${JSON.stringify(definition.loader.name)}` : "loader"} failed: ${messageOf(error)}`, { cause: error });
|
|
189
|
+
function revive(value, entries) {
|
|
190
|
+
value.cacheHint = hintOf(value.cacheHint);
|
|
191
|
+
for (const entry of entries(value))
|
|
192
|
+
if (entry.cacheHint !== undefined)
|
|
193
|
+
entry.cacheHint = hintOf(entry.cacheHint);
|
|
194
|
+
return value;
|
|
195
|
+
}
|
|
196
|
+
async function cached({
|
|
197
|
+
call,
|
|
198
|
+
name,
|
|
199
|
+
kind,
|
|
200
|
+
filter,
|
|
201
|
+
load,
|
|
202
|
+
entries,
|
|
203
|
+
fail
|
|
204
|
+
}) {
|
|
205
|
+
let key;
|
|
206
|
+
try {
|
|
207
|
+
key = await liveKey(name, kind, filter);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
return fail(new Error(`${call}: ${messageOf(error)}`, { cause: error }));
|
|
210
|
+
}
|
|
211
|
+
await refreshing.get(name)?.catch(() => {});
|
|
212
|
+
try {
|
|
213
|
+
const hit = await storage().getItem(key);
|
|
214
|
+
if (isObject(hit))
|
|
215
|
+
return revive({ ...hit, error: undefined }, entries);
|
|
216
|
+
} catch (error) {
|
|
217
|
+
cacheFailed("reading", error);
|
|
218
|
+
}
|
|
219
|
+
const generation = generationOf(name);
|
|
220
|
+
const result = await load();
|
|
221
|
+
const { maxAge } = result.cacheHint;
|
|
222
|
+
if (result.error !== undefined || maxAge === undefined || !(maxAge > 0) || generation !== generationOf(name))
|
|
223
|
+
return result;
|
|
224
|
+
try {
|
|
225
|
+
const store = storage();
|
|
226
|
+
await store.setItem(key, result, { ttl: maxAge });
|
|
227
|
+
if (generation !== generationOf(name))
|
|
228
|
+
await store.removeItem(key);
|
|
229
|
+
} catch (error) {
|
|
230
|
+
cacheFailed("writing", error);
|
|
231
|
+
}
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
async getLiveCollection(name, filter) {
|
|
236
|
+
const call = `getLiveCollection(${JSON.stringify(name)})`;
|
|
237
|
+
const definition = definitionOf(call, name);
|
|
238
|
+
return cached({
|
|
239
|
+
call,
|
|
240
|
+
name,
|
|
241
|
+
kind: "collection",
|
|
242
|
+
filter,
|
|
243
|
+
async load() {
|
|
244
|
+
try {
|
|
245
|
+
const loaded = await definition.loader.loadCollection(filter);
|
|
246
|
+
if (!isObject(loaded) || !Array.isArray(loaded.entries))
|
|
247
|
+
throw new LiveError(`${call}: loadCollection must return { entries: [...] }`);
|
|
248
|
+
const entries = [];
|
|
249
|
+
for (const raw of loaded.entries)
|
|
250
|
+
entries.push(await entryOf(call, definition, raw));
|
|
251
|
+
return {
|
|
252
|
+
entries,
|
|
253
|
+
error: undefined,
|
|
254
|
+
cacheHint: mergeHints([hintOf(loaded.cacheHint), ...entries.map((entry) => entry.cacheHint)])
|
|
255
|
+
};
|
|
256
|
+
} catch (error) {
|
|
257
|
+
return { entries: undefined, error: failed(call, definition, error), cacheHint: {} };
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
entries: (value) => value.entries ?? [],
|
|
261
|
+
fail: (error) => ({ entries: undefined, error, cacheHint: {} })
|
|
262
|
+
});
|
|
263
|
+
},
|
|
264
|
+
async getLiveEntry(name, filter) {
|
|
265
|
+
const call = `getLiveEntry(${JSON.stringify(name)})`;
|
|
266
|
+
const definition = definitionOf(call, name);
|
|
267
|
+
return cached({
|
|
268
|
+
call,
|
|
269
|
+
name,
|
|
270
|
+
kind: "entry",
|
|
271
|
+
filter,
|
|
272
|
+
async load() {
|
|
273
|
+
try {
|
|
274
|
+
const loaded = await definition.loader.loadEntry(filter);
|
|
275
|
+
if (loaded === undefined || loaded === null)
|
|
276
|
+
return { entry: undefined, error: undefined, cacheHint: {} };
|
|
277
|
+
const entry = await entryOf(call, definition, loaded);
|
|
278
|
+
return { entry, error: undefined, cacheHint: mergeHints([entry.cacheHint]) };
|
|
279
|
+
} catch (error) {
|
|
280
|
+
return { entry: undefined, error: failed(call, definition, error), cacheHint: {} };
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
entries: (value) => value.entry ? [value.entry] : [],
|
|
284
|
+
fail: (error) => ({ entry: undefined, error, cacheHint: {} })
|
|
285
|
+
});
|
|
286
|
+
},
|
|
287
|
+
async refreshContent(options = {}) {
|
|
288
|
+
const requested = options.collections;
|
|
289
|
+
if (requested !== undefined && !(Array.isArray(requested) && requested.every((name) => typeof name === "string")))
|
|
290
|
+
throw new TypeError("refreshContent: collections must be an array of collection names");
|
|
291
|
+
for (const name of requested ?? [])
|
|
292
|
+
if (!names.includes(name))
|
|
293
|
+
throw new TypeError(`refreshContent: ${JSON.stringify(name)} is not a collection of content.config.ts`);
|
|
294
|
+
const live = (requested ?? Object.keys(collections)).filter((name) => Object.hasOwn(collections, name));
|
|
295
|
+
await Promise.all(live.map((name) => {
|
|
296
|
+
generations.set(name, generationOf(name) + 1);
|
|
297
|
+
const done = Promise.resolve().then(() => storage().clear(liveKeyPrefix(name))).finally(() => {
|
|
298
|
+
if (refreshing.get(name) === done)
|
|
299
|
+
refreshing.delete(name);
|
|
300
|
+
});
|
|
301
|
+
refreshing.set(name, done);
|
|
302
|
+
return done;
|
|
303
|
+
}));
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// packages/content/src/server/live.ts
|
|
309
|
+
var hasMarkdown = typeof globalThis.Bun?.markdown !== "undefined";
|
|
310
|
+
var live = createLiveContent({
|
|
311
|
+
collections,
|
|
312
|
+
names,
|
|
313
|
+
storage: () => {
|
|
314
|
+
const cache = useStorage("cache");
|
|
315
|
+
return {
|
|
316
|
+
getItem: (key) => cache.getItem(key),
|
|
317
|
+
setItem: (key, value, options) => cache.setItem(key, value, options),
|
|
318
|
+
removeItem: (key) => cache.removeItem(key),
|
|
319
|
+
clear: (prefix) => cache.clear(prefix)
|
|
320
|
+
};
|
|
321
|
+
},
|
|
322
|
+
warn: (message) => useLogger().child({ name: "content" }).warn(message),
|
|
323
|
+
...hasMarkdown ? {
|
|
324
|
+
parseMarkdown: async (source) => (await (await import("hamur/markdown")).parseMarkdown(source)).ast
|
|
325
|
+
} : {}
|
|
326
|
+
});
|
|
327
|
+
function getLiveCollection(name, filter) {
|
|
328
|
+
return live.getLiveCollection(name, filter);
|
|
329
|
+
}
|
|
330
|
+
function getLiveEntry(name, filter) {
|
|
331
|
+
return live.getLiveEntry(name, filter);
|
|
332
|
+
}
|
|
333
|
+
function refreshContent(options) {
|
|
334
|
+
return live.refreshContent(options);
|
|
335
|
+
}
|
|
336
|
+
export {
|
|
337
|
+
findPageBreadcrumb2 as findPageBreadcrumb,
|
|
338
|
+
findPageChildren2 as findPageChildren,
|
|
339
|
+
findPageHeadline2 as findPageHeadline,
|
|
340
|
+
findPageSiblings2 as findPageSiblings,
|
|
341
|
+
getLiveCollection,
|
|
342
|
+
getLiveEntry,
|
|
343
|
+
queryCollection,
|
|
344
|
+
queryCollectionItemSurroundings,
|
|
345
|
+
queryCollectionNavigation,
|
|
346
|
+
queryCollectionSearchSections,
|
|
347
|
+
refreshContent,
|
|
348
|
+
searchCollection
|
|
349
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { MdRoot } from "hamur/markdown";
|
|
2
|
+
import type { CollectionName } from "../index.ts";
|
|
3
|
+
import type { PageFields } from "../types.ts";
|
|
4
|
+
import { type ContentPage } from "./page.ts";
|
|
5
|
+
import { type SearchHit, type SearchOptions, type SearchStatus, type UseSearchCollectionOptions } from "./search.ts";
|
|
6
|
+
export type { ContentPage, SearchHit, SearchOptions, SearchStatus, UseSearchCollectionOptions };
|
|
7
|
+
export type ProseProps = Record<string, unknown> & {
|
|
8
|
+
children?: string;
|
|
9
|
+
};
|
|
10
|
+
export interface ContentRendererProps {
|
|
11
|
+
/** A page entry, which renders its `body`, or a Markdown AST. */
|
|
12
|
+
value: PageFields | MdRoot;
|
|
13
|
+
/** Markdown components by kebab-case name and prose components by `Prose<Tag>` name, each called with the node's props and `children` as a string; `false` registers none. */
|
|
14
|
+
components?: Record<string, (props: ProseProps) => string> | false;
|
|
15
|
+
/** The wrapper element; `"div"` by default. */
|
|
16
|
+
tag?: string;
|
|
17
|
+
/** Renders the entry's `excerpt` instead of its `body`. */
|
|
18
|
+
excerpt?: boolean;
|
|
19
|
+
/** Space-separated tags whose element is dropped and whose children are kept. */
|
|
20
|
+
unwrap?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const ProseH1: (props: ProseProps) => string;
|
|
23
|
+
export declare const ProseH2: (props: ProseProps) => string;
|
|
24
|
+
export declare const ProseH3: (props: ProseProps) => string;
|
|
25
|
+
export declare const ProseH4: (props: ProseProps) => string;
|
|
26
|
+
export declare const ProseH5: (props: ProseProps) => string;
|
|
27
|
+
export declare const ProseH6: (props: ProseProps) => string;
|
|
28
|
+
export declare const ProseP: (props: ProseProps) => string;
|
|
29
|
+
export declare const ProseUl: (props: ProseProps) => string;
|
|
30
|
+
export declare const ProseOl: (props: ProseProps) => string;
|
|
31
|
+
export declare const ProseLi: (props: ProseProps) => string;
|
|
32
|
+
export declare const ProseBlockquote: (props: ProseProps) => string;
|
|
33
|
+
export declare const ProseCode: (props: ProseProps) => string;
|
|
34
|
+
export declare const ProseImg: (props: ProseProps) => string;
|
|
35
|
+
export declare const ProseTable: (props: ProseProps) => string;
|
|
36
|
+
export declare const ProseHr: (props: ProseProps) => string;
|
|
37
|
+
export declare const ProseStrong: (props: ProseProps) => string;
|
|
38
|
+
export declare const ProseEm: (props: ProseProps) => string;
|
|
39
|
+
/** An internal `href` is a `Link`, as `MarkdownRenderer` writes it. */
|
|
40
|
+
export declare function ProseA({ href, ...rest }: ProseProps): string;
|
|
41
|
+
export declare function ProsePre({ language: _language, highlights: _highlights, code: _code, filename, ...rest }: ProseProps): string;
|
|
42
|
+
/** A page entry's body, or a Markdown AST, through `MarkdownRenderer` with the prose components of `components`. */
|
|
43
|
+
export declare function ContentRenderer({ value, components, tag, excerpt, unwrap }: ContentRendererProps): string;
|
|
44
|
+
export interface UseSearchCollectionResult {
|
|
45
|
+
readonly status: SearchStatus;
|
|
46
|
+
/** Calls `listener` with the new status on each change; returns the function that stops it. */
|
|
47
|
+
onStatus(listener: (status: SearchStatus) => void): () => void;
|
|
48
|
+
search(query: string, options?: SearchOptions): Promise<SearchHit[]>;
|
|
49
|
+
init(): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
/** The collection's search index, loaded on the first `search()` or `init()`, or at once in the browser with `immediate`; `status` is a getter. */
|
|
52
|
+
export declare function useSearchCollection(name: string, { immediate }?: UseSearchCollectionOptions): UseSearchCollectionResult;
|
|
53
|
+
/** The entry of `collection` whose `path` is the route path, `undefined` while it loads; throws the 404 when there is none. */
|
|
54
|
+
export declare function useContentPage<N extends CollectionName>(collection: N): ContentPage<N> | undefined;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type HamurError, type HeadInput, type SeoMetaInput } from "hamur/app";
|
|
2
|
+
import type { CollectionItem } from "../index.ts";
|
|
3
|
+
import type { PageEntry, PageFields } from "../types.ts";
|
|
4
|
+
/** What `useContentPage(N)` finds: the page fields of the collection's item type, `PageEntry` while typegen has written none. */
|
|
5
|
+
export type ContentPage<N extends string> = Extract<CollectionItem<N>, PageFields>;
|
|
6
|
+
export declare const pageKey: (collection: string, path: string) => string;
|
|
7
|
+
/** A data collection has no paths. */
|
|
8
|
+
export declare function checkPageCollection(collection: string): void;
|
|
9
|
+
/** The entry of `collection` whose `path` is `path`; `null` (a value the payload keeps) when there is none. */
|
|
10
|
+
export declare function loadPage(collection: string, path: string): Promise<PageEntry | null>;
|
|
11
|
+
/** The entry's `seo` with `title` and `description` from the entry when `seo` has none. */
|
|
12
|
+
export declare function pageSeo(entry: PageFields | null | undefined): SeoMetaInput;
|
|
13
|
+
/** The head `link` to the page's Markdown copy; none unless `content.raw` is on. */
|
|
14
|
+
export declare function pageHead(entry: PageFields | null | undefined): HeadInput;
|
|
15
|
+
export interface PageRead {
|
|
16
|
+
data: PageEntry | null | undefined;
|
|
17
|
+
error: HamurError | undefined;
|
|
18
|
+
status: string;
|
|
19
|
+
}
|
|
20
|
+
/** The entry of a settled read; a failed read throws its error and a settled read without an entry the 404. `undefined` while the entry loads. */
|
|
21
|
+
export declare function settledPage(path: string, { data, error, status }: PageRead): PageEntry | undefined;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type ComponentChildren, type ComponentType, type VNode } from "preact";
|
|
2
|
+
import type { MdRoot } from "hamur/markdown";
|
|
3
|
+
import type { CollectionName } from "../index.ts";
|
|
4
|
+
import type { PageFields } from "../types.ts";
|
|
5
|
+
import { type ContentPage } from "./page.ts";
|
|
6
|
+
import { type SearchHit, type SearchOptions, type SearchStatus, type UseSearchCollectionOptions } from "./search.ts";
|
|
7
|
+
export type { ContentPage, SearchHit, SearchOptions, SearchStatus, UseSearchCollectionOptions };
|
|
8
|
+
export interface ContentRendererProps {
|
|
9
|
+
/** A page entry, which renders its `body`, or a Markdown AST. */
|
|
10
|
+
value: PageFields | MdRoot;
|
|
11
|
+
/** Markdown components by kebab-case name and prose components by `Prose<Tag>` name; `false` registers none. */
|
|
12
|
+
components?: Record<string, ComponentType<any>> | false;
|
|
13
|
+
/** The wrapper element; `"div"` by default. */
|
|
14
|
+
tag?: string;
|
|
15
|
+
/** Renders the entry's `excerpt` instead of its `body`. */
|
|
16
|
+
excerpt?: boolean;
|
|
17
|
+
/** Space-separated tags whose element is dropped and whose children are kept. */
|
|
18
|
+
unwrap?: string;
|
|
19
|
+
}
|
|
20
|
+
export type ProseProps = Record<string, unknown> & {
|
|
21
|
+
children?: ComponentChildren;
|
|
22
|
+
};
|
|
23
|
+
export declare const ProseH1: (props: ProseProps) => VNode;
|
|
24
|
+
export declare const ProseH2: (props: ProseProps) => VNode;
|
|
25
|
+
export declare const ProseH3: (props: ProseProps) => VNode;
|
|
26
|
+
export declare const ProseH4: (props: ProseProps) => VNode;
|
|
27
|
+
export declare const ProseH5: (props: ProseProps) => VNode;
|
|
28
|
+
export declare const ProseH6: (props: ProseProps) => VNode;
|
|
29
|
+
export declare const ProseP: (props: ProseProps) => VNode;
|
|
30
|
+
export declare const ProseUl: (props: ProseProps) => VNode;
|
|
31
|
+
export declare const ProseOl: (props: ProseProps) => VNode;
|
|
32
|
+
export declare const ProseLi: (props: ProseProps) => VNode;
|
|
33
|
+
export declare const ProseBlockquote: (props: ProseProps) => VNode;
|
|
34
|
+
export declare const ProseCode: (props: ProseProps) => VNode;
|
|
35
|
+
export declare const ProseImg: (props: ProseProps) => VNode;
|
|
36
|
+
export declare const ProseTable: (props: ProseProps) => VNode;
|
|
37
|
+
export declare const ProseHr: (props: ProseProps) => VNode;
|
|
38
|
+
export declare const ProseStrong: (props: ProseProps) => VNode;
|
|
39
|
+
export declare const ProseEm: (props: ProseProps) => VNode;
|
|
40
|
+
/** An internal `href` is a `Link`, as `MarkdownRenderer` writes it. */
|
|
41
|
+
export declare function ProseA({ href, ...rest }: ProseProps): VNode;
|
|
42
|
+
export declare function ProsePre({ language: _language, highlights: _highlights, code: _code, filename, ...rest }: ProseProps): VNode;
|
|
43
|
+
/** A page entry's body, or a Markdown AST, through `MarkdownRenderer` with the prose components of `components`. */
|
|
44
|
+
export declare function ContentRenderer({ value, components, tag, excerpt, unwrap, }: ContentRendererProps): VNode | null;
|
|
45
|
+
export interface UseSearchCollectionResult {
|
|
46
|
+
status: SearchStatus;
|
|
47
|
+
search(query: string, options?: SearchOptions): Promise<SearchHit[]>;
|
|
48
|
+
init(): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
/** The collection's search index, loaded on the first `search()` or `init()`, or at mount with `immediate`; `status` is state. */
|
|
51
|
+
export declare function useSearchCollection(name: string, { immediate }?: UseSearchCollectionOptions): UseSearchCollectionResult;
|
|
52
|
+
/** The entry of `collection` whose `path` is the route path, `undefined` while it loads; throws the 404 when there is none. */
|
|
53
|
+
export declare function useContentPage<N extends CollectionName>(collection: N): ContentPage<N> | undefined;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { MdRoot } from "hamur/markdown";
|
|
2
|
+
import type { PageFields } from "../types.ts";
|
|
3
|
+
/** An `href` that is an app path (`/…`, not `//…`), which `MarkdownRenderer` writes as `Link`. */
|
|
4
|
+
export declare const isInternal: (href: unknown) => href is string;
|
|
5
|
+
export interface PrepareOptions<Component> {
|
|
6
|
+
value: PageFields | MdRoot | undefined;
|
|
7
|
+
components: Record<string, Component> | false | undefined;
|
|
8
|
+
/** The default prose component of each tag (`a`, `h1`, …); the app's `Prose<Tag>` file and a `Prose<Tag>` in `components` win, in that order. */
|
|
9
|
+
defaults: Readonly<Record<string, Component>>;
|
|
10
|
+
excerpt: boolean | undefined;
|
|
11
|
+
unwrap: string | undefined;
|
|
12
|
+
/** Prop names a library spells differently from the attribute (`class` → `className`). */
|
|
13
|
+
rename?: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
export interface Prepared<Component> {
|
|
16
|
+
root: MdRoot;
|
|
17
|
+
/** `components` for `MarkdownRenderer`: the Markdown components, and each prose component under its tag's key. */
|
|
18
|
+
components: Record<string, Component>;
|
|
19
|
+
}
|
|
20
|
+
/** What `ContentRenderer` hands to `MarkdownRenderer`; undefined when there is nothing to render. */
|
|
21
|
+
export declare function prepare<Component>({ value, components, defaults, excerpt, unwrap, rename, }: PrepareOptions<Component>): Prepared<Component> | undefined;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type ComponentType, type ReactNode } from "react";
|
|
2
|
+
import type { MdRoot } from "hamur/markdown";
|
|
3
|
+
import type { CollectionName } from "../index.ts";
|
|
4
|
+
import type { PageFields } from "../types.ts";
|
|
5
|
+
import { type ContentPage } from "./page.ts";
|
|
6
|
+
import { type SearchHit, type SearchOptions, type SearchStatus, type UseSearchCollectionOptions } from "./search.ts";
|
|
7
|
+
export type { ContentPage, SearchHit, SearchOptions, SearchStatus, UseSearchCollectionOptions };
|
|
8
|
+
export interface ContentRendererProps {
|
|
9
|
+
/** A page entry, which renders its `body`, or a Markdown AST. */
|
|
10
|
+
value: PageFields | MdRoot;
|
|
11
|
+
/** Markdown components by kebab-case name and prose components by `Prose<Tag>` name; `false` registers none. */
|
|
12
|
+
components?: Record<string, ComponentType<any>> | false;
|
|
13
|
+
/** The wrapper element; `"div"` by default. */
|
|
14
|
+
tag?: string;
|
|
15
|
+
/** Renders the entry's `excerpt` instead of its `body`. */
|
|
16
|
+
excerpt?: boolean;
|
|
17
|
+
/** Space-separated tags whose element is dropped and whose children are kept. */
|
|
18
|
+
unwrap?: string;
|
|
19
|
+
}
|
|
20
|
+
export type ProseProps = Record<string, unknown> & {
|
|
21
|
+
children?: ReactNode;
|
|
22
|
+
};
|
|
23
|
+
export declare const ProseH1: (props: ProseProps) => ReactNode;
|
|
24
|
+
export declare const ProseH2: (props: ProseProps) => ReactNode;
|
|
25
|
+
export declare const ProseH3: (props: ProseProps) => ReactNode;
|
|
26
|
+
export declare const ProseH4: (props: ProseProps) => ReactNode;
|
|
27
|
+
export declare const ProseH5: (props: ProseProps) => ReactNode;
|
|
28
|
+
export declare const ProseH6: (props: ProseProps) => ReactNode;
|
|
29
|
+
export declare const ProseP: (props: ProseProps) => ReactNode;
|
|
30
|
+
export declare const ProseUl: (props: ProseProps) => ReactNode;
|
|
31
|
+
export declare const ProseOl: (props: ProseProps) => ReactNode;
|
|
32
|
+
export declare const ProseLi: (props: ProseProps) => ReactNode;
|
|
33
|
+
export declare const ProseBlockquote: (props: ProseProps) => ReactNode;
|
|
34
|
+
export declare const ProseCode: (props: ProseProps) => ReactNode;
|
|
35
|
+
export declare const ProseImg: (props: ProseProps) => ReactNode;
|
|
36
|
+
export declare const ProseTable: (props: ProseProps) => ReactNode;
|
|
37
|
+
export declare const ProseHr: (props: ProseProps) => ReactNode;
|
|
38
|
+
export declare const ProseStrong: (props: ProseProps) => ReactNode;
|
|
39
|
+
export declare const ProseEm: (props: ProseProps) => ReactNode;
|
|
40
|
+
/** An internal `href` is a `Link`, as `MarkdownRenderer` writes it. */
|
|
41
|
+
export declare function ProseA({ href, ...rest }: ProseProps): ReactNode;
|
|
42
|
+
export declare function ProsePre({ language: _language, highlights: _highlights, code: _code, filename, ...rest }: ProseProps): ReactNode;
|
|
43
|
+
/** A page entry's body, or a Markdown AST, through `MarkdownRenderer` with the prose components of `components`. */
|
|
44
|
+
export declare function ContentRenderer({ value, components, tag, excerpt, unwrap }: ContentRendererProps): ReactNode;
|
|
45
|
+
export interface UseSearchCollectionResult {
|
|
46
|
+
status: SearchStatus;
|
|
47
|
+
search(query: string, options?: SearchOptions): Promise<SearchHit[]>;
|
|
48
|
+
init(): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
/** The collection's search index, loaded on the first `search()` or `init()`, or at mount with `immediate`; `status` is state. */
|
|
51
|
+
export declare function useSearchCollection(name: string, { immediate }?: UseSearchCollectionOptions): UseSearchCollectionResult;
|
|
52
|
+
/** The entry of `collection` whose `path` is the route path, suspending until it loads; throws the 404 when there is none. */
|
|
53
|
+
export declare function useContentPage<N extends CollectionName>(collection: N): ContentPage<N>;
|