@analogjs/content 3.0.0-beta.9 → 3.0.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/fesm2022/analogjs-content-md4x.mjs +35 -73
- package/fesm2022/analogjs-content-md4x.mjs.map +1 -1
- package/fesm2022/analogjs-content-mdc.mjs +5 -7
- package/fesm2022/analogjs-content-mdc.mjs.map +1 -1
- package/fesm2022/analogjs-content-og.mjs +21 -4
- package/fesm2022/analogjs-content-og.mjs.map +1 -1
- package/fesm2022/analogjs-content-resources.mjs +10 -18
- package/fesm2022/analogjs-content-resources.mjs.map +1 -1
- package/fesm2022/analogjs-content.mjs +28 -29
- package/fesm2022/analogjs-content.mjs.map +1 -1
- package/fesm2022/content-list-loader.mjs +22 -30
- package/fesm2022/content-list-loader.mjs.map +1 -1
- package/fesm2022/frontmatter-validation-error.mjs +1 -2
- package/fesm2022/parse-raw-content-file.mjs +2 -5
- package/fesm2022/parse-raw-content-file.mjs.map +1 -1
- package/package.json +7 -5
- package/types/og/src/lib/parse-html.d.ts +10 -0
- package/types/src/lib/anchor-navigation.directive.d.ts +2 -1
- package/types/src/lib/render-task.service.d.ts +2 -2
|
@@ -1,29 +1,8 @@
|
|
|
1
1
|
import { g as ContentRenderer, o as withContentFileLoader, r as withContentListLoader } from "./content-list-loader.mjs";
|
|
2
2
|
import * as i0 from "@angular/core";
|
|
3
3
|
import { Injectable, InjectionToken, inject } from "@angular/core";
|
|
4
|
-
|
|
4
|
+
// packages/content/md4x/src/lib/md4x-content-renderer.service.ts
|
|
5
5
|
var MD4X_RENDERER_OPTIONS = new InjectionToken("md4x_renderer_options");
|
|
6
|
-
function makeSlug$1(text, slugCounts) {
|
|
7
|
-
const baseSlug = text.toLowerCase().replace(/[^\w\s-]/g, "").trim().replace(/\s+/g, "-");
|
|
8
|
-
const count = slugCounts.get(baseSlug) ?? 0;
|
|
9
|
-
slugCounts.set(baseSlug, count + 1);
|
|
10
|
-
return count === 0 ? baseSlug : `${baseSlug}-${count}`;
|
|
11
|
-
}
|
|
12
|
-
function headingsToToc$1(headings) {
|
|
13
|
-
const slugCounts = /* @__PURE__ */ new Map();
|
|
14
|
-
return headings.map((h) => ({
|
|
15
|
-
id: makeSlug$1(h.text, slugCounts),
|
|
16
|
-
level: h.level,
|
|
17
|
-
text: h.text
|
|
18
|
-
}));
|
|
19
|
-
}
|
|
20
|
-
function injectHeadingIds$1(html, toc) {
|
|
21
|
-
let tocIndex = 0;
|
|
22
|
-
return html.replace(/<h([1-6])>/g, (match, level) => {
|
|
23
|
-
const item = toc[tocIndex++];
|
|
24
|
-
return item ? `<h${level} id="${item.id}">` : match;
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
6
|
/**
|
|
28
7
|
* Content renderer backed by md4x (C-based CommonMark parser compiled with Zig).
|
|
29
8
|
* 50-70x faster than marked for complex documents.
|
|
@@ -36,21 +15,20 @@ var Md4xContentRendererService = class Md4xContentRendererService extends Conten
|
|
|
36
15
|
this.options = inject(MD4X_RENDERER_OPTIONS, { optional: true });
|
|
37
16
|
}
|
|
38
17
|
async render(content) {
|
|
39
|
-
const { renderToHtml, parseMeta } = await import("md4x/napi");
|
|
40
|
-
const
|
|
41
|
-
heal: this.options?.heal,
|
|
42
|
-
highlighter: this.options?.highlighter
|
|
43
|
-
});
|
|
44
|
-
const toc = headingsToToc$1(parseMeta(content).headings);
|
|
18
|
+
const { renderToHtml, parseMeta, heal } = await import("md4x/napi");
|
|
19
|
+
const source = this.options?.heal ? heal(content) : content;
|
|
45
20
|
return {
|
|
46
|
-
content:
|
|
47
|
-
|
|
21
|
+
content: renderToHtml(source, {
|
|
22
|
+
highlighter: this.options?.highlighter,
|
|
23
|
+
headingIds: true
|
|
24
|
+
}),
|
|
25
|
+
toc: parseMeta(source).headings
|
|
48
26
|
};
|
|
49
27
|
}
|
|
50
28
|
static {
|
|
51
29
|
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
52
30
|
minVersion: "12.0.0",
|
|
53
|
-
version: "22.
|
|
31
|
+
version: "22.3.0",
|
|
54
32
|
ngImport: i0,
|
|
55
33
|
type: Md4xContentRendererService,
|
|
56
34
|
deps: null,
|
|
@@ -60,7 +38,7 @@ var Md4xContentRendererService = class Md4xContentRendererService extends Conten
|
|
|
60
38
|
static {
|
|
61
39
|
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
62
40
|
minVersion: "12.0.0",
|
|
63
|
-
version: "22.
|
|
41
|
+
version: "22.3.0",
|
|
64
42
|
ngImport: i0,
|
|
65
43
|
type: Md4xContentRendererService
|
|
66
44
|
});
|
|
@@ -68,34 +46,12 @@ var Md4xContentRendererService = class Md4xContentRendererService extends Conten
|
|
|
68
46
|
};
|
|
69
47
|
i0.ɵɵngDeclareClassMetadata({
|
|
70
48
|
minVersion: "12.0.0",
|
|
71
|
-
version: "22.
|
|
49
|
+
version: "22.3.0",
|
|
72
50
|
ngImport: i0,
|
|
73
51
|
type: Md4xContentRendererService,
|
|
74
52
|
decorators: [{ type: Injectable }]
|
|
75
53
|
});
|
|
76
|
-
|
|
77
|
-
//#region packages/content/md4x/src/lib/md4x-wasm-content-renderer.service.ts
|
|
78
|
-
function makeSlug(text, slugCounts) {
|
|
79
|
-
const baseSlug = text.toLowerCase().replace(/[^\w\s-]/g, "").trim().replace(/\s+/g, "-");
|
|
80
|
-
const count = slugCounts.get(baseSlug) ?? 0;
|
|
81
|
-
slugCounts.set(baseSlug, count + 1);
|
|
82
|
-
return count === 0 ? baseSlug : `${baseSlug}-${count}`;
|
|
83
|
-
}
|
|
84
|
-
function headingsToToc(headings) {
|
|
85
|
-
const slugCounts = /* @__PURE__ */ new Map();
|
|
86
|
-
return headings.map((h) => ({
|
|
87
|
-
id: makeSlug(h.text, slugCounts),
|
|
88
|
-
level: h.level,
|
|
89
|
-
text: h.text
|
|
90
|
-
}));
|
|
91
|
-
}
|
|
92
|
-
function injectHeadingIds(html, toc) {
|
|
93
|
-
let tocIndex = 0;
|
|
94
|
-
return html.replace(/<h([1-6])>/g, (match, level) => {
|
|
95
|
-
const item = toc[tocIndex++];
|
|
96
|
-
return item ? `<h${level} id="${item.id}">` : match;
|
|
97
|
-
});
|
|
98
|
-
}
|
|
54
|
+
// packages/content/md4x/src/lib/md4x-wasm-content-renderer.service.ts
|
|
99
55
|
/**
|
|
100
56
|
* Content renderer backed by md4x/wasm for client-side (browser) rendering.
|
|
101
57
|
* ~100KB gzip, 3-6x faster than marked in the browser.
|
|
@@ -112,20 +68,19 @@ var Md4xWasmContentRendererService = class Md4xWasmContentRendererService extend
|
|
|
112
68
|
const wasm = await import("md4x/wasm");
|
|
113
69
|
if (!this.initPromise) this.initPromise = wasm.init();
|
|
114
70
|
await this.initPromise;
|
|
115
|
-
const
|
|
116
|
-
heal: this.options?.heal,
|
|
117
|
-
highlighter: this.options?.highlighter
|
|
118
|
-
});
|
|
119
|
-
const toc = headingsToToc(wasm.parseMeta(content).headings);
|
|
71
|
+
const source = this.options?.heal ? wasm.heal(content) : content;
|
|
120
72
|
return {
|
|
121
|
-
content:
|
|
122
|
-
|
|
73
|
+
content: wasm.renderToHtml(source, {
|
|
74
|
+
highlighter: this.options?.highlighter,
|
|
75
|
+
headingIds: true
|
|
76
|
+
}),
|
|
77
|
+
toc: wasm.parseMeta(source).headings
|
|
123
78
|
};
|
|
124
79
|
}
|
|
125
80
|
static {
|
|
126
81
|
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
127
82
|
minVersion: "12.0.0",
|
|
128
|
-
version: "22.
|
|
83
|
+
version: "22.3.0",
|
|
129
84
|
ngImport: i0,
|
|
130
85
|
type: Md4xWasmContentRendererService,
|
|
131
86
|
deps: null,
|
|
@@ -135,7 +90,7 @@ var Md4xWasmContentRendererService = class Md4xWasmContentRendererService extend
|
|
|
135
90
|
static {
|
|
136
91
|
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
137
92
|
minVersion: "12.0.0",
|
|
138
|
-
version: "22.
|
|
93
|
+
version: "22.3.0",
|
|
139
94
|
ngImport: i0,
|
|
140
95
|
type: Md4xWasmContentRendererService
|
|
141
96
|
});
|
|
@@ -143,13 +98,12 @@ var Md4xWasmContentRendererService = class Md4xWasmContentRendererService extend
|
|
|
143
98
|
};
|
|
144
99
|
i0.ɵɵngDeclareClassMetadata({
|
|
145
100
|
minVersion: "12.0.0",
|
|
146
|
-
version: "22.
|
|
101
|
+
version: "22.3.0",
|
|
147
102
|
ngImport: i0,
|
|
148
103
|
type: Md4xWasmContentRendererService,
|
|
149
104
|
decorators: [{ type: Injectable }]
|
|
150
105
|
});
|
|
151
|
-
|
|
152
|
-
//#region packages/content/md4x/src/lib/provide-md4x.ts
|
|
106
|
+
// packages/content/md4x/src/lib/provide-md4x.ts
|
|
153
107
|
/**
|
|
154
108
|
* Provides the experimental md4x-based content renderer (NAPI, server/build-time).
|
|
155
109
|
*
|
|
@@ -200,8 +154,7 @@ function withMd4xWasmRenderer(options) {
|
|
|
200
154
|
withContentListLoader()
|
|
201
155
|
];
|
|
202
156
|
}
|
|
203
|
-
|
|
204
|
-
//#region packages/content/md4x/src/lib/streaming-markdown-renderer.ts
|
|
157
|
+
// packages/content/md4x/src/lib/streaming-markdown-renderer.ts
|
|
205
158
|
/**
|
|
206
159
|
* Transforms a stream of markdown chunks into a stream of rendered HTML.
|
|
207
160
|
* Uses md4x's `heal()` to fix incomplete markdown from streaming sources
|
|
@@ -223,12 +176,21 @@ function withMd4xWasmRenderer(options) {
|
|
|
223
176
|
async function streamMarkdown(input, options) {
|
|
224
177
|
const { renderToHtml, heal } = await import("md4x/napi");
|
|
225
178
|
let buffer = "";
|
|
179
|
+
let closed = false;
|
|
226
180
|
const reader = input.getReader();
|
|
181
|
+
const release = async (reason) => {
|
|
182
|
+
if (closed) return;
|
|
183
|
+
closed = true;
|
|
184
|
+
return reader.cancel(reason).finally(() => reader.releaseLock());
|
|
185
|
+
};
|
|
227
186
|
return new ReadableStream({
|
|
228
187
|
async pull(controller) {
|
|
229
188
|
try {
|
|
230
189
|
const { done, value } = await reader.read();
|
|
190
|
+
if (closed) return;
|
|
231
191
|
if (done) {
|
|
192
|
+
closed = true;
|
|
193
|
+
reader.releaseLock();
|
|
232
194
|
if (buffer) {
|
|
233
195
|
const source = options?.heal ? heal(buffer) : buffer;
|
|
234
196
|
controller.enqueue(renderToHtml(source));
|
|
@@ -241,14 +203,14 @@ async function streamMarkdown(input, options) {
|
|
|
241
203
|
controller.enqueue(renderToHtml(source));
|
|
242
204
|
} catch (error) {
|
|
243
205
|
controller.error(error);
|
|
206
|
+
await release(error).catch(() => void 0);
|
|
244
207
|
}
|
|
245
208
|
},
|
|
246
|
-
cancel() {
|
|
247
|
-
|
|
209
|
+
cancel(reason) {
|
|
210
|
+
return release(reason);
|
|
248
211
|
}
|
|
249
212
|
});
|
|
250
213
|
}
|
|
251
|
-
//#endregion
|
|
252
214
|
export { MD4X_RENDERER_OPTIONS, Md4xContentRendererService, Md4xWasmContentRendererService, streamMarkdown, withMd4xRenderer, withMd4xWasmRenderer };
|
|
253
215
|
|
|
254
216
|
//# sourceMappingURL=analogjs-content-md4x.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analogjs-content-md4x.mjs","names":[],"sources":["../../md4x/src/lib/md4x-content-renderer.service.ts","../../md4x/src/lib/md4x-wasm-content-renderer.service.ts","../../md4x/src/lib/provide-md4x.ts","../../md4x/src/lib/streaming-markdown-renderer.ts"],"sourcesContent":["import { Injectable, inject, InjectionToken } from '@angular/core';\n\nimport {\n ContentRenderer,\n RenderedContent,\n TableOfContentItem,\n} from '../../../src/lib/content-renderer';\n\n/**\n * Options for the experimental md4x-based content renderer.\n *\n * @experimental md4x integration is experimental and may change in future releases.\n */\nexport interface Md4xRendererOptions {\n /** Heal incomplete markdown (useful for streaming/LLM content). */\n heal?: boolean;\n /** Custom code block highlighter. Receives raw code and block metadata,\n * returns highlighted HTML or undefined to keep default rendering. */\n highlighter?: (\n code: string,\n block: { lang: string; filename?: string; highlights?: number[] },\n ) => string | undefined;\n}\n\nexport const MD4X_RENDERER_OPTIONS: InjectionToken<Md4xRendererOptions> =\n new InjectionToken<Md4xRendererOptions>('md4x_renderer_options');\n\nfunction makeSlug(text: string, slugCounts: Map<string, number>): string {\n const baseSlug = text\n .toLowerCase()\n .replace(/[^\\w\\s-]/g, '')\n .trim()\n .replace(/\\s+/g, '-');\n const count = slugCounts.get(baseSlug) ?? 0;\n slugCounts.set(baseSlug, count + 1);\n return count === 0 ? baseSlug : `${baseSlug}-${count}`;\n}\n\nfunction headingsToToc(\n headings: Array<{ level: number; text: string }>,\n): TableOfContentItem[] {\n const slugCounts = new Map<string, number>();\n return headings.map((h) => ({\n id: makeSlug(h.text, slugCounts),\n level: h.level,\n text: h.text,\n }));\n}\n\nfunction injectHeadingIds(html: string, toc: TableOfContentItem[]): string {\n let tocIndex = 0;\n return html.replace(/<h([1-6])>/g, (match, level) => {\n const item = toc[tocIndex++];\n return item ? `<h${level} id=\"${item.id}\">` : match;\n });\n}\n\n/**\n * Content renderer backed by md4x (C-based CommonMark parser compiled with Zig).\n * 50-70x faster than marked for complex documents.\n *\n * @experimental md4x integration is experimental and may change in future releases.\n */\n@Injectable()\nexport class Md4xContentRendererService extends ContentRenderer {\n private options = inject(MD4X_RENDERER_OPTIONS, { optional: true });\n\n override async render(content: string): Promise<RenderedContent> {\n const { renderToHtml, parseMeta } = await import('md4x/napi');\n const html = renderToHtml(content, {\n heal: this.options?.heal,\n highlighter: this.options?.highlighter,\n });\n const meta = parseMeta(content);\n const toc = headingsToToc(meta.headings);\n return {\n content: injectHeadingIds(html, toc),\n toc,\n };\n }\n}\n","import { Injectable, inject } from '@angular/core';\n\nimport {\n ContentRenderer,\n RenderedContent,\n TableOfContentItem,\n} from '../../../src/lib/content-renderer';\nimport {\n MD4X_RENDERER_OPTIONS,\n Md4xRendererOptions,\n} from './md4x-content-renderer.service';\n\nfunction makeSlug(text: string, slugCounts: Map<string, number>): string {\n const baseSlug = text\n .toLowerCase()\n .replace(/[^\\w\\s-]/g, '')\n .trim()\n .replace(/\\s+/g, '-');\n const count = slugCounts.get(baseSlug) ?? 0;\n slugCounts.set(baseSlug, count + 1);\n return count === 0 ? baseSlug : `${baseSlug}-${count}`;\n}\n\nfunction headingsToToc(\n headings: Array<{ level: number; text: string }>,\n): TableOfContentItem[] {\n const slugCounts = new Map<string, number>();\n return headings.map((h) => ({\n id: makeSlug(h.text, slugCounts),\n level: h.level,\n text: h.text,\n }));\n}\n\nfunction injectHeadingIds(html: string, toc: TableOfContentItem[]): string {\n let tocIndex = 0;\n return html.replace(/<h([1-6])>/g, (match, level) => {\n const item = toc[tocIndex++];\n return item ? `<h${level} id=\"${item.id}\">` : match;\n });\n}\n\n/**\n * Content renderer backed by md4x/wasm for client-side (browser) rendering.\n * ~100KB gzip, 3-6x faster than marked in the browser.\n *\n * @experimental md4x integration is experimental and may change in future releases.\n */\n@Injectable()\nexport class Md4xWasmContentRendererService extends ContentRenderer {\n private options = inject(MD4X_RENDERER_OPTIONS, { optional: true });\n private initPromise: Promise<void> | null = null;\n\n override async render(content: string): Promise<RenderedContent> {\n const wasm = await import('md4x/wasm');\n if (!this.initPromise) {\n this.initPromise = wasm.init();\n }\n await this.initPromise;\n\n const html = wasm.renderToHtml(content, {\n heal: this.options?.heal,\n highlighter: this.options?.highlighter,\n });\n const meta = wasm.parseMeta(content);\n const toc = headingsToToc(meta.headings);\n return {\n content: injectHeadingIds(html, toc),\n toc,\n };\n }\n}\n","import { Provider } from '@angular/core';\n\nimport { ContentRenderer } from '../../../src/lib/content-renderer';\nimport { withContentFileLoader } from '../../../src/lib/content-file-loader';\nimport { withContentListLoader } from '../../../src/lib/content-list-loader';\nimport {\n Md4xContentRendererService,\n MD4X_RENDERER_OPTIONS,\n} from './md4x-content-renderer.service';\nimport { Md4xWasmContentRendererService } from './md4x-wasm-content-renderer.service';\nimport type { Md4xRendererOptions } from './md4x-content-renderer.service';\n\n/**\n * Provides the experimental md4x-based content renderer (NAPI, server/build-time).\n *\n * @experimental md4x integration is experimental and may change in future releases.\n *\n * @example\n * ```typescript\n * provideContent(withMd4xRenderer());\n * provideContent(withMd4xRenderer({ heal: true }));\n * ```\n */\nexport function withMd4xRenderer(options?: Md4xRendererOptions): Provider {\n return [\n { provide: ContentRenderer, useClass: Md4xContentRendererService },\n options ? { provide: MD4X_RENDERER_OPTIONS, useValue: options } : [],\n withContentFileLoader(),\n withContentListLoader(),\n ];\n}\n\n/**\n * Provides the experimental md4x WASM content renderer (browser/CSR).\n * ~100KB gzip, 3-6x faster than marked in the browser.\n *\n * @experimental md4x integration is experimental and may change in future releases.\n *\n * @example\n * ```typescript\n * provideContent(withMd4xWasmRenderer());\n * ```\n */\nexport function withMd4xWasmRenderer(options?: Md4xRendererOptions): Provider {\n return [\n { provide: ContentRenderer, useClass: Md4xWasmContentRendererService },\n options ? { provide: MD4X_RENDERER_OPTIONS, useValue: options } : [],\n withContentFileLoader(),\n withContentListLoader(),\n ];\n}\n","/**\n * Transforms a stream of markdown chunks into a stream of rendered HTML.\n * Uses md4x's `heal()` to fix incomplete markdown from streaming sources\n * (LLMs, collaborative editing) so each emitted HTML chunk is valid.\n *\n * @experimental Streaming markdown support is experimental and may change in future releases.\n *\n * @example\n * ```typescript\n * // In a Nitro API route\n * import { streamMarkdown } from '@analogjs/content';\n *\n * export default defineEventHandler(async (event) => {\n * const llmStream = getAIStream(prompt);\n * return streamMarkdown(llmStream, { heal: true });\n * });\n * ```\n */\nexport async function streamMarkdown(\n input: ReadableStream<string>,\n options?: { heal?: boolean },\n): Promise<ReadableStream<string>> {\n const { renderToHtml, heal } = await import('md4x/napi');\n\n let buffer = '';\n const reader = input.getReader();\n\n return new ReadableStream<string>({\n async pull(controller) {\n try {\n const { done, value } = await reader.read();\n\n if (done) {\n if (buffer) {\n const source = options?.heal ? heal(buffer) : buffer;\n controller.enqueue(renderToHtml(source));\n }\n controller.close();\n return;\n }\n\n buffer += value;\n const source = options?.heal ? heal(buffer) : buffer;\n controller.enqueue(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ACR,IAAI,QAAQ;MACV,MAAM,SAAS,SAAS,OAAO,KAAK,MAAM,IAAI;MAC9C,WAAW,QAAQ,aAAa,MAAM,CAAC;KACzC;KACA,WAAW,MAAK;KAChB;IACF;IAEA,UAAU;IACV,MAAM,SAAS,SAAS,OAAO,KAAK,MAAM,IAAI;IAC9C,WAAW,QAAQ,aAAa,MAAM,CAAC;GACzC,SAAS,OAAO;IACd,WAAW,MAAM,KAAK;GACxB;EACF;EACA,SAAM;GACJ,OAAO,OAAM;EACf;CACD,CAAA;AACH"}
|
|
1
|
+
{"version":3,"file":"analogjs-content-md4x.mjs","names":[],"sources":["../../md4x/src/lib/md4x-content-renderer.service.ts","../../md4x/src/lib/md4x-wasm-content-renderer.service.ts","../../md4x/src/lib/provide-md4x.ts","../../md4x/src/lib/streaming-markdown-renderer.ts"],"sourcesContent":["import { Injectable, inject, InjectionToken } from '@angular/core';\n\nimport {\n ContentRenderer,\n RenderedContent,\n} from '../../../src/lib/content-renderer';\n\n/**\n * Options for the experimental md4x-based content renderer.\n *\n * @experimental md4x integration is experimental and may change in future releases.\n */\nexport interface Md4xRendererOptions {\n /** Heal incomplete markdown (useful for streaming/LLM content). */\n heal?: boolean;\n /** Custom code block highlighter. Receives raw code and block metadata,\n * returns highlighted HTML or undefined to keep default rendering. */\n highlighter?: (\n code: string,\n block: { lang: string; filename?: string; highlights?: number[] },\n ) => string | undefined;\n}\n\nexport const MD4X_RENDERER_OPTIONS: InjectionToken<Md4xRendererOptions> =\n new InjectionToken<Md4xRendererOptions>('md4x_renderer_options');\n\n/**\n * Content renderer backed by md4x (C-based CommonMark parser compiled with Zig).\n * 50-70x faster than marked for complex documents.\n *\n * @experimental md4x integration is experimental and may change in future releases.\n */\n@Injectable()\nexport class Md4xContentRendererService extends ContentRenderer {\n private options = inject(MD4X_RENDERER_OPTIONS, { optional: true });\n\n override async render(content: string): Promise<RenderedContent> {\n const { renderToHtml, parseMeta, heal } = await import('md4x/napi');\n const source = this.options?.heal ? heal(content) : content;\n const html = renderToHtml(source, {\n highlighter: this.options?.highlighter,\n headingIds: true,\n });\n return { content: html, toc: parseMeta(source).headings };\n }\n}\n","import { Injectable, inject } from '@angular/core';\n\nimport {\n ContentRenderer,\n RenderedContent,\n} from '../../../src/lib/content-renderer';\nimport {\n MD4X_RENDERER_OPTIONS,\n Md4xRendererOptions,\n} from './md4x-content-renderer.service';\n\n/**\n * Content renderer backed by md4x/wasm for client-side (browser) rendering.\n * ~100KB gzip, 3-6x faster than marked in the browser.\n *\n * @experimental md4x integration is experimental and may change in future releases.\n */\n@Injectable()\nexport class Md4xWasmContentRendererService extends ContentRenderer {\n private options = inject(MD4X_RENDERER_OPTIONS, { optional: true });\n private initPromise: Promise<void> | null = null;\n\n override async render(content: string): Promise<RenderedContent> {\n const wasm = await import('md4x/wasm');\n if (!this.initPromise) {\n this.initPromise = wasm.init();\n }\n await this.initPromise;\n\n const source = this.options?.heal ? wasm.heal(content) : content;\n const html = wasm.renderToHtml(source, {\n highlighter: this.options?.highlighter,\n headingIds: true,\n });\n return { content: html, toc: wasm.parseMeta(source).headings };\n }\n}\n","import { Provider } from '@angular/core';\n\nimport { ContentRenderer } from '../../../src/lib/content-renderer';\nimport { withContentFileLoader } from '../../../src/lib/content-file-loader';\nimport { withContentListLoader } from '../../../src/lib/content-list-loader';\nimport {\n Md4xContentRendererService,\n MD4X_RENDERER_OPTIONS,\n} from './md4x-content-renderer.service';\nimport { Md4xWasmContentRendererService } from './md4x-wasm-content-renderer.service';\nimport type { Md4xRendererOptions } from './md4x-content-renderer.service';\n\n/**\n * Provides the experimental md4x-based content renderer (NAPI, server/build-time).\n *\n * @experimental md4x integration is experimental and may change in future releases.\n *\n * @example\n * ```typescript\n * provideContent(withMd4xRenderer());\n * provideContent(withMd4xRenderer({ heal: true }));\n * ```\n */\nexport function withMd4xRenderer(options?: Md4xRendererOptions): Provider {\n return [\n { provide: ContentRenderer, useClass: Md4xContentRendererService },\n options ? { provide: MD4X_RENDERER_OPTIONS, useValue: options } : [],\n withContentFileLoader(),\n withContentListLoader(),\n ];\n}\n\n/**\n * Provides the experimental md4x WASM content renderer (browser/CSR).\n * ~100KB gzip, 3-6x faster than marked in the browser.\n *\n * @experimental md4x integration is experimental and may change in future releases.\n *\n * @example\n * ```typescript\n * provideContent(withMd4xWasmRenderer());\n * ```\n */\nexport function withMd4xWasmRenderer(options?: Md4xRendererOptions): Provider {\n return [\n { provide: ContentRenderer, useClass: Md4xWasmContentRendererService },\n options ? { provide: MD4X_RENDERER_OPTIONS, useValue: options } : [],\n withContentFileLoader(),\n withContentListLoader(),\n ];\n}\n","/**\n * Transforms a stream of markdown chunks into a stream of rendered HTML.\n * Uses md4x's `heal()` to fix incomplete markdown from streaming sources\n * (LLMs, collaborative editing) so each emitted HTML chunk is valid.\n *\n * @experimental Streaming markdown support is experimental and may change in future releases.\n *\n * @example\n * ```typescript\n * // In a Nitro API route\n * import { streamMarkdown } from '@analogjs/content';\n *\n * export default defineEventHandler(async (event) => {\n * const llmStream = getAIStream(prompt);\n * return streamMarkdown(llmStream, { heal: true });\n * });\n * ```\n */\nexport async function streamMarkdown(\n input: ReadableStream<string>,\n options?: { heal?: boolean },\n): Promise<ReadableStream<string>> {\n const { renderToHtml, heal } = await import('md4x/napi');\n\n let buffer = '';\n let closed = false;\n const reader = input.getReader();\n\n const release = async (reason?: unknown) => {\n if (closed) {\n return;\n }\n closed = true;\n return reader.cancel(reason).finally(() => reader.releaseLock());\n };\n\n return new ReadableStream<string>({\n async pull(controller) {\n try {\n const { done, value } = await reader.read();\n if (closed) {\n return;\n }\n\n if (done) {\n closed = true;\n reader.releaseLock();\n if (buffer) {\n const source = options?.heal ? heal(buffer) : buffer;\n controller.enqueue(renderToHtml(source));\n }\n controller.close();\n return;\n }\n\n buffer += value;\n const source = options?.heal ? heal(buffer) : buffer;\n controller.enqueue(renderToHtml(source));\n } catch (error) {\n controller.error(error);\n await release(error).catch(() => undefined);\n }\n },\n cancel(reason) {\n return release(reason);\n },\n });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KACT,OAAO,YAAW;KAClB,IAAI,QAAQ;MACV,MAAM,SAAS,SAAS,OAAO,KAAK,MAAM,IAAI;MAC9C,WAAW,QAAQ,aAAa,MAAM,CAAC;KACzC;KACA,WAAW,MAAK;KAChB;IACF;IAEA,UAAU;IACV,MAAM,SAAS,SAAS,OAAO,KAAK,MAAM,IAAI;IAC9C,WAAW,QAAQ,aAAa,MAAM,CAAC;GACzC,SAAS,OAAO;IACd,WAAW,MAAM,KAAK;IACtB,MAAM,QAAQ,KAAK,CAAC,CAAC,YAAY,KAAA,CAAS;GAC5C;EACF;EACA,OAAO,QAAM;GACX,OAAO,QAAQ,MAAM;EACvB;CACD,CAAA;AACH"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
2
|
import { Directive, ElementRef, InjectionToken, Renderer2, ViewContainerRef, effect, inject, input } from "@angular/core";
|
|
3
|
-
|
|
3
|
+
// packages/content/mdc/src/lib/mdc-component-registry.ts
|
|
4
4
|
/**
|
|
5
5
|
* Registry mapping MDC component names to lazy-loaded Angular components.
|
|
6
6
|
*
|
|
@@ -30,8 +30,7 @@ function withMdcComponents(components) {
|
|
|
30
30
|
useValue: new Map(Object.entries(components))
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
//#region packages/content/mdc/src/lib/mdc-renderer.directive.ts
|
|
33
|
+
// packages/content/mdc/src/lib/mdc-renderer.directive.ts
|
|
35
34
|
/**
|
|
36
35
|
* Directive that renders MDC (Markdown Components) AST nodes as Angular components.
|
|
37
36
|
*
|
|
@@ -117,7 +116,7 @@ var MdcRendererDirective = class MdcRendererDirective {
|
|
|
117
116
|
static {
|
|
118
117
|
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
119
118
|
minVersion: "12.0.0",
|
|
120
|
-
version: "22.
|
|
119
|
+
version: "22.3.0",
|
|
121
120
|
ngImport: i0,
|
|
122
121
|
type: MdcRendererDirective,
|
|
123
122
|
deps: [],
|
|
@@ -127,7 +126,7 @@ var MdcRendererDirective = class MdcRendererDirective {
|
|
|
127
126
|
static {
|
|
128
127
|
this.ɵdir = i0.ɵɵngDeclareDirective({
|
|
129
128
|
minVersion: "17.1.0",
|
|
130
|
-
version: "22.
|
|
129
|
+
version: "22.3.0",
|
|
131
130
|
type: MdcRendererDirective,
|
|
132
131
|
isStandalone: true,
|
|
133
132
|
selector: "[mdcAst]",
|
|
@@ -144,7 +143,7 @@ var MdcRendererDirective = class MdcRendererDirective {
|
|
|
144
143
|
};
|
|
145
144
|
i0.ɵɵngDeclareClassMetadata({
|
|
146
145
|
minVersion: "12.0.0",
|
|
147
|
-
version: "22.
|
|
146
|
+
version: "22.3.0",
|
|
148
147
|
ngImport: i0,
|
|
149
148
|
type: MdcRendererDirective,
|
|
150
149
|
decorators: [{
|
|
@@ -164,7 +163,6 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
164
163
|
}]
|
|
165
164
|
}] }
|
|
166
165
|
});
|
|
167
|
-
//#endregion
|
|
168
166
|
export { MDC_COMPONENTS, MdcRendererDirective, withMdcComponents };
|
|
169
167
|
|
|
170
168
|
//# sourceMappingURL=analogjs-content-mdc.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analogjs-content-mdc.mjs","names":[],"sources":["../../mdc/src/lib/mdc-component-registry.ts","../../mdc/src/lib/mdc-renderer.directive.ts"],"sourcesContent":["import { InjectionToken, Type, Provider } from '@angular/core';\n\n/**\n * Registry mapping MDC component names to lazy-loaded Angular components.\n *\n * @experimental MDC component support is experimental and may change in future releases.\n */\nexport const MDC_COMPONENTS: InjectionToken<\n Map<string, () => Promise<Type<unknown>>>\n> = new InjectionToken('mdc_components');\n\n/**\n * Provides a registry of Angular components that can be used in MDC\n * (Markdown Components) syntax within markdown content.\n *\n * @experimental MDC component support is experimental and may change in future releases.\n *\n * @example\n * ```typescript\n * provideContent(\n * withMd4xRenderer(),\n * withMdcComponents({\n * alert: () => import('./components/alert.component').then(m => m.AlertComponent),\n * card: () => import('./components/card.component').then(m => m.CardComponent),\n * }),\n * );\n * ```\n */\nexport function withMdcComponents(\n components: Record<string, () => Promise<Type<unknown>>>,\n): Provider {\n return {\n provide: MDC_COMPONENTS,\n useValue: new Map(Object.entries(components)),\n };\n}\n","import {\n Directive,\n ElementRef,\n effect,\n inject,\n input,\n InputSignal,\n Renderer2,\n ViewContainerRef,\n} from '@angular/core';\n\nimport { MDC_COMPONENTS } from './mdc-component-registry';\n\ntype ComarkNode =\n | string\n | [string | null, Record<string, unknown>, ...ComarkNode[]];\n\n/**\n * Directive that renders MDC (Markdown Components) AST nodes as Angular components.\n *\n * Walks the ComarkTree AST from md4x's `parseAST()`, matches component nodes\n * to the registered MDC_COMPONENTS map, and instantiates them via\n * `ViewContainerRef.createComponent()` with MDC attributes bound as inputs.\n *\n * @experimental MDC component support is experimental and may change in future releases.\n *\n * @example\n * ```html\n * <div [mdcAst]=\"parsedAst\"></div>\n * ```\n */\n@Directive({\n // eslint-disable-next-line @angular-eslint/directive-selector\n selector: '[mdcAst]',\n standalone: true,\n})\nexport class MdcRendererDirective {\n readonly ast: InputSignal<{ nodes: ComarkNode[] } | null> = input<{\n nodes: ComarkNode[];\n } | null>(null, {\n alias: 'mdcAst',\n });\n\n private readonly viewContainer = inject(ViewContainerRef);\n private readonly renderer = inject(Renderer2);\n private readonly el = inject(ElementRef);\n private readonly components = inject(MDC_COMPONENTS, { optional: true });\n private renderId = 0;\n\n constructor() {\n effect(() => {\n const ast = this.ast();\n const currentRenderId = ++this.renderId;\n\n this.viewContainer.clear();\n const host = this.el.nativeElement as HTMLElement;\n host.innerHTML = '';\n\n if (!ast?.nodes) return;\n\n // Fire-and-forget: Angular doesn't await effects, so we schedule\n // the async rendering and let it complete in the background.\n void this.renderNodes(ast.nodes, host, currentRenderId);\n });\n }\n\n private async renderNodes(\n nodes: ComarkNode[],\n parent: HTMLElement,\n renderId: number,\n ): Promise<void> {\n for (const node of nodes) {\n if (this.renderId !== renderId) return;\n await this.renderNode(node, parent, renderId);\n }\n }\n\n private async renderNode(\n node: ComarkNode,\n parent: HTMLElement,\n renderId: number,\n ): Promise<void> {\n if (this.renderId !== renderId) return;\n\n if (typeof node === 'string') {\n const text = this.renderer.createText(node);\n this.renderer.appendChild(parent, text);\n return;\n }\n\n const [tag, props, ...children] = node;\n\n if (!tag) {\n for (const child of children) {\n if (this.renderId !== renderId) return;\n await this.renderNode(child, parent, renderId);\n }\n return;\n }\n\n // Check if this tag is a registered MDC component\n const componentLoader = this.components?.get(tag);\n if (componentLoader) {\n try {\n const componentType = await componentLoader();\n if (this.renderId !== renderId) return;\n\n const tempContainer = this.renderer.createElement('div');\n for (const child of children) {\n if (this.renderId !== renderId) return;\n await this.renderNode(child, tempContainer, renderId);\n }\n if (this.renderId !== renderId) return;\n\n const projectableNodes = [\n Array.from((tempContainer as HTMLElement).childNodes),\n ];\n const componentRef = this.viewContainer.createComponent(componentType, {\n projectableNodes,\n });\n\n // Bind MDC attributes as component inputs\n for (const [key, value] of Object.entries(props)) {\n componentRef.setInput(key, value);\n }\n\n const componentEl = componentRef.location.nativeElement as HTMLElement;\n this.renderer.appendChild(parent, componentEl);\n } catch (e) {\n console.error(`[MdcRenderer] Failed to load component \"${tag}\":`, e);\n }\n return;\n }\n\n // Fall back to rendering as a standard HTML element\n const el = this.renderer.createElement(tag);\n for (const [key, value] of Object.entries(props)) {\n this.renderer.setAttribute(el, key, String(value));\n }\n for (const child of children) {\n if (this.renderId !== renderId) return;\n await this.renderNode(child, el, renderId);\n }\n this.renderer.appendChild(parent, el);\n }\n}\n"],"mappings":";;;;;;;;AAOA,IAAa,iBAET,IAAI,eAAe,gBAAgB;;;;;;;;;;;;;;;;;;AAmBvC,SAAgB,kBACd,YAAwD;CAExD,OAAO;EACL,SAAS;EACT,UAAU,IAAI,IAAI,OAAO,QAAQ,UAAU,CAAC;CAC7C;AACH
|
|
1
|
+
{"version":3,"file":"analogjs-content-mdc.mjs","names":[],"sources":["../../mdc/src/lib/mdc-component-registry.ts","../../mdc/src/lib/mdc-renderer.directive.ts"],"sourcesContent":["import { InjectionToken, Type, Provider } from '@angular/core';\n\n/**\n * Registry mapping MDC component names to lazy-loaded Angular components.\n *\n * @experimental MDC component support is experimental and may change in future releases.\n */\nexport const MDC_COMPONENTS: InjectionToken<\n Map<string, () => Promise<Type<unknown>>>\n> = new InjectionToken('mdc_components');\n\n/**\n * Provides a registry of Angular components that can be used in MDC\n * (Markdown Components) syntax within markdown content.\n *\n * @experimental MDC component support is experimental and may change in future releases.\n *\n * @example\n * ```typescript\n * provideContent(\n * withMd4xRenderer(),\n * withMdcComponents({\n * alert: () => import('./components/alert.component').then(m => m.AlertComponent),\n * card: () => import('./components/card.component').then(m => m.CardComponent),\n * }),\n * );\n * ```\n */\nexport function withMdcComponents(\n components: Record<string, () => Promise<Type<unknown>>>,\n): Provider {\n return {\n provide: MDC_COMPONENTS,\n useValue: new Map(Object.entries(components)),\n };\n}\n","import {\n Directive,\n ElementRef,\n effect,\n inject,\n input,\n InputSignal,\n Renderer2,\n ViewContainerRef,\n} from '@angular/core';\n\nimport { MDC_COMPONENTS } from './mdc-component-registry';\n\ntype ComarkNode =\n | string\n | [string | null, Record<string, unknown>, ...ComarkNode[]];\n\n/**\n * Directive that renders MDC (Markdown Components) AST nodes as Angular components.\n *\n * Walks the ComarkTree AST from md4x's `parseAST()`, matches component nodes\n * to the registered MDC_COMPONENTS map, and instantiates them via\n * `ViewContainerRef.createComponent()` with MDC attributes bound as inputs.\n *\n * @experimental MDC component support is experimental and may change in future releases.\n *\n * @example\n * ```html\n * <div [mdcAst]=\"parsedAst\"></div>\n * ```\n */\n@Directive({\n // eslint-disable-next-line @angular-eslint/directive-selector\n selector: '[mdcAst]',\n standalone: true,\n})\nexport class MdcRendererDirective {\n readonly ast: InputSignal<{ nodes: ComarkNode[] } | null> = input<{\n nodes: ComarkNode[];\n } | null>(null, {\n alias: 'mdcAst',\n });\n\n private readonly viewContainer = inject(ViewContainerRef);\n private readonly renderer = inject(Renderer2);\n private readonly el = inject(ElementRef);\n private readonly components = inject(MDC_COMPONENTS, { optional: true });\n private renderId = 0;\n\n constructor() {\n effect(() => {\n const ast = this.ast();\n const currentRenderId = ++this.renderId;\n\n this.viewContainer.clear();\n const host = this.el.nativeElement as HTMLElement;\n host.innerHTML = '';\n\n if (!ast?.nodes) return;\n\n // Fire-and-forget: Angular doesn't await effects, so we schedule\n // the async rendering and let it complete in the background.\n void this.renderNodes(ast.nodes, host, currentRenderId);\n });\n }\n\n private async renderNodes(\n nodes: ComarkNode[],\n parent: HTMLElement,\n renderId: number,\n ): Promise<void> {\n for (const node of nodes) {\n if (this.renderId !== renderId) return;\n await this.renderNode(node, parent, renderId);\n }\n }\n\n private async renderNode(\n node: ComarkNode,\n parent: HTMLElement,\n renderId: number,\n ): Promise<void> {\n if (this.renderId !== renderId) return;\n\n if (typeof node === 'string') {\n const text = this.renderer.createText(node);\n this.renderer.appendChild(parent, text);\n return;\n }\n\n const [tag, props, ...children] = node;\n\n if (!tag) {\n for (const child of children) {\n if (this.renderId !== renderId) return;\n await this.renderNode(child, parent, renderId);\n }\n return;\n }\n\n // Check if this tag is a registered MDC component\n const componentLoader = this.components?.get(tag);\n if (componentLoader) {\n try {\n const componentType = await componentLoader();\n if (this.renderId !== renderId) return;\n\n const tempContainer = this.renderer.createElement('div');\n for (const child of children) {\n if (this.renderId !== renderId) return;\n await this.renderNode(child, tempContainer, renderId);\n }\n if (this.renderId !== renderId) return;\n\n const projectableNodes = [\n Array.from((tempContainer as HTMLElement).childNodes),\n ];\n const componentRef = this.viewContainer.createComponent(componentType, {\n projectableNodes,\n });\n\n // Bind MDC attributes as component inputs\n for (const [key, value] of Object.entries(props)) {\n componentRef.setInput(key, value);\n }\n\n const componentEl = componentRef.location.nativeElement as HTMLElement;\n this.renderer.appendChild(parent, componentEl);\n } catch (e) {\n console.error(`[MdcRenderer] Failed to load component \"${tag}\":`, e);\n }\n return;\n }\n\n // Fall back to rendering as a standard HTML element\n const el = this.renderer.createElement(tag);\n for (const [key, value] of Object.entries(props)) {\n this.renderer.setAttribute(el, key, String(value));\n }\n for (const child of children) {\n if (this.renderId !== renderId) return;\n await this.renderNode(child, el, renderId);\n }\n this.renderer.appendChild(parent, el);\n }\n}\n"],"mappings":";;;;;;;;AAOA,IAAa,iBAET,IAAI,eAAe,gBAAgB;;;;;;;;;;;;;;;;;;AAmBvC,SAAgB,kBACd,YAAwD;CAExD,OAAO;EACL,SAAS;EACT,UAAU,IAAI,IAAI,OAAO,QAAQ,UAAU,CAAC;CAC7C;AACH;;;;;;;;;;;;;;;;ACCA,IAAa,uBAAb,MAAa,qBAAoB;CAa/B,cAAA;EAZS,KAAA,MAAmD,MAElD,MAAI,EACZ,OAAO,SAAQ,CAAA;EAGA,KAAA,gBAAgB,OAAO,gBAAgB;EACvC,KAAA,WAAW,OAAO,SAAS;EAC3B,KAAA,KAAK,OAAO,UAAU;EACtB,KAAA,aAAa,OAAO,gBAAgB,EAAE,UAAU,KAAI,CAAE;EAC/D,KAAA,WAAW;EAGjB,aAAY;GACV,MAAM,MAAM,KAAK,IAAG;GACpB,MAAM,kBAAkB,EAAE,KAAK;GAE/B,KAAK,cAAc,MAAK;GACxB,MAAM,OAAO,KAAK,GAAG;GACrB,KAAK,YAAY;GAEjB,IAAI,CAAC,KAAK,OAAO;GAIjB,KAAU,YAAY,IAAI,OAAO,MAAM,eAAe;EACxD,CAAC;CACH;CAEQ,MAAM,YACZ,OACA,QACA,UAAgB;EAEhB,KAAK,MAAM,QAAQ,OAAO;GACxB,IAAI,KAAK,aAAa,UAAU;GAChC,MAAM,KAAK,WAAW,MAAM,QAAQ,QAAQ;EAC9C;CACF;CAEQ,MAAM,WACZ,MACA,QACA,UAAgB;EAEhB,IAAI,KAAK,aAAa,UAAU;EAEhC,IAAI,OAAO,SAAS,UAAU;GAC5B,MAAM,OAAO,KAAK,SAAS,WAAW,IAAI;GAC1C,KAAK,SAAS,YAAY,QAAQ,IA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GAAA,YAAA;GAAA,SAAA;GAAA,UAAA;GAAA,MAAA;GAAoB,MAAA,CAAA;GAAA,QAAA,GAAA,gBAAA;EAAA,CAAA;CAAA;CAApB;EAAA,KAAA,OAAA,GAAA,qBAAA;GAAA,YAAA;GAAA,SAAA;GAAA,MAAA;GAAoB,cAAA;GAAA,UAAA;GAAA,QAAA,EAAA,KAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA,EAAA;GAAA,UAAA;EAAA,CAAA;CAAA;;AAApB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAoB,YAAA,CAAA;EALhC,MAAA;EAAU,MAAA,CAAA;GAET,UAAU;GACV,YAAY;EACb,CAAA"}
|
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
import satori from "satori";
|
|
2
|
-
import { html } from "satori-html";
|
|
3
2
|
import sharp from "sharp";
|
|
4
|
-
|
|
3
|
+
import { decodeHTML, decodeHTMLAttribute } from "entities";
|
|
4
|
+
import { html } from "satori-html";
|
|
5
|
+
// packages/content/og/src/lib/parse-html.ts
|
|
6
|
+
function parseHtml(element) {
|
|
7
|
+
const node = html(element);
|
|
8
|
+
decodeNode(node);
|
|
9
|
+
return node;
|
|
10
|
+
}
|
|
11
|
+
function decodeNode(node) {
|
|
12
|
+
const { props } = node;
|
|
13
|
+
for (const [key, value] of Object.entries(props)) if (key !== "children" && typeof value === "string") props[key] = decodeHTMLAttribute(value);
|
|
14
|
+
const { children } = props;
|
|
15
|
+
props.children = Array.isArray(children) ? children.map(decodeChild) : children && decodeChild(children);
|
|
16
|
+
}
|
|
17
|
+
function decodeChild(child) {
|
|
18
|
+
if (typeof child === "string") return decodeHTML(child);
|
|
19
|
+
decodeNode(child);
|
|
20
|
+
return child;
|
|
21
|
+
}
|
|
22
|
+
// packages/content/og/src/lib/og.ts
|
|
5
23
|
var generateImage = async (element, options) => {
|
|
6
|
-
const elementHtml =
|
|
24
|
+
const elementHtml = parseHtml(element);
|
|
7
25
|
const svg = await satori(elementHtml, {
|
|
8
26
|
width: options.width || 1200,
|
|
9
27
|
height: options.height || 630,
|
|
@@ -32,7 +50,6 @@ var ImageResponse = class extends Response {
|
|
|
32
50
|
});
|
|
33
51
|
}
|
|
34
52
|
};
|
|
35
|
-
//#endregion
|
|
36
53
|
export { ImageResponse };
|
|
37
54
|
|
|
38
55
|
//# sourceMappingURL=analogjs-content-og.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analogjs-content-og.mjs","names":[],"sources":["../../og/src/lib/og.ts"],"sourcesContent":["// Credit for modified source: https://github.com/etherCorps/sveltekit-og/blob/main/src/lib/api.ts\n\nimport satori from 'satori';\nimport
|
|
1
|
+
{"version":3,"file":"analogjs-content-og.mjs","names":[],"sources":["../../og/src/lib/parse-html.ts","../../og/src/lib/og.ts"],"sourcesContent":["import { decodeHTML, decodeHTMLAttribute } from 'entities';\nimport { html } from 'satori-html';\n\ninterface ParsedNode {\n type: string;\n props: {\n children?: ParsedChild | ParsedChild[];\n [prop: string]: unknown;\n };\n}\n\ntype ParsedChild = string | ParsedNode;\n\n// satori-html leaves entities in text and attribute values undecoded.\nexport function parseHtml(element: string): ParsedNode {\n const node: ParsedNode = html(element);\n decodeNode(node);\n return node;\n}\n\nfunction decodeNode(node: ParsedNode): void {\n const { props } = node;\n for (const [key, value] of Object.entries(props)) {\n if (key !== 'children' && typeof value === 'string') {\n props[key] = decodeHTMLAttribute(value);\n }\n }\n\n const { children } = props;\n props.children = Array.isArray(children)\n ? children.map(decodeChild)\n : children && decodeChild(children);\n}\n\nfunction decodeChild(child: ParsedChild): ParsedChild {\n if (typeof child === 'string') {\n return decodeHTML(child);\n }\n decodeNode(child);\n return child;\n}\n","// Credit for modified source: https://github.com/etherCorps/sveltekit-og/blob/main/src/lib/api.ts\n\nimport satori from 'satori';\nimport sharp from 'sharp';\n\nimport { ImageResponseOptions } from './options';\nimport { parseHtml } from './parse-html';\n\nexport const generateImage = async (\n element: string,\n options: ImageResponseOptions,\n): Promise<Buffer> => {\n const elementHtml = parseHtml(element);\n const svg = await satori(elementHtml as any, {\n width: options.width || 1200,\n height: options.height || 630,\n fonts: options.fonts?.length ? options.fonts : [],\n tailwindConfig: options.tailwindConfig,\n });\n const svgBuffer = Buffer.from(svg);\n const png = sharp(svgBuffer).png().toBuffer();\n\n const pngBuffer = await png;\n\n return pngBuffer;\n};\n\nexport class ImageResponse extends Response {\n constructor(element: string, options: ImageResponseOptions = {}) {\n super();\n\n const body = new ReadableStream({\n async start(controller) {\n const buffer = await generateImage(element, options);\n controller.enqueue(buffer);\n controller.close();\n },\n });\n\n return new Response(body, {\n headers: {\n 'Content-Type': 'image/png',\n 'Cache-Control': options.debug\n ? 'no-cache, no-store'\n : 'public, immutable, no-transform, max-age=31536000',\n ...options.headers,\n },\n status: options.status || 200,\n statusText: options.statusText,\n });\n }\n}\n"],"mappings":";;;;;AAcA,SAAgB,UAAU,SAAe;CACvC,MAAM,OAAmB,KAAK,OAAO;CACrC,WAAW,IAAI;CACf,OAAO;AACT;AAEA,SAAS,WAAW,MAAgB;CAClC,MAAM,EAAE,UAAU;CAClB,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,GAC7C,IAAI,QAAQ,cAAc,OAAO,UAAU,UACzC,MAAM,OAAO,oBAAoB,KAAK;CAI1C,MAAM,EAAE,aAAa;CACrB,MAAM,WAAW,MAAM,QAAQ,QAAQ,IACnC,SAAS,IAAI,WAAW,IACxB,YAAY,YAAY,QAAQ;AACtC;AAEA,SAAS,YAAY,OAAkB;CACrC,IAAI,OAAO,UAAU,UACnB,OAAO,WAAW,KAAK;CAEzB,WAAW,KAAK;CAChB,OAAO;AACT;;AChCA,IAAa,gBAAgB,OAC3B,SACA,YACmB;CACnB,MAAM,cAAc,UAAU,OAAO;CACrC,MAAM,MAAM,MAAM,OAAO,aAAoB;EAC3C,OAAO,QAAQ,SAAS;EACxB,QAAQ,QAAQ,UAAU;EAC1B,OAAO,QAAQ,OAAO,SAAS,QAAQ,QAAQ,CAAA;EAC/C,gBAAgB,QAAQ;CACzB,CAAA;CACD,MAAM,YAAY,OAAO,KAAK,GAAG;CAKjC,OAAO,MAJK,MAAM,SAAS,CAAC,CAAC,IAAG,CAAE,CAAC,SAEX;AAG1B;AAEA,IAAa,gBAAb,cAAmC,SAAQ;CACzC,YAAY,SAAiB,UAAgC,CAAA,GAAE;EAC7D,MAAK;EAEL,MAAM,OAAO,IAAI,eAAe,EAC9B,MAAM,MAAM,YAAU;GACpB,MAAM,SAAS,MAAM,cAAc,SAAS,OAAO;GACnD,WAAW,QAAQ,MAAM;GACzB,WAAW,MAAK;EAClB,EACD,CAAA;EAED,OAAO,IAAI,SAAS,MAAM;GACxB,SAAS;IACP,gBAAgB;IAChB,iBAAiB,QAAQ,QACrB,uBACA;IACJ,GAAG,QAAQ;GACZ;GACD,QAAQ,QAAQ,UAAU;GAC1B,YAAY,QAAQ;EACrB,CAAA;CACH;AACD"}
|
|
@@ -2,22 +2,19 @@ import { a as injectContentFileLoader, f as filterByLocale, g as ContentRenderer
|
|
|
2
2
|
import { t as FrontmatterValidationError } from "./frontmatter-validation-error.mjs";
|
|
3
3
|
import { computed, inject, resource } from "@angular/core";
|
|
4
4
|
import { ActivatedRoute } from "@angular/router";
|
|
5
|
-
import { from } from "rxjs";
|
|
6
5
|
import { map } from "rxjs/operators";
|
|
7
6
|
import { toSignal } from "@angular/core/rxjs-interop";
|
|
8
|
-
|
|
7
|
+
// packages/content/resources/src/content-files-resource.ts
|
|
9
8
|
function contentFilesResource(filterFn) {
|
|
10
9
|
const contentListLoader = injectContentListLoader();
|
|
11
10
|
const locale = injectContentLocale();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return results;
|
|
16
|
-
});
|
|
17
|
-
return resource({ loader: () => contentList });
|
|
11
|
+
return resource({ loader: async () => {
|
|
12
|
+
const items = await contentListLoader();
|
|
13
|
+
const results = locale ? filterByLocale(items, locale) : items;
|
|
14
|
+
return filterFn ? results.filter(filterFn) : results;
|
|
15
|
+
} });
|
|
18
16
|
}
|
|
19
|
-
|
|
20
|
-
//#region packages/content/resources/src/content-file-resource.ts
|
|
17
|
+
// packages/content/resources/src/content-file-resource.ts
|
|
21
18
|
async function validateAttributes(schema, attributes, filename) {
|
|
22
19
|
const result = await schema["~standard"].validate(attributes);
|
|
23
20
|
if (result.issues) throw new FrontmatterValidationError(result.issues, filename);
|
|
@@ -75,15 +72,11 @@ function contentFileResource(paramsOrOptions, fallbackArg = "No Content Found")
|
|
|
75
72
|
const loaderPromise = injectContentFileLoader();
|
|
76
73
|
const contentRenderer = inject(ContentRenderer);
|
|
77
74
|
const locale = injectContentLocale();
|
|
78
|
-
const contentFilesMap = toSignal(from(loaderPromise()));
|
|
79
75
|
const input = params || toSignal(inject(ActivatedRoute).paramMap.pipe(map((params) => params.get("slug"))), { requireSync: true });
|
|
80
76
|
return resource({
|
|
81
|
-
params: computed(() => ({
|
|
82
|
-
|
|
83
|
-
files
|
|
84
|
-
})),
|
|
85
|
-
loader: async ({ params: resourceParams }) => {
|
|
86
|
-
const { input: param, files } = resourceParams;
|
|
77
|
+
params: computed(() => ({ input: input() })),
|
|
78
|
+
loader: async ({ params: { input: param } }) => {
|
|
79
|
+
const files = await loaderPromise();
|
|
87
80
|
if (typeof param === "string") {
|
|
88
81
|
if (param) {
|
|
89
82
|
const file = await getContentFile(files, param, fallback, locale, schema);
|
|
@@ -123,7 +116,6 @@ function contentFileResource(paramsOrOptions, fallbackArg = "No Content Found")
|
|
|
123
116
|
}
|
|
124
117
|
});
|
|
125
118
|
}
|
|
126
|
-
//#endregion
|
|
127
119
|
export { contentFileResource, contentFilesResource };
|
|
128
120
|
|
|
129
121
|
//# sourceMappingURL=analogjs-content-resources.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analogjs-content-resources.mjs","names":[],"sources":["../../resources/src/content-files-resource.ts","../../resources/src/content-file-resource.ts"],"sourcesContent":["import { resource, ResourceRef } from '@angular/core';\nimport type { ContentFile } from '../../src/lib/content-file';\nimport {\n filterByLocale,\n injectContentLocale,\n} from '../../src/lib/content-locale';\nimport type { InjectContentFilesFilterFunction } from '../../src/lib/inject-content-files';\nimport { injectContentListLoader } from '../../src/lib/content-list-loader';\n\nexport function contentFilesResource<Attributes extends Record<string, any>>(\n filterFn?: InjectContentFilesFilterFunction<Attributes> | undefined,\n): ResourceRef<ContentFile<Attributes>[] | undefined> {\n const contentListLoader = injectContentListLoader<Attributes>();\n const locale = injectContentLocale();\n const contentList = contentListLoader().then((items) => {\n let results = locale ? filterByLocale(items, locale) : items;\n if (filterFn) {\n results = results.filter(filterFn);\n }\n return results;\n });\n\n return resource({\n loader: () => contentList,\n });\n}\n","import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n computed,\n inject,\n resource,\n Signal,\n type ResourceRef,\n} from '@angular/core';\nimport { ActivatedRoute } from '@angular/router';\n\nimport { toSignal } from '@angular/core/rxjs-interop';\nimport { from } from 'rxjs';\nimport { map } from 'rxjs/operators';\nimport type { ContentFile } from '../../src/lib/content-file';\nimport { injectContentLocale } from '../../src/lib/content-locale';\nimport { ContentRenderer } from '../../src/lib/content-renderer';\nimport { FrontmatterValidationError } from '../../src/lib/frontmatter-validation-error';\nimport type {\n ContentFileLoader,\n ContentFileModule,\n} from '../../src/lib/parse-content-file';\nimport { injectContentFileLoader } from '../../src/lib/content-file-loader';\n\nexport interface ContentFileResourceResult<\n Attributes extends Record<string, any> = Record<string, any>,\n> extends ContentFile<Attributes | Record<string, never>> {\n toc: Array<{ id: string; level: number; text: string }>;\n}\n\ntype ContentFileParams =\n | Signal<string | { customFilename: string }>\n | Signal<string>\n | Signal<{ customFilename: string }>;\n\nasync function validateAttributes<TSchema extends StandardSchemaV1>(\n schema: TSchema,\n attributes: unknown,\n filename?: string,\n) {\n const result = await schema['~standard'].validate(attributes);\n if (result.issues) {\n throw new FrontmatterValidationError(result.issues, filename);\n }\n\n return result.value;\n}\n\nfunction getValidationFilename(filename: string): string {\n return filename.replace(/^\\/src\\/content\\//, '');\n}\n\nasync function getContentFile<\n Attributes extends Record<string, any> = Record<string, any>,\n>(\n contentFiles: Record<string, ContentFileLoader>,\n slug: string,\n fallback: string,\n locale?: string | null,\n schema?: StandardSchemaV1,\n): Promise<ContentFile<Attributes | Record<string, never>>> {\n // Normalize file keys so both \"/src/content/...\" and \"/<project>/src/content/...\" resolve.\n // This mirrors normalization used elsewhere in the content pipeline.\n const normalizedFiles: Record<string, ContentFileLoader> = {};\n const stemToKey: Record<string, string> = {};\n for (const [key, resolver] of Object.entries(contentFiles)) {\n const normalizedKey = key\n // replace any prefix up to the content directory with /src/content\n // use a non-greedy match so nested paths containing \"/content\" are preserved\n .replace(/^(?:.*?)\\/content(?=\\/)/, '/src/content')\n // normalize duplicate slashes\n .replace(/\\/{2,}/g, '/');\n normalizedFiles[normalizedKey] = resolver;\n // Index by bare filename stem so slug-only lookups work\n const stem = normalizedKey\n .split('/')\n .pop()\n ?.replace(/\\.[^.]+$/, '');\n if (stem && !stemToKey[stem]) {\n stemToKey[stem] = normalizedKey;\n }\n }\n\n // Try direct file first, then directory index variants, then bare slug via stem\n const base = `/src/content/${slug}`.replace(/\\/{2,}/g, '/');\n const candidates = [`${base}.md`, `${base}/index.md`];\n\n // Try locale-prefixed paths first, then fall back to unprefixed, then bare slug via stem\n const localeCandidates = locale\n ? candidates.map((c) =>\n c.replace('/src/content/', `/src/content/${locale}/`),\n )\n : [];\n const allCandidates = [...localeCandidates, ...candidates];\n const matchKey =\n allCandidates.find((k) => k in normalizedFiles) ?? stemToKey[slug];\n const contentFile = matchKey ? normalizedFiles[matchKey] : undefined;\n\n if (!contentFile) {\n return {\n filename: base,\n attributes: {},\n slug: '',\n content: fallback,\n } as ContentFile<Attributes | Record<string, never>>;\n }\n\n const resolvedBase = matchKey!.replace(/\\.md$/, '');\n const validationFilename = getValidationFilename(matchKey!);\n\n return contentFile().then(async (contentFile: string | ContentFileModule) => {\n if (typeof contentFile === 'string') {\n const { parseRawContentFile, parseRawContentFileAsync } =\n await import('../../src/lib/parse-raw-content-file');\n const { content, attributes } = schema\n ? await parseRawContentFileAsync(\n contentFile,\n schema,\n validationFilename,\n )\n : parseRawContentFile<Attributes>(contentFile);\n\n return {\n filename: resolvedBase,\n slug,\n attributes,\n content,\n } as ContentFile<Attributes | Record<string, never>>;\n }\n\n const attributes = schema\n ? await validateAttributes(\n schema,\n contentFile.metadata,\n validationFilename,\n )\n : contentFile.metadata;\n\n return {\n filename: resolvedBase,\n slug,\n attributes,\n content: contentFile.default,\n } as ContentFile<Attributes | Record<string, never>>;\n });\n}\n\n/**\n * Resource for requesting an individual content file.\n *\n * @example\n * ```typescript\n * // Without schema (existing behavior)\n * const post = contentFileResource<BlogAttributes>();\n *\n * // With schema validation\n * import * as v from 'valibot';\n * const BlogSchema = v.object({\n * title: v.string(),\n * date: v.pipe(v.string(), v.isoDate()),\n * });\n * const post = contentFileResource({ schema: BlogSchema });\n * ```\n */\nexport function contentFileResource<\n Attributes extends Record<string, any> = Record<string, any>,\n>(\n params?: ContentFileParams,\n fallback?: string,\n): ResourceRef<ContentFileResourceResult<Attributes> | undefined>;\n\nexport function contentFileResource<TSchema extends StandardSchemaV1>(options: {\n params?: ContentFileParams;\n fallback?: string;\n schema: TSchema;\n}): ResourceRef<\n | ContentFileResourceResult<\n StandardSchemaV1.InferOutput<TSchema> & Record<string, any>\n >\n | undefined\n>;\n\nexport function contentFileResource(\n paramsOrOptions?:\n | ContentFileParams\n | {\n params?: ContentFileParams;\n fallback?: string;\n schema?: StandardSchemaV1;\n },\n fallbackArg = 'No Content Found',\n) {\n // Detect options-object form vs legacy positional form\n const isOptionsObject =\n paramsOrOptions &&\n typeof paramsOrOptions === 'object' &&\n !('set' in paramsOrOptions) && // not a Signal\n ('schema' in paramsOrOptions ||\n 'params' in paramsOrOptions ||\n 'fallback' in paramsOrOptions);\n\n const params: ContentFileParams | undefined = isOptionsObject\n ? (paramsOrOptions as { params?: ContentFileParams }).params\n : (paramsOrOptions as ContentFileParams | undefined);\n const fallback: string = isOptionsObject\n ? ((paramsOrOptions as { fallback?: string }).fallback ??\n 'No Content Found')\n : fallbackArg;\n const schema: StandardSchemaV1 | undefined = isOptionsObject\n ? (paramsOrOptions as { schema?: StandardSchemaV1 }).schema\n : undefined;\n\n const loaderPromise = injectContentFileLoader();\n const contentRenderer = inject(ContentRenderer);\n const locale = injectContentLocale();\n const contentFilesMap = toSignal(from(loaderPromise()));\n const input =\n params ||\n toSignal(\n inject(ActivatedRoute).paramMap.pipe(\n map((params) => params.get('slug') as string),\n ),\n { requireSync: true },\n );\n\n return resource({\n params: computed(() => ({ input: input(), files: contentFilesMap() })),\n loader: async ({ params: resourceParams }) => {\n const { input: param, files } = resourceParams;\n\n if (typeof param === 'string') {\n if (param) {\n const file = await getContentFile(\n files!,\n param,\n fallback,\n locale,\n schema,\n );\n if (typeof file.content === 'string') {\n const rendered = (await contentRenderer.render(file.content)) as {\n toc?: Array<{ id: string; level: number; text: string }>;\n };\n return {\n ...file,\n toc: rendered.toc ?? [],\n };\n }\n return {\n ...file,\n toc: [],\n };\n }\n\n return {\n filename: '',\n slug: '',\n attributes: {},\n content: fallback,\n toc: [],\n };\n } else {\n const file = await getContentFile(\n files!,\n param.customFilename,\n fallback,\n locale,\n schema,\n );\n if (typeof file.content === 'string') {\n const rendered = (await contentRenderer.render(file.content)) as {\n toc?: Array<{ id: string; level: number; text: string }>;\n };\n return {\n ...file,\n toc: rendered.toc ?? [],\n };\n }\n return {\n ...file,\n toc: [],\n };\n }\n },\n });\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,qBACd,UAAmE;CAEnE,MAAM,oBAAoB,wBAAuB;CACjD,MAAM,SAAS,oBAAmB;CAClC,MAAM,cAAc,kBAAiB,CAAE,CAAC,MAAM,UAAS;EACrD,IAAI,UAAU,SAAS,eAAe,OAAO,MAAM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AO,UAAU;GAEhC,IAAI,OAAO,UAAU,UAAU;IAC7B,IAAI,OAAO;KACT,MAAM,OAAO,MAAM,eACjB,OACA,OACA,UACA,QACA,MAAM;KAER,IAAI,OAAO,KAAK,YAAY,UAAU;MACpC,MAAM,WAAY,MAAM,gBAAgB,OAAO,KAAK,OAAO;MAG3D,OAAO;OACL,GAAG;OACH,KAAK,SAAS,OAAO,CAAA;MACtB;KACH;KACA,OAAO;MACL,GAAG;MACH,KAAK,CAAA;KACN;IACH;IAEA,OAAO;KACL,UAAU;KACV,MAAM;KACN,YAAY,CAAA;KACZ,SAAS;KACT,KAAK,CAAA;IACN;GACH,OAAO;IACL,MAAM,OAAO,MAAM,eACjB,OACA,MAAM,gBACN,UACA,QACA,MAAM;IAER,IAAI,OAAO,KAAK,YAAY,UAAU;KACpC,MAAM,WAAY,MAAM,gBAAgB,OAAO,KAAK,OAAO;KAG3D,OAAO;MACL,GAAG;MACH,KAAK,SAAS,OAAO,CAAA;KACtB;IACH;IACA,OAAO;KACL,GAAG;KACH,KAAK,CAAA;IACN;GACH;EACF;CACD,CAAA;AACH"}
|
|
1
|
+
{"version":3,"file":"analogjs-content-resources.mjs","names":[],"sources":["../../resources/src/content-files-resource.ts","../../resources/src/content-file-resource.ts"],"sourcesContent":["import { resource, ResourceRef } from '@angular/core';\nimport type { ContentFile } from '../../src/lib/content-file';\nimport {\n filterByLocale,\n injectContentLocale,\n} from '../../src/lib/content-locale';\nimport type { InjectContentFilesFilterFunction } from '../../src/lib/inject-content-files';\nimport { injectContentListLoader } from '../../src/lib/content-list-loader';\n\nexport function contentFilesResource<Attributes extends Record<string, any>>(\n filterFn?: InjectContentFilesFilterFunction<Attributes> | undefined,\n): ResourceRef<ContentFile<Attributes>[] | undefined> {\n const contentListLoader = injectContentListLoader<Attributes>();\n const locale = injectContentLocale();\n\n return resource({\n loader: async () => {\n const items = await contentListLoader();\n const results = locale ? filterByLocale(items, locale) : items;\n return filterFn ? results.filter(filterFn) : results;\n },\n });\n}\n","import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n computed,\n inject,\n resource,\n Signal,\n type ResourceRef,\n} from '@angular/core';\nimport { ActivatedRoute } from '@angular/router';\n\nimport { toSignal } from '@angular/core/rxjs-interop';\nimport { map } from 'rxjs/operators';\nimport type { ContentFile } from '../../src/lib/content-file';\nimport { injectContentLocale } from '../../src/lib/content-locale';\nimport { ContentRenderer } from '../../src/lib/content-renderer';\nimport { FrontmatterValidationError } from '../../src/lib/frontmatter-validation-error';\nimport type {\n ContentFileLoader,\n ContentFileModule,\n} from '../../src/lib/parse-content-file';\nimport { injectContentFileLoader } from '../../src/lib/content-file-loader';\n\nexport interface ContentFileResourceResult<\n Attributes extends Record<string, any> = Record<string, any>,\n> extends ContentFile<Attributes | Record<string, never>> {\n toc: Array<{ id: string; level: number; text: string }>;\n}\n\ntype ContentFileParams =\n | Signal<string | { customFilename: string }>\n | Signal<string>\n | Signal<{ customFilename: string }>;\n\nasync function validateAttributes<TSchema extends StandardSchemaV1>(\n schema: TSchema,\n attributes: unknown,\n filename?: string,\n) {\n const result = await schema['~standard'].validate(attributes);\n if (result.issues) {\n throw new FrontmatterValidationError(result.issues, filename);\n }\n\n return result.value;\n}\n\nfunction getValidationFilename(filename: string): string {\n return filename.replace(/^\\/src\\/content\\//, '');\n}\n\nasync function getContentFile<\n Attributes extends Record<string, any> = Record<string, any>,\n>(\n contentFiles: Record<string, ContentFileLoader>,\n slug: string,\n fallback: string,\n locale?: string | null,\n schema?: StandardSchemaV1,\n): Promise<ContentFile<Attributes | Record<string, never>>> {\n // Normalize file keys so both \"/src/content/...\" and \"/<project>/src/content/...\" resolve.\n // This mirrors normalization used elsewhere in the content pipeline.\n const normalizedFiles: Record<string, ContentFileLoader> = {};\n const stemToKey: Record<string, string> = {};\n for (const [key, resolver] of Object.entries(contentFiles)) {\n const normalizedKey = key\n // replace any prefix up to the content directory with /src/content\n // use a non-greedy match so nested paths containing \"/content\" are preserved\n .replace(/^(?:.*?)\\/content(?=\\/)/, '/src/content')\n // normalize duplicate slashes\n .replace(/\\/{2,}/g, '/');\n normalizedFiles[normalizedKey] = resolver;\n // Index by bare filename stem so slug-only lookups work\n const stem = normalizedKey\n .split('/')\n .pop()\n ?.replace(/\\.[^.]+$/, '');\n if (stem && !stemToKey[stem]) {\n stemToKey[stem] = normalizedKey;\n }\n }\n\n // Try direct file first, then directory index variants, then bare slug via stem\n const base = `/src/content/${slug}`.replace(/\\/{2,}/g, '/');\n const candidates = [`${base}.md`, `${base}/index.md`];\n\n // Try locale-prefixed paths first, then fall back to unprefixed, then bare slug via stem\n const localeCandidates = locale\n ? candidates.map((c) =>\n c.replace('/src/content/', `/src/content/${locale}/`),\n )\n : [];\n const allCandidates = [...localeCandidates, ...candidates];\n const matchKey =\n allCandidates.find((k) => k in normalizedFiles) ?? stemToKey[slug];\n const contentFile = matchKey ? normalizedFiles[matchKey] : undefined;\n\n if (!contentFile) {\n return {\n filename: base,\n attributes: {},\n slug: '',\n content: fallback,\n } as ContentFile<Attributes | Record<string, never>>;\n }\n\n const resolvedBase = matchKey!.replace(/\\.md$/, '');\n const validationFilename = getValidationFilename(matchKey!);\n\n return contentFile().then(async (contentFile: string | ContentFileModule) => {\n if (typeof contentFile === 'string') {\n const { parseRawContentFile, parseRawContentFileAsync } =\n await import('../../src/lib/parse-raw-content-file');\n const { content, attributes } = schema\n ? await parseRawContentFileAsync(\n contentFile,\n schema,\n validationFilename,\n )\n : parseRawContentFile<Attributes>(contentFile);\n\n return {\n filename: resolvedBase,\n slug,\n attributes,\n content,\n } as ContentFile<Attributes | Record<string, never>>;\n }\n\n const attributes = schema\n ? await validateAttributes(\n schema,\n contentFile.metadata,\n validationFilename,\n )\n : contentFile.metadata;\n\n return {\n filename: resolvedBase,\n slug,\n attributes,\n content: contentFile.default,\n } as ContentFile<Attributes | Record<string, never>>;\n });\n}\n\n/**\n * Resource for requesting an individual content file.\n *\n * @example\n * ```typescript\n * // Without schema (existing behavior)\n * const post = contentFileResource<BlogAttributes>();\n *\n * // With schema validation\n * import * as v from 'valibot';\n * const BlogSchema = v.object({\n * title: v.string(),\n * date: v.pipe(v.string(), v.isoDate()),\n * });\n * const post = contentFileResource({ schema: BlogSchema });\n * ```\n */\nexport function contentFileResource<\n Attributes extends Record<string, any> = Record<string, any>,\n>(\n params?: ContentFileParams,\n fallback?: string,\n): ResourceRef<ContentFileResourceResult<Attributes> | undefined>;\n\nexport function contentFileResource<TSchema extends StandardSchemaV1>(options: {\n params?: ContentFileParams;\n fallback?: string;\n schema: TSchema;\n}): ResourceRef<\n | ContentFileResourceResult<\n StandardSchemaV1.InferOutput<TSchema> & Record<string, any>\n >\n | undefined\n>;\n\nexport function contentFileResource(\n paramsOrOptions?:\n | ContentFileParams\n | {\n params?: ContentFileParams;\n fallback?: string;\n schema?: StandardSchemaV1;\n },\n fallbackArg = 'No Content Found',\n) {\n // Detect options-object form vs legacy positional form\n const isOptionsObject =\n paramsOrOptions &&\n typeof paramsOrOptions === 'object' &&\n !('set' in paramsOrOptions) && // not a Signal\n ('schema' in paramsOrOptions ||\n 'params' in paramsOrOptions ||\n 'fallback' in paramsOrOptions);\n\n const params: ContentFileParams | undefined = isOptionsObject\n ? (paramsOrOptions as { params?: ContentFileParams }).params\n : (paramsOrOptions as ContentFileParams | undefined);\n const fallback: string = isOptionsObject\n ? ((paramsOrOptions as { fallback?: string }).fallback ??\n 'No Content Found')\n : fallbackArg;\n const schema: StandardSchemaV1 | undefined = isOptionsObject\n ? (paramsOrOptions as { schema?: StandardSchemaV1 }).schema\n : undefined;\n\n const loaderPromise = injectContentFileLoader();\n const contentRenderer = inject(ContentRenderer);\n const locale = injectContentLocale();\n const input =\n params ||\n toSignal(\n inject(ActivatedRoute).paramMap.pipe(\n map((params) => params.get('slug') as string),\n ),\n { requireSync: true },\n );\n\n return resource({\n params: computed(() => ({ input: input() })),\n loader: async ({ params: { input: param } }) => {\n const files = await loaderPromise();\n\n if (typeof param === 'string') {\n if (param) {\n const file = await getContentFile(\n files,\n param,\n fallback,\n locale,\n schema,\n );\n if (typeof file.content === 'string') {\n const rendered = (await contentRenderer.render(file.content)) as {\n toc?: Array<{ id: string; level: number; text: string }>;\n };\n return {\n ...file,\n toc: rendered.toc ?? [],\n };\n }\n return {\n ...file,\n toc: [],\n };\n }\n\n return {\n filename: '',\n slug: '',\n attributes: {},\n content: fallback,\n toc: [],\n };\n } else {\n const file = await getContentFile(\n files,\n param.customFilename,\n fallback,\n locale,\n schema,\n );\n if (typeof file.content === 'string') {\n const rendered = (await contentRenderer.render(file.content)) as {\n toc?: Array<{ id: string; level: number; text: string }>;\n };\n return {\n ...file,\n toc: rendered.toc ?? [],\n };\n }\n return {\n ...file,\n toc: [],\n };\n }\n },\n });\n}\n"],"mappings":";;;;;;;AASA,SAAgB,qBACd,UAAmE;CAEnE,MAAM,oBAAoB,wBAAuB;CACjD,MAAM,SAAS,oBAAmB;CAElC,OAAO,SAAS,EACd,QAAQ,YAAW;EACjB,MAAM,QAAQ,MAAM,kBAAiB;EACrC,MAAM,UAAU,SAAS,eAAe,OAAO,MAAM,IAAI;EACzD,OAAO,WAAW,QAAQ,OAAO,QAAQ,IAAI;CAC/C,EACD,CAAA;AACH;;ACWA,eAAe,mBACb,QACA,YACA,UAAiB;CAEjB,MAAM,SAAS,MAAM,OAAO,YAAY,CAAC,SAAS,UAAU;CAC5D,IAAI,OAAO,QACT,MAAM,IAAI,2BAA2B,OAAO,QAAQ,QAAQ;CAG9D,OAAO,OAAO;AAChB;AAEA,SAAS,sBAAsB,UAAgB;CAC7C,OAAO,SAAS,QAAQ,qBAAqB,EAAE;AACjD;AAEA,eAAe,eAGb,cACA,MACA,UACA,QACA,QAAyB;CAIzB,MAAM,kBAAqD,CAAA;CAC3D,MAAM,YAAoC,CAAA;CAC1C,KAAK,MAAM,CAAC,KAAK,aAAa,OAAO,QAAQ,YAAY,GAAG;EAC1D,MAAM,gBAAgB,IAGnB,QAAQ,2BAA2B,cAAc,CAAC,CAElD,QAA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