@glw907/cairn-cms 0.17.0 → 0.18.0
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/dist/components/EditPage.svelte +9 -2
- package/dist/components/EditPage.svelte.d.ts +2 -0
- package/dist/components/EditPage.svelte.d.ts.map +1 -1
- package/dist/content/compose.d.ts.map +1 -1
- package/dist/content/compose.js +1 -0
- package/dist/content/links.d.ts +14 -0
- package/dist/content/links.d.ts.map +1 -0
- package/dist/content/links.js +41 -0
- package/dist/content/manifest.d.ts +55 -0
- package/dist/content/manifest.d.ts.map +1 -0
- package/dist/content/manifest.js +98 -0
- package/dist/content/types.d.ts +10 -1
- package/dist/content/types.d.ts.map +1 -1
- package/dist/delivery/index.d.ts +1 -0
- package/dist/delivery/index.d.ts.map +1 -1
- package/dist/delivery/index.js +1 -0
- package/dist/delivery/manifest.d.ts +13 -0
- package/dist/delivery/manifest.d.ts.map +1 -0
- package/dist/delivery/manifest.js +31 -0
- package/dist/github/repo.d.ts +21 -0
- package/dist/github/repo.d.ts.map +1 -1
- package/dist/github/repo.js +79 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/render/pipeline.d.ts +4 -1
- package/dist/render/pipeline.d.ts.map +1 -1
- package/dist/render/pipeline.js +7 -2
- package/dist/render/resolve-links.d.ts +8 -0
- package/dist/render/resolve-links.d.ts.map +1 -0
- package/dist/render/resolve-links.js +36 -0
- package/dist/render/sanitize-schema.d.ts.map +1 -1
- package/dist/render/sanitize-schema.js +9 -0
- package/dist/sveltekit/content-routes.d.ts +3 -0
- package/dist/sveltekit/content-routes.d.ts.map +1 -1
- package/dist/sveltekit/content-routes.js +29 -2
- package/dist/sveltekit/public-routes.d.ts +2 -0
- package/dist/sveltekit/public-routes.d.ts.map +1 -1
- package/dist/sveltekit/public-routes.js +2 -1
- package/package.json +1 -1
- package/src/lib/components/EditPage.svelte +9 -2
- package/src/lib/content/compose.ts +1 -0
- package/src/lib/content/links.ts +48 -0
- package/src/lib/content/manifest.ts +138 -0
- package/src/lib/content/types.ts +10 -3
- package/src/lib/delivery/index.ts +1 -0
- package/src/lib/delivery/manifest.ts +38 -0
- package/src/lib/github/repo.ts +103 -0
- package/src/lib/index.ts +16 -0
- package/src/lib/render/pipeline.ts +8 -2
- package/src/lib/render/resolve-links.ts +42 -0
- package/src/lib/render/sanitize-schema.ts +9 -0
- package/src/lib/sveltekit/content-routes.ts +36 -4
- package/src/lib/sveltekit/public-routes.ts +4 -2
package/src/lib/github/repo.ts
CHANGED
|
@@ -136,3 +136,106 @@ export async function commitFile(
|
|
|
136
136
|
if (!res.ok) throw new Error(`GitHub commit ${path} failed: ${res.status} ${await res.text()}`);
|
|
137
137
|
return ((await res.json()) as { commit: { sha: string } }).commit.sha;
|
|
138
138
|
}
|
|
139
|
+
|
|
140
|
+
/** A path change for an atomic commit: write `content`, or delete the path when `content` is null. */
|
|
141
|
+
export interface FileChange {
|
|
142
|
+
path: string;
|
|
143
|
+
content: string | null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** A Git Trees API change entry: a blob written from raw content, or a `sha: null` delete. */
|
|
147
|
+
interface TreeChange {
|
|
148
|
+
path: string;
|
|
149
|
+
mode: '100644';
|
|
150
|
+
type: 'blob';
|
|
151
|
+
content?: string;
|
|
152
|
+
sha?: null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** A Git Data API URL under the repo's `git/` namespace. */
|
|
156
|
+
function gitUrl(repo: RepoRef, suffix: string): string {
|
|
157
|
+
return `${API}/repos/${repo.owner}/${repo.repo}/git/${suffix}`;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The branch head commit sha, through the Git Data API single-ref read. */
|
|
161
|
+
async function headCommitSha(repo: RepoRef, token: string): Promise<string> {
|
|
162
|
+
const res = await fetch(gitUrl(repo, `ref/heads/${encodeURIComponent(repo.branch)}`), {
|
|
163
|
+
headers: ghHeaders('application/vnd.github+json', token),
|
|
164
|
+
});
|
|
165
|
+
if (!res.ok) throw new Error(`GitHub ref ${repo.branch} failed: ${res.status}`);
|
|
166
|
+
return ((await res.json()) as { object: { sha: string } }).object.sha;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The base tree sha of a commit. */
|
|
170
|
+
async function commitTreeSha(repo: RepoRef, commitSha: string, token: string): Promise<string> {
|
|
171
|
+
const res = await fetch(gitUrl(repo, `commits/${commitSha}`), {
|
|
172
|
+
headers: ghHeaders('application/vnd.github+json', token),
|
|
173
|
+
});
|
|
174
|
+
if (!res.ok) throw new Error(`GitHub commit ${commitSha} failed: ${res.status}`);
|
|
175
|
+
return ((await res.json()) as { tree: { sha: string } }).tree.sha;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Map file changes to Git Trees API entries, encoding a null content as a delete. */
|
|
179
|
+
function treeChanges(changes: FileChange[]): TreeChange[] {
|
|
180
|
+
return changes.map((c) =>
|
|
181
|
+
c.content === null
|
|
182
|
+
? { path: c.path, mode: '100644', type: 'blob', sha: null }
|
|
183
|
+
: { path: c.path, mode: '100644', type: 'blob', content: c.content },
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Retries after the initial attempt when the branch moves under an atomic commit. */
|
|
188
|
+
const COMMIT_RETRIES = 3;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Commit several path changes in one commit over the Git Data API. The author is the editor; the
|
|
192
|
+
* committer is omitted, so GitHub attributes the commit to the App. Returns the new commit sha.
|
|
193
|
+
* Builds the new tree on the current head's tree, so paths not named here are preserved.
|
|
194
|
+
*
|
|
195
|
+
* Caller preconditions this layer cannot enforce (the save and lifecycle paths must): every
|
|
196
|
+
* `path` is confined to the site's content directories (the App token can write anywhere in the
|
|
197
|
+
* repo), and `author` is derived from the verified server-side session, never request input.
|
|
198
|
+
*
|
|
199
|
+
* An empty change set is rejected, since it would otherwise push an empty commit that triggers a
|
|
200
|
+
* site redeploy for no content change.
|
|
201
|
+
*/
|
|
202
|
+
export async function commitFiles(
|
|
203
|
+
repo: RepoRef,
|
|
204
|
+
changes: FileChange[],
|
|
205
|
+
opts: { message: string; author: CommitAuthor },
|
|
206
|
+
token: string,
|
|
207
|
+
): Promise<string> {
|
|
208
|
+
if (changes.length === 0) throw new Error('commitFiles: no changes to commit');
|
|
209
|
+
const tree = treeChanges(changes);
|
|
210
|
+
for (let attempt = 0; attempt <= COMMIT_RETRIES; attempt++) {
|
|
211
|
+
const parent = await headCommitSha(repo, token);
|
|
212
|
+
const baseTree = await commitTreeSha(repo, parent, token);
|
|
213
|
+
|
|
214
|
+
const treeRes = await fetch(gitUrl(repo, 'trees'), {
|
|
215
|
+
method: 'POST',
|
|
216
|
+
headers: { ...ghHeaders('application/vnd.github+json', token), 'Content-Type': 'application/json' },
|
|
217
|
+
body: JSON.stringify({ base_tree: baseTree, tree }),
|
|
218
|
+
});
|
|
219
|
+
if (!treeRes.ok) throw new Error(`GitHub tree create failed: ${treeRes.status} ${await treeRes.text()}`);
|
|
220
|
+
const newTree = ((await treeRes.json()) as { sha: string }).sha;
|
|
221
|
+
|
|
222
|
+
const commitRes = await fetch(gitUrl(repo, 'commits'), {
|
|
223
|
+
method: 'POST',
|
|
224
|
+
headers: { ...ghHeaders('application/vnd.github+json', token), 'Content-Type': 'application/json' },
|
|
225
|
+
body: JSON.stringify({ message: opts.message, tree: newTree, parents: [parent], author: opts.author }),
|
|
226
|
+
});
|
|
227
|
+
if (!commitRes.ok) throw new Error(`GitHub commit create failed: ${commitRes.status} ${await commitRes.text()}`);
|
|
228
|
+
const newCommit = ((await commitRes.json()) as { sha: string }).sha;
|
|
229
|
+
|
|
230
|
+
const refRes = await fetch(gitUrl(repo, `refs/heads/${encodeURIComponent(repo.branch)}`), {
|
|
231
|
+
method: 'PATCH',
|
|
232
|
+
headers: { ...ghHeaders('application/vnd.github+json', token), 'Content-Type': 'application/json' },
|
|
233
|
+
body: JSON.stringify({ sha: newCommit, force: false }),
|
|
234
|
+
});
|
|
235
|
+
if (refRes.ok) return newCommit;
|
|
236
|
+
// A non-fast-forward means the branch moved; retry on the new head so a concurrent commit
|
|
237
|
+
// is preserved. Any other failure is not a race, so surface it.
|
|
238
|
+
if (refRes.status !== 422) throw new Error(`GitHub ref update failed: ${refRes.status} ${await refRes.text()}`);
|
|
239
|
+
}
|
|
240
|
+
throw new CommitConflictError(`${repo.branch} (atomic commit)`);
|
|
241
|
+
}
|
package/src/lib/index.ts
CHANGED
|
@@ -49,6 +49,22 @@ export {
|
|
|
49
49
|
composeDatedId,
|
|
50
50
|
} from './content/ids.js';
|
|
51
51
|
export type { DatePrefix } from './content/ids.js';
|
|
52
|
+
// Internal-link token and the committed content manifest (content-graph design). The corpus
|
|
53
|
+
// builder and the request-time resolver ship from the delivery entry; this surface is the
|
|
54
|
+
// grammar, the manifest operations, and their types a migrating site adopts.
|
|
55
|
+
export { parseCairnToken, extractCairnLinks } from './content/links.js';
|
|
56
|
+
export type { CairnRef, LinkResolve } from './content/links.js';
|
|
57
|
+
export {
|
|
58
|
+
serializeManifest,
|
|
59
|
+
parseManifest,
|
|
60
|
+
emptyManifest,
|
|
61
|
+
verifyManifest,
|
|
62
|
+
upsertEntry,
|
|
63
|
+
removeEntry,
|
|
64
|
+
manifestEntryFromFile,
|
|
65
|
+
manifestLinkResolver,
|
|
66
|
+
} from './content/manifest.js';
|
|
67
|
+
export type { Manifest, ManifestEntry, LinkTarget } from './content/manifest.js';
|
|
52
68
|
// Render engine (Plan 04): generic directive pipeline; sites own the component registry.
|
|
53
69
|
export { defineRegistry, emptyValues } from './render/registry.js';
|
|
54
70
|
export type {
|
|
@@ -8,10 +8,13 @@ import rehypeSlug from 'rehype-slug';
|
|
|
8
8
|
import rehypeStringify from 'rehype-stringify';
|
|
9
9
|
import rehypeSanitize from 'rehype-sanitize';
|
|
10
10
|
import type { Schema } from 'hast-util-sanitize';
|
|
11
|
+
import { VFile } from 'vfile';
|
|
11
12
|
import { buildSanitizeSchema, rehypeAnchorRel } from './sanitize-schema.js';
|
|
12
13
|
import { remarkDirectiveStamp } from './remark-directives.js';
|
|
14
|
+
import { remarkResolveCairnLinks, CAIRN_RESOLVE } from './resolve-links.js';
|
|
13
15
|
import { rehypeDispatch } from './rehype-dispatch.js';
|
|
14
16
|
import type { ComponentRegistry } from './registry.js';
|
|
17
|
+
import type { LinkResolve } from '../content/links.js';
|
|
15
18
|
|
|
16
19
|
export interface RendererOptions {
|
|
17
20
|
/** Stamp a `data-rise` ordinal (0, 1, 2, …) on each top-level component so a site's
|
|
@@ -33,7 +36,7 @@ export interface RendererOptions {
|
|
|
33
36
|
* stamped markers to registry-built hast. Returns `renderMarkdown` plus the remark/
|
|
34
37
|
* rehype plugin arrays (so the admin editor preview can reuse the exact same set). */
|
|
35
38
|
export function createRenderer(registry: ComponentRegistry, options: RendererOptions = {}) {
|
|
36
|
-
const remarkPlugins: PluggableList = [remarkDirective, [remarkDirectiveStamp, registry]];
|
|
39
|
+
const remarkPlugins: PluggableList = [remarkDirective, [remarkDirectiveStamp, registry], remarkResolveCairnLinks];
|
|
37
40
|
// The sanitize floor runs after rehype-raw (so author raw HTML is parsed, then cleaned) and
|
|
38
41
|
// before the dispatch (so the site's trusted build() output and its inline SVG icons are never
|
|
39
42
|
// sanitized). The anchor-rel hardening runs last so it also covers component-built anchors.
|
|
@@ -57,6 +60,9 @@ export function createRenderer(registry: ComponentRegistry, options: RendererOpt
|
|
|
57
60
|
return {
|
|
58
61
|
remarkPlugins,
|
|
59
62
|
rehypePlugins,
|
|
60
|
-
renderMarkdown: async (content: string): Promise<string> =>
|
|
63
|
+
renderMarkdown: async (content: string, opts: { resolve?: LinkResolve } = {}): Promise<string> => {
|
|
64
|
+
const file = new VFile({ value: content, data: { [CAIRN_RESOLVE]: opts.resolve } });
|
|
65
|
+
return String(await processor.process(file));
|
|
66
|
+
},
|
|
61
67
|
};
|
|
62
68
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// cairn-cms: the cairn: link resolver, an mdast step in the render pipeline (content-graph design).
|
|
2
|
+
// It runs before remark-rehype, so the rewritten href passes through the sanitize floor exactly as
|
|
3
|
+
// any other anchor. The per-call resolver is read off the VFile (set by renderMarkdown), so the
|
|
4
|
+
// processor is still built once. A miss either marks the link broken (preview) or throws (build),
|
|
5
|
+
// decided by the injected resolver.
|
|
6
|
+
import { visit } from 'unist-util-visit';
|
|
7
|
+
import type { VFile } from 'vfile';
|
|
8
|
+
import { parseCairnToken, type LinkResolve } from '../content/links.js';
|
|
9
|
+
|
|
10
|
+
/** The VFile data key the renderer sets the per-call resolver under. */
|
|
11
|
+
export const CAIRN_RESOLVE = 'cairnResolve';
|
|
12
|
+
|
|
13
|
+
interface LinkNode {
|
|
14
|
+
url: string;
|
|
15
|
+
data?: { hProperties?: Record<string, unknown> };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Resolve cairn: link nodes against the VFile's resolver. A non-cairn href and a malformed token
|
|
19
|
+
* pass through. A missing target is marked with the cairn-broken-link class (the resolver returns
|
|
20
|
+
* undefined) or, when the resolver throws, the error propagates and fails the build. */
|
|
21
|
+
export function remarkResolveCairnLinks() {
|
|
22
|
+
return (tree: unknown, file: VFile): void => {
|
|
23
|
+
const resolve = file.data[CAIRN_RESOLVE] as LinkResolve | undefined;
|
|
24
|
+
if (!resolve) return;
|
|
25
|
+
visit(tree as Parameters<typeof visit>[0], 'link', (node: LinkNode) => {
|
|
26
|
+
const ref = parseCairnToken(node.url);
|
|
27
|
+
if (!ref) return;
|
|
28
|
+
const url = resolve(ref); // may throw (build backstop); propagates out of render
|
|
29
|
+
if (url) {
|
|
30
|
+
node.url = url;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
// Missing target in the preview: mark it broken and neutralize the href, keeping the text.
|
|
34
|
+
node.url = '#';
|
|
35
|
+
node.data = node.data ?? {};
|
|
36
|
+
const props = (node.data.hProperties = node.data.hProperties ?? {});
|
|
37
|
+
const existing = Array.isArray(props.className) ? (props.className as string[]) : [];
|
|
38
|
+
props.className = [...existing, 'cairn-broken-link'];
|
|
39
|
+
props.title = 'Broken internal link';
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -29,6 +29,11 @@ export function buildSanitizeSchema(
|
|
|
29
29
|
const anchorAttrs = (attributes.a ?? []).filter(
|
|
30
30
|
(entry) => !(Array.isArray(entry) && entry[0] === 'className'),
|
|
31
31
|
);
|
|
32
|
+
// Admit the inert `cairn:` href scheme on top of the default protocol allowlist. The render
|
|
33
|
+
// resolver rewrites a `cairn:` link to a live permalink before delivery; an unresolved one
|
|
34
|
+
// survives the floor in its inert token form (a visible unresolved-link signal), never as an
|
|
35
|
+
// executable vector. The dangerous-protocol strip (javascript:, data:) is preserved.
|
|
36
|
+
const protocols = defaultSchema.protocols ?? {};
|
|
32
37
|
const schema: Schema = {
|
|
33
38
|
...defaultSchema,
|
|
34
39
|
tagNames: [...(defaultSchema.tagNames ?? []), 'nav', 'details', 'summary'],
|
|
@@ -37,6 +42,10 @@ export function buildSanitizeSchema(
|
|
|
37
42
|
'*': [...(attributes['*'] ?? []), 'className', ...markers],
|
|
38
43
|
a: [...anchorAttrs, 'className', 'target', 'rel'],
|
|
39
44
|
},
|
|
45
|
+
protocols: {
|
|
46
|
+
...protocols,
|
|
47
|
+
href: [...(protocols.href ?? []), 'cairn'],
|
|
48
|
+
},
|
|
40
49
|
};
|
|
41
50
|
return extend ? extend(schema) : schema;
|
|
42
51
|
}
|
|
@@ -7,8 +7,9 @@ import { findConcept } from '../content/concepts.js';
|
|
|
7
7
|
import { frontmatterFromForm, parseMarkdown, dateInputValue, serializeMarkdown } from '../content/frontmatter.js';
|
|
8
8
|
import { isValidId, slugify, filenameFromId, composeDatedId } from '../content/ids.js';
|
|
9
9
|
import { appCredentials, type GithubKeyEnv } from '../github/credentials.js';
|
|
10
|
-
import { listMarkdown, readRaw,
|
|
10
|
+
import { listMarkdown, readRaw, commitFiles } from '../github/repo.js';
|
|
11
11
|
import { cachedInstallationToken } from '../github/signing.js';
|
|
12
|
+
import { emptyManifest, manifestEntryFromFile, parseManifest, serializeManifest, upsertEntry, type LinkTarget } from '../content/manifest.js';
|
|
12
13
|
import { CommitConflictError } from '../github/types.js';
|
|
13
14
|
import type { CairnRuntime, ConceptDescriptor, FrontmatterField } from '../content/types.js';
|
|
14
15
|
import type { Editor, Role } from '../auth/types.js';
|
|
@@ -63,6 +64,8 @@ export interface EditData {
|
|
|
63
64
|
isNew: boolean;
|
|
64
65
|
saved: boolean;
|
|
65
66
|
error: string | null;
|
|
67
|
+
/** The site's link targets, for the preview resolver and the link picker; from the committed manifest. */
|
|
68
|
+
linkTargets: LinkTarget[];
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
/** The structural event the content routes read; a real SvelteKit RequestEvent satisfies it. */
|
|
@@ -207,6 +210,20 @@ export function createContentRoutes(runtime: CairnRuntime, deps: ContentRoutesDe
|
|
|
207
210
|
|
|
208
211
|
const parsed = raw === null ? { frontmatter: {}, body: '' } : parseMarkdown(raw);
|
|
209
212
|
const title = typeof parsed.frontmatter.title === 'string' && parsed.frontmatter.title.trim() ? parsed.frontmatter.title : id;
|
|
213
|
+
|
|
214
|
+
let linkTargets: LinkTarget[] = [];
|
|
215
|
+
const manifestRaw = await readRaw(runtime.backend, runtime.manifestPath, token);
|
|
216
|
+
if (manifestRaw !== null) {
|
|
217
|
+
linkTargets = parseManifest(manifestRaw).entries.map((e) => ({
|
|
218
|
+
concept: e.concept,
|
|
219
|
+
id: e.id,
|
|
220
|
+
permalink: e.permalink,
|
|
221
|
+
title: e.title,
|
|
222
|
+
date: e.date,
|
|
223
|
+
draft: e.draft,
|
|
224
|
+
}));
|
|
225
|
+
}
|
|
226
|
+
|
|
210
227
|
return {
|
|
211
228
|
conceptId: concept.id,
|
|
212
229
|
id,
|
|
@@ -218,6 +235,7 @@ export function createContentRoutes(runtime: CairnRuntime, deps: ContentRoutesDe
|
|
|
218
235
|
isNew,
|
|
219
236
|
saved: event.url.searchParams.get('saved') === '1',
|
|
220
237
|
error: event.url.searchParams.get('error'),
|
|
238
|
+
linkTargets,
|
|
221
239
|
};
|
|
222
240
|
}
|
|
223
241
|
|
|
@@ -249,11 +267,25 @@ export function createContentRoutes(runtime: CairnRuntime, deps: ContentRoutesDe
|
|
|
249
267
|
|
|
250
268
|
const markdown = serializeMarkdown(result.data, body);
|
|
251
269
|
const token = await mintToken(event.platform?.env ?? {});
|
|
270
|
+
|
|
271
|
+
// Read the committed manifest, upsert this entry's row, and commit content and manifest in one
|
|
272
|
+
// commit. A missing manifest starts empty (first save on a fresh repo). The build regenerates
|
|
273
|
+
// and verifies the manifest, so this incremental patch is the cheap request-time path. On a
|
|
274
|
+
// 422 retry commitFiles re-sends this manifest blob last-writer-wins. A concurrent save can then
|
|
275
|
+
// leave the committed manifest stale, which the next build rejects via verifyManifest; regenerate
|
|
276
|
+
// it with npm run cairn:manifest to recover.
|
|
277
|
+
const manifestRaw = await readRaw(runtime.backend, runtime.manifestPath, token);
|
|
278
|
+
const manifest = manifestRaw === null ? emptyManifest() : parseManifest(manifestRaw);
|
|
279
|
+
const row = manifestEntryFromFile(concept, { path, raw: markdown });
|
|
280
|
+
const nextManifest = serializeManifest(upsertEntry(manifest, row));
|
|
281
|
+
|
|
252
282
|
try {
|
|
253
|
-
await
|
|
283
|
+
await commitFiles(
|
|
254
284
|
runtime.backend,
|
|
255
|
-
|
|
256
|
-
|
|
285
|
+
[
|
|
286
|
+
{ path, content: markdown },
|
|
287
|
+
{ path: runtime.manifestPath, content: nextManifest },
|
|
288
|
+
],
|
|
257
289
|
{ message: `Update ${concept.label.toLowerCase()}: ${id}`, author: { name: editor.displayName, email: editor.email } },
|
|
258
290
|
token,
|
|
259
291
|
);
|
|
@@ -9,11 +9,13 @@ import type { SiteIndex } from '../delivery/site-index.js';
|
|
|
9
9
|
import { buildSeoMeta } from '../delivery/seo.js';
|
|
10
10
|
import type { SeoMeta } from '../delivery/seo.js';
|
|
11
11
|
import { readSeoFields, resolveImageUrl } from '../delivery/seo-fields.js';
|
|
12
|
+
import { buildLinkResolver } from '../delivery/manifest.js';
|
|
13
|
+
import type { LinkResolve } from '../content/links.js';
|
|
12
14
|
|
|
13
15
|
/** Injected dependencies for the public loaders. */
|
|
14
16
|
export interface PublicRoutesDeps {
|
|
15
17
|
site: SiteIndex;
|
|
16
|
-
render: (md: string, opts?: { stagger?: boolean }) => string | Promise<string>;
|
|
18
|
+
render: (md: string, opts?: { stagger?: boolean; resolve?: LinkResolve }) => string | Promise<string>;
|
|
17
19
|
origin: string;
|
|
18
20
|
/** Site name for og:site_name and the SEO head. */
|
|
19
21
|
siteName: string;
|
|
@@ -85,7 +87,7 @@ export function createPublicRoutes(deps: PublicRoutesDeps) {
|
|
|
85
87
|
...(fields.author ? { author: fields.author } : {}),
|
|
86
88
|
...(entry.date ? { feeds } : {}),
|
|
87
89
|
});
|
|
88
|
-
return { entry, html: await render(entry.body, { stagger: true }), canonicalUrl, seo, newer, older };
|
|
90
|
+
return { entry, html: await render(entry.body, { stagger: true, resolve: buildLinkResolver(site) }), canonicalUrl, seo, newer, older };
|
|
89
91
|
}
|
|
90
92
|
|
|
91
93
|
/** The chronological archive for one concept: every non-draft summary, newest-first. */
|