@analogjs/content 3.0.0-alpha.5 → 3.0.0-alpha.50

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.
Files changed (63) hide show
  1. package/devtools/package.json +4 -0
  2. package/fesm2022/analogjs-content-devtools.mjs +162 -0
  3. package/fesm2022/analogjs-content-devtools.mjs.map +1 -0
  4. package/fesm2022/analogjs-content-md4x.mjs +291 -0
  5. package/fesm2022/analogjs-content-md4x.mjs.map +1 -0
  6. package/fesm2022/analogjs-content-mdc.mjs +170 -0
  7. package/fesm2022/analogjs-content-mdc.mjs.map +1 -0
  8. package/fesm2022/analogjs-content-og.mjs.map +1 -0
  9. package/fesm2022/analogjs-content-prism-highlighter.mjs +5 -4
  10. package/fesm2022/analogjs-content-prism-highlighter.mjs.map +1 -0
  11. package/fesm2022/analogjs-content-resources.mjs +39 -25
  12. package/fesm2022/analogjs-content-resources.mjs.map +1 -0
  13. package/fesm2022/analogjs-content-shiki-highlighter.mjs +1 -1
  14. package/fesm2022/analogjs-content-shiki-highlighter.mjs.map +1 -0
  15. package/fesm2022/analogjs-content.mjs +42 -354
  16. package/fesm2022/analogjs-content.mjs.map +1 -0
  17. package/fesm2022/content-list-loader.mjs +260 -0
  18. package/fesm2022/content-list-loader.mjs.map +1 -0
  19. package/fesm2022/content-renderer.mjs +128 -0
  20. package/fesm2022/content-renderer.mjs.map +1 -0
  21. package/fesm2022/marked-content-highlighter.mjs +40 -0
  22. package/fesm2022/marked-content-highlighter.mjs.map +1 -0
  23. package/fesm2022/parse-raw-content-file.mjs +45 -0
  24. package/fesm2022/parse-raw-content-file.mjs.map +1 -0
  25. package/md4x/package.json +4 -0
  26. package/mdc/package.json +4 -0
  27. package/package.json +71 -36
  28. package/plugin/migrations.json +1 -1
  29. package/plugin/package.json +2 -21
  30. package/plugin/src/index.d.ts +3 -1
  31. package/plugin/src/index.d.ts.map +1 -0
  32. package/plugin/src/index.js +5 -4
  33. package/plugin/src/index.js.map +1 -0
  34. package/plugin/src/migrations/update-markdown-version/compat.d.ts +5 -2
  35. package/plugin/src/migrations/update-markdown-version/compat.d.ts.map +1 -0
  36. package/plugin/src/migrations/update-markdown-version/compat.js +8 -7
  37. package/plugin/src/migrations/update-markdown-version/compat.js.map +1 -0
  38. package/plugin/src/migrations/update-markdown-version/update-markdown-version.d.ts +6 -2
  39. package/plugin/src/migrations/update-markdown-version/update-markdown-version.d.ts.map +1 -0
  40. package/plugin/src/migrations/update-markdown-version/update-markdown-version.js +18 -20
  41. package/plugin/src/migrations/update-markdown-version/update-markdown-version.js.map +1 -0
  42. package/src/lib/devtools/content-devtools-client.ts +215 -0
  43. package/src/lib/devtools/content-devtools.styles.css +194 -0
  44. package/types/devtools/src/index.d.ts +1 -0
  45. package/types/md4x/src/index.d.ts +5 -0
  46. package/types/md4x/src/lib/md4x-content-renderer.service.d.ts +33 -0
  47. package/types/md4x/src/lib/md4x-wasm-content-renderer.service.d.ts +16 -0
  48. package/types/md4x/src/lib/provide-md4x.d.ts +26 -0
  49. package/types/md4x/src/lib/streaming-markdown-renderer.d.ts +21 -0
  50. package/types/mdc/src/index.d.ts +2 -0
  51. package/types/mdc/src/lib/mdc-component-registry.d.ts +25 -0
  52. package/types/mdc/src/lib/mdc-renderer.directive.d.ts +33 -0
  53. package/types/prism-highlighter/src/lib/prism-highlighter.d.ts +1 -1
  54. package/types/resources/src/content-file-resource.d.ts +32 -7
  55. package/types/resources/src/content-files-resource.d.ts +2 -1
  56. package/types/src/index.d.ts +6 -3
  57. package/types/src/lib/content-locale.d.ts +68 -0
  58. package/types/src/lib/devtools/content-devtools-plugin.d.ts +23 -0
  59. package/types/src/lib/devtools/content-devtools-renderer.d.ts +23 -0
  60. package/types/src/lib/devtools/index.d.ts +23 -0
  61. package/types/src/lib/get-content-files.d.ts +19 -4
  62. package/types/src/lib/parse-raw-content-file.d.ts +15 -1
  63. package/plugin/README.md +0 -11
@@ -0,0 +1,260 @@
1
+ import * as i0 from "@angular/core";
2
+ import { Injectable, InjectionToken, inject, signal, ɵPendingTasksInternal } from "@angular/core";
3
+ //#region packages/content/src/lib/content-locale.ts
4
+ /**
5
+ * Token for the active content locale.
6
+ * Provided via `withLocale()` in `provideContent()`.
7
+ *
8
+ * When set, `injectContentFiles()` filters to content matching this locale,
9
+ * and `injectContent()` resolves locale-prefixed content paths first.
10
+ */
11
+ var CONTENT_LOCALE = new InjectionToken("@analogjs/content Locale");
12
+ /**
13
+ * Injects the content locale, returning null if not configured.
14
+ */
15
+ function injectContentLocale() {
16
+ return inject(CONTENT_LOCALE, { optional: true });
17
+ }
18
+ /**
19
+ * Content feature that sets the active locale for content resolution.
20
+ *
21
+ * When provided, content APIs become locale-aware:
22
+ * - `injectContentFiles()` filters to files in the locale subdirectory
23
+ * or with a matching `locale` frontmatter attribute.
24
+ * - `injectContent()` tries locale-prefixed paths first
25
+ * (e.g., `content/fr/blog/post.md` before `content/blog/post.md`).
26
+ *
27
+ * Usage:
28
+ * ```typescript
29
+ * // With loader — runs in injection context
30
+ * provideContent(
31
+ * withMarkdownRenderer(),
32
+ * withLocale({ loadLocale: injectLocale }),
33
+ * )
34
+ *
35
+ * // Static locale
36
+ * provideContent(
37
+ * withMarkdownRenderer(),
38
+ * withLocale('fr'),
39
+ * )
40
+ * ```
41
+ */
42
+ function withLocale(locale) {
43
+ if (typeof locale === "string") return {
44
+ provide: CONTENT_LOCALE,
45
+ useValue: locale
46
+ };
47
+ return {
48
+ provide: CONTENT_LOCALE,
49
+ useFactory: locale.loadLocale
50
+ };
51
+ }
52
+ /**
53
+ * Filters content files by locale using map-based key lookup.
54
+ *
55
+ * Matching rules:
56
+ * 1. Frontmatter `locale` attribute matches the active locale.
57
+ * 2. File is in the active locale subdirectory (e.g., `/content/fr/blog/post`).
58
+ * 3. File has no locale marker and no localized variant exists — included as universal content.
59
+ *
60
+ * Files in a different locale's subdirectory are always excluded.
61
+ */
62
+ function filterByLocale(files, locale) {
63
+ const localePrefix = `/content/${locale}/`;
64
+ const allLocalePrefixes = /* @__PURE__ */ new Set();
65
+ for (const file of files) {
66
+ const match = file.filename.match(/\/content\/([a-z]{2}(?:-[a-zA-Z]+)?)\//);
67
+ if (match) allLocalePrefixes.add(`/content/${match[1]}/`);
68
+ }
69
+ const localizedBasePaths = /* @__PURE__ */ new Set();
70
+ for (const file of files) if (file.filename.includes(localePrefix)) localizedBasePaths.add(file.filename.replace(localePrefix, "/content/"));
71
+ return files.filter((file) => {
72
+ if (file.attributes["locale"]) return file.attributes["locale"] === locale;
73
+ if (file.filename.includes(localePrefix)) return true;
74
+ for (const prefix of allLocalePrefixes) if (prefix !== localePrefix && file.filename.includes(prefix)) return false;
75
+ return !localizedBasePaths.has(file.filename);
76
+ });
77
+ }
78
+ /**
79
+ * Prepends locale-prefixed candidates before the standard candidates
80
+ * for content file map key lookup.
81
+ */
82
+ function withLocaleCandidates(candidates, locale) {
83
+ if (!locale) return candidates;
84
+ return [...candidates.map((c) => c.replace("/src/content/", `/src/content/${locale}/`)), ...candidates];
85
+ }
86
+ //#endregion
87
+ //#region packages/content/src/lib/get-content-files.ts
88
+ /**
89
+ * These bindings are rewritten at build time:
90
+ * - `ANALOG_CONTENT_FILE_LIST` by `@analogjs/platform`'s content plugin,
91
+ * which substitutes the empty-object initializer with the frontmatter
92
+ * map for discovered content files.
93
+ * - `ANALOG_CONTENT_ROUTE_FILES` by `@analogjs/platform`'s router plugin,
94
+ * which substitutes the empty-object initializer with the lazy-import
95
+ * map for discovered content files. The router plugin already rewrites
96
+ * a same-named binding exported from `@analogjs/router/content`; it
97
+ * matches this module for free because its filter keys off `_ROUTE_FILES`.
98
+ *
99
+ * They are declared as `export const` at module scope so the bundler treats
100
+ * them as public module bindings and cannot constant-fold them away during
101
+ * library build. Previously these lived as local consts inside each getter,
102
+ * and Rolldown collapsed `const X = {}; return X;` into `return {};`, which
103
+ * erased the rewrite target the platform plugins rely on.
104
+ */
105
+ var ANALOG_CONTENT_FILE_LIST = {};
106
+ var ANALOG_CONTENT_ROUTE_FILES = {};
107
+ /**
108
+ * Returns the list of content files by filename with ?analog-content-list=true.
109
+ * We use the query param to transform the return into an array of
110
+ * just front matter attributes.
111
+ */
112
+ var getContentFilesList = () => ANALOG_CONTENT_FILE_LIST;
113
+ /**
114
+ * Returns the lazy loaded content files for lookups.
115
+ */
116
+ var getContentFiles = () => ANALOG_CONTENT_ROUTE_FILES;
117
+ //#endregion
118
+ //#region packages/content/src/lib/content-files-list-token.ts
119
+ function getSlug(filename) {
120
+ const base = (filename.split(/[/\\]/).pop() || "").trim().replace(/\.[^./\\]+$/, "");
121
+ return base === "index" ? "" : base;
122
+ }
123
+ var CONTENT_FILES_LIST_TOKEN = new InjectionToken("@analogjs/content Content Files List", {
124
+ providedIn: "root",
125
+ factory() {
126
+ const contentFiles = getContentFilesList();
127
+ return Object.keys(contentFiles).map((filename) => {
128
+ const attributes = contentFiles[filename];
129
+ const slug = attributes["slug"];
130
+ return {
131
+ filename,
132
+ attributes,
133
+ slug: slug ? encodeURI(slug) : encodeURI(getSlug(filename))
134
+ };
135
+ });
136
+ }
137
+ });
138
+ //#endregion
139
+ //#region packages/content/src/lib/content-files-token.ts
140
+ var CONTENT_FILES_TOKEN = new InjectionToken("@analogjs/content Content Files", {
141
+ providedIn: "root",
142
+ factory() {
143
+ const allFiles = { ...getContentFiles() };
144
+ const contentFilesList = inject(CONTENT_FILES_LIST_TOKEN);
145
+ const lookup = {};
146
+ contentFilesList.forEach((item) => {
147
+ const contentFilename = item.filename.replace(/(.*?)\/content/, "/src/content");
148
+ const fileParts = contentFilename.split("/");
149
+ const filePath = fileParts.slice(0, fileParts.length - 1).join("/");
150
+ const fileNameParts = fileParts[fileParts.length - 1].split(".");
151
+ const ext = fileNameParts[fileNameParts.length - 1];
152
+ let slug = item.slug ?? "";
153
+ if (slug === "") slug = "index";
154
+ const subdirRoot = fileParts.length > 4 ? fileParts.slice(0, 4).join("/") : "/src/content";
155
+ lookup[contentFilename] = `${slug.includes("/") ? `${subdirRoot}/${slug}` : `${filePath}/${slug}`}.${ext}`.replace(/\/{2,}/g, "/");
156
+ });
157
+ const objectUsingSlugAttribute = {};
158
+ Object.entries(allFiles).forEach((entry) => {
159
+ const filename = entry[0];
160
+ const value = entry[1];
161
+ const newFilename = lookup[filename.replace(/^\/(.*?)\/content/, "/src/content")];
162
+ if (newFilename !== void 0) {
163
+ const objectFilename = newFilename.replace(/^\/(.*?)\/content/, "/src/content");
164
+ objectUsingSlugAttribute[objectFilename] = value;
165
+ }
166
+ });
167
+ return objectUsingSlugAttribute;
168
+ }
169
+ });
170
+ new InjectionToken("@analogjs/content Content Files", {
171
+ providedIn: "root",
172
+ factory() {
173
+ return signal(inject(CONTENT_FILES_TOKEN));
174
+ }
175
+ });
176
+ //#endregion
177
+ //#region packages/content/src/lib/render-task.service.ts
178
+ var RenderTaskService = class RenderTaskService {
179
+ #pendingTasks = inject(ɵPendingTasksInternal);
180
+ addRenderTask() {
181
+ return this.#pendingTasks.add();
182
+ }
183
+ clearRenderTask(clear) {
184
+ if (typeof clear === "function") clear();
185
+ else if (typeof this.#pendingTasks.remove === "function") this.#pendingTasks.remove(clear);
186
+ }
187
+ static {
188
+ this.ɵfac = i0.ɵɵngDeclareFactory({
189
+ minVersion: "12.0.0",
190
+ version: "21.2.8",
191
+ ngImport: i0,
192
+ type: RenderTaskService,
193
+ deps: [],
194
+ target: i0.ɵɵFactoryTarget.Injectable
195
+ });
196
+ }
197
+ static {
198
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
199
+ minVersion: "12.0.0",
200
+ version: "21.2.8",
201
+ ngImport: i0,
202
+ type: RenderTaskService
203
+ });
204
+ }
205
+ };
206
+ i0.ɵɵngDeclareClassMetadata({
207
+ minVersion: "12.0.0",
208
+ version: "21.2.8",
209
+ ngImport: i0,
210
+ type: RenderTaskService,
211
+ decorators: [{ type: Injectable }]
212
+ });
213
+ //#endregion
214
+ //#region packages/content/src/lib/inject-content-files.ts
215
+ function injectContentFiles(filterFn) {
216
+ const renderTaskService = inject(RenderTaskService);
217
+ const task = renderTaskService.addRenderTask();
218
+ const allContentFiles = inject(CONTENT_FILES_LIST_TOKEN);
219
+ const locale = inject(CONTENT_LOCALE, { optional: true });
220
+ renderTaskService.clearRenderTask(task);
221
+ let results = allContentFiles;
222
+ if (locale) results = filterByLocale(results, locale);
223
+ if (filterFn) results = results.filter(filterFn);
224
+ return results;
225
+ }
226
+ function injectContentFilesMap() {
227
+ return inject(CONTENT_FILES_TOKEN);
228
+ }
229
+ //#endregion
230
+ //#region packages/content/src/lib/content-file-loader.ts
231
+ var CONTENT_FILE_LOADER = new InjectionToken("@analogjs/content/resource File Loader");
232
+ function injectContentFileLoader() {
233
+ return inject(CONTENT_FILE_LOADER);
234
+ }
235
+ function withContentFileLoader() {
236
+ return {
237
+ provide: CONTENT_FILE_LOADER,
238
+ useFactory() {
239
+ return async () => injectContentFilesMap();
240
+ }
241
+ };
242
+ }
243
+ //#endregion
244
+ //#region packages/content/src/lib/content-list-loader.ts
245
+ var CONTENT_LIST_LOADER = new InjectionToken("@analogjs/content/resource List Loader");
246
+ function injectContentListLoader() {
247
+ return inject(CONTENT_LIST_LOADER);
248
+ }
249
+ function withContentListLoader() {
250
+ return {
251
+ provide: CONTENT_LIST_LOADER,
252
+ useFactory() {
253
+ return async () => injectContentFiles();
254
+ }
255
+ };
256
+ }
257
+ //#endregion
258
+ export { injectContentFileLoader as a, injectContentFilesMap as c, CONTENT_LOCALE as d, filterByLocale as f, withLocaleCandidates as h, CONTENT_FILE_LOADER as i, RenderTaskService as l, withLocale as m, injectContentListLoader as n, withContentFileLoader as o, injectContentLocale as p, withContentListLoader as r, injectContentFiles as s, CONTENT_LIST_LOADER as t, CONTENT_FILES_TOKEN as u };
259
+
260
+ //# sourceMappingURL=content-list-loader.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-list-loader.mjs","names":["#pendingTasks"],"sources":["../../src/lib/content-locale.ts","../../src/lib/get-content-files.ts","../../src/lib/content-files-list-token.ts","../../src/lib/content-files-token.ts","../../src/lib/render-task.service.ts","../../src/lib/inject-content-files.ts","../../src/lib/content-file-loader.ts","../../src/lib/content-list-loader.ts"],"sourcesContent":["import { InjectionToken, inject, Provider } from '@angular/core';\n\nimport { ContentFile } from './content-file';\n\n/**\n * Token for the active content locale.\n * Provided via `withLocale()` in `provideContent()`.\n *\n * When set, `injectContentFiles()` filters to content matching this locale,\n * and `injectContent()` resolves locale-prefixed content paths first.\n */\nexport const CONTENT_LOCALE: InjectionToken<string> =\n new InjectionToken<string>('@analogjs/content Locale');\n\n/**\n * Injects the content locale, returning null if not configured.\n */\nexport function injectContentLocale(): string | null {\n return inject(CONTENT_LOCALE, { optional: true });\n}\n\nexport interface ContentLocaleOptions {\n /**\n * Function that returns the active locale.\n * Runs in injection context so `inject()` can be used to read\n * from other tokens (e.g., a LOCALE token from a router package).\n *\n * ```typescript\n * withLocale({ loadLocale: injectLocale })\n * withLocale({ loadLocale: () => navigator.language.split('-')[0] })\n * ```\n */\n loadLocale: () => string | null;\n}\n\n/**\n * Content feature that sets the active locale for content resolution.\n *\n * When provided, content APIs become locale-aware:\n * - `injectContentFiles()` filters to files in the locale subdirectory\n * or with a matching `locale` frontmatter attribute.\n * - `injectContent()` tries locale-prefixed paths first\n * (e.g., `content/fr/blog/post.md` before `content/blog/post.md`).\n *\n * Usage:\n * ```typescript\n * // With loader — runs in injection context\n * provideContent(\n * withMarkdownRenderer(),\n * withLocale({ loadLocale: injectLocale }),\n * )\n *\n * // Static locale\n * provideContent(\n * withMarkdownRenderer(),\n * withLocale('fr'),\n * )\n * ```\n */\nexport function withLocale(locale: string | ContentLocaleOptions): Provider {\n if (typeof locale === 'string') {\n return { provide: CONTENT_LOCALE, useValue: locale };\n }\n\n return { provide: CONTENT_LOCALE, useFactory: locale.loadLocale };\n}\n\n/**\n * Filters content files by locale using map-based key lookup.\n *\n * Matching rules:\n * 1. Frontmatter `locale` attribute matches the active locale.\n * 2. File is in the active locale subdirectory (e.g., `/content/fr/blog/post`).\n * 3. File has no locale marker and no localized variant exists — included as universal content.\n *\n * Files in a different locale's subdirectory are always excluded.\n */\nexport function filterByLocale<T extends Record<string, any>>(\n files: ContentFile<T>[],\n locale: string,\n): ContentFile<T>[] {\n const localePrefix = `/content/${locale}/`;\n\n // Collect all locale prefixes present in the file set\n const allLocalePrefixes = new Set<string>();\n for (const file of files) {\n const match = file.filename.match(/\\/content\\/([a-z]{2}(?:-[a-zA-Z]+)?)\\//);\n if (match) {\n allLocalePrefixes.add(`/content/${match[1]}/`);\n }\n }\n\n // Build set of base paths that have a localized variant for the active locale\n const localizedBasePaths = new Set<string>();\n for (const file of files) {\n if (file.filename.includes(localePrefix)) {\n localizedBasePaths.add(file.filename.replace(localePrefix, '/content/'));\n }\n }\n\n return files.filter((file) => {\n // Frontmatter locale attribute takes priority\n if (file.attributes['locale']) {\n return file.attributes['locale'] === locale;\n }\n // File is in the active locale subdirectory — include\n if (file.filename.includes(localePrefix)) {\n return true;\n }\n // File is in a different locale's subdirectory — exclude\n for (const prefix of allLocalePrefixes) {\n if (prefix !== localePrefix && file.filename.includes(prefix)) {\n return false;\n }\n }\n // Universal content — include only if no localized variant exists\n return !localizedBasePaths.has(file.filename);\n });\n}\n\n/**\n * Prepends locale-prefixed candidates before the standard candidates\n * for content file map key lookup.\n */\nexport function withLocaleCandidates(\n candidates: string[],\n locale: string | null | undefined,\n): string[] {\n if (!locale) {\n return candidates;\n }\n const localeCandidates = candidates.map((c) =>\n c.replace('/src/content/', `/src/content/${locale}/`),\n );\n return [...localeCandidates, ...candidates];\n}\n","/**\n * These bindings are rewritten at build time:\n * - `ANALOG_CONTENT_FILE_LIST` by `@analogjs/platform`'s content plugin,\n * which substitutes the empty-object initializer with the frontmatter\n * map for discovered content files.\n * - `ANALOG_CONTENT_ROUTE_FILES` by `@analogjs/platform`'s router plugin,\n * which substitutes the empty-object initializer with the lazy-import\n * map for discovered content files. The router plugin already rewrites\n * a same-named binding exported from `@analogjs/router/content`; it\n * matches this module for free because its filter keys off `_ROUTE_FILES`.\n *\n * They are declared as `export const` at module scope so the bundler treats\n * them as public module bindings and cannot constant-fold them away during\n * library build. Previously these lived as local consts inside each getter,\n * and Rolldown collapsed `const X = {}; return X;` into `return {};`, which\n * erased the rewrite target the platform plugins rely on.\n */\n\nexport const ANALOG_CONTENT_FILE_LIST = {};\nexport const ANALOG_CONTENT_ROUTE_FILES = {};\n\n/**\n * Returns the list of content files by filename with ?analog-content-list=true.\n * We use the query param to transform the return into an array of\n * just front matter attributes.\n */\nexport const getContentFilesList = () =>\n ANALOG_CONTENT_FILE_LIST as Record<string, Record<string, any>>;\n\n/**\n * Returns the lazy loaded content files for lookups.\n */\nexport const getContentFiles = () =>\n ANALOG_CONTENT_ROUTE_FILES as Record<string, () => Promise<string>>;\n","import { InjectionToken } from '@angular/core';\nimport { ContentFile } from './content-file';\nimport { getContentFilesList } from './get-content-files';\n\nfunction getSlug(filename: string) {\n // Extract the last path segment without its extension.\n // Handles names with dots like [[...slug]].md by stripping only the final extension.\n const lastSegment = (filename.split(/[/\\\\]/).pop() || '').trim();\n const base = lastSegment.replace(/\\.[^./\\\\]+$/, ''); // strip only the final extension\n // Treat index.md as index route => empty slug\n return base === 'index' ? '' : base;\n}\n\nexport const CONTENT_FILES_LIST_TOKEN: InjectionToken<ContentFile[]> =\n new InjectionToken<ContentFile[]>('@analogjs/content Content Files List', {\n providedIn: 'root',\n factory() {\n const contentFiles = getContentFilesList();\n\n return Object.keys(contentFiles).map((filename) => {\n const attributes = contentFiles[filename];\n const slug = attributes['slug'];\n\n return {\n filename,\n attributes,\n slug: slug ? encodeURI(slug) : encodeURI(getSlug(filename)),\n };\n });\n },\n });\n","import { InjectionToken, Signal, inject, signal } from '@angular/core';\n\nimport { getContentFiles } from './get-content-files';\nimport { CONTENT_FILES_LIST_TOKEN } from './content-files-list-token';\n\nexport const CONTENT_FILES_TOKEN: InjectionToken<\n Record<string, () => Promise<string>>\n> = new InjectionToken<Record<string, () => Promise<string>>>(\n '@analogjs/content Content Files',\n {\n providedIn: 'root',\n factory() {\n const contentFiles = getContentFiles();\n const allFiles = { ...contentFiles };\n const contentFilesList = inject(CONTENT_FILES_LIST_TOKEN);\n\n const lookup: Record<string, string> = {};\n contentFilesList.forEach((item) => {\n const contentFilename = item.filename.replace(\n /(.*?)\\/content/,\n '/src/content',\n );\n const fileParts = contentFilename.split('/');\n const filePath = fileParts.slice(0, fileParts.length - 1).join('/');\n const fileNameParts = fileParts[fileParts.length - 1].split('.');\n const ext = fileNameParts[fileNameParts.length - 1];\n let slug = (item.slug ?? '') as string;\n // Default empty slug to 'index'\n if (slug === '') {\n slug = 'index';\n }\n // Slugs with path separators are scoped to the file's top-level\n // subdirectory (e.g. `/src/content/docs`) rather than absolute root,\n // so nested files keep resolving through `subdirectory` lookups.\n // Files directly under `/src/content` keep the original root-relative\n // behavior since they have no subdirectory of their own.\n const subdirRoot =\n fileParts.length > 4\n ? fileParts.slice(0, 4).join('/')\n : '/src/content';\n const newBase = slug.includes('/')\n ? `${subdirRoot}/${slug}`\n : `${filePath}/${slug}`;\n lookup[contentFilename] = `${newBase}.${ext}`.replace(/\\/{2,}/g, '/');\n });\n\n const objectUsingSlugAttribute: Record<string, () => Promise<string>> =\n {};\n Object.entries(allFiles).forEach((entry) => {\n const filename = entry[0];\n const value = entry[1];\n const strippedFilename = filename.replace(\n /^\\/(.*?)\\/content/,\n '/src/content',\n );\n\n const newFilename = lookup[strippedFilename];\n if (newFilename !== undefined) {\n const objectFilename = newFilename.replace(\n /^\\/(.*?)\\/content/,\n '/src/content',\n );\n objectUsingSlugAttribute[objectFilename] =\n value as () => Promise<string>;\n }\n });\n\n return objectUsingSlugAttribute;\n },\n },\n);\n\nexport const CONTENT_FILES_MAP_TOKEN: InjectionToken<\n Signal<Record<string, () => Promise<string>>>\n> = new InjectionToken<Signal<Record<string, () => Promise<string>>>>(\n '@analogjs/content Content Files',\n {\n providedIn: 'root',\n factory() {\n return signal(inject(CONTENT_FILES_TOKEN));\n },\n },\n);\n","import { Injectable, inject } from '@angular/core';\nimport { ɵPendingTasksInternal as ɵPendingTasks } from '@angular/core';\n\n@Injectable()\nexport class RenderTaskService {\n #pendingTasks = inject(ɵPendingTasks);\n\n addRenderTask(): number {\n return this.#pendingTasks.add();\n }\n\n clearRenderTask(clear: number | (() => void)): void {\n if (typeof clear === 'function') {\n clear();\n } else if (typeof (this.#pendingTasks as any).remove === 'function') {\n (this.#pendingTasks as any).remove(clear);\n }\n }\n}\n","import { inject } from '@angular/core';\n\nimport { ContentFile } from './content-file';\nimport { CONTENT_FILES_LIST_TOKEN } from './content-files-list-token';\nimport { CONTENT_FILES_TOKEN } from './content-files-token';\nimport { CONTENT_LOCALE, filterByLocale } from './content-locale';\nimport { RenderTaskService } from './render-task.service';\n\nexport function injectContentFiles<Attributes extends Record<string, any>>(\n filterFn?: InjectContentFilesFilterFunction<Attributes>,\n): ContentFile<Attributes>[] {\n const renderTaskService = inject(RenderTaskService);\n const task = renderTaskService.addRenderTask();\n const allContentFiles = inject(\n CONTENT_FILES_LIST_TOKEN,\n ) as ContentFile<Attributes>[];\n const locale = inject(CONTENT_LOCALE, { optional: true });\n renderTaskService.clearRenderTask(task);\n\n let results = allContentFiles;\n\n if (locale) {\n results = filterByLocale(results, locale);\n }\n\n if (filterFn) {\n results = results.filter(filterFn);\n }\n\n return results;\n}\n\nexport type InjectContentFilesFilterFunction<T extends Record<string, any>> = (\n value: ContentFile<T>,\n index: number,\n array: ContentFile<T>[],\n) => boolean;\n\nexport function injectContentFilesMap(): Record<string, () => Promise<string>> {\n return inject(CONTENT_FILES_TOKEN);\n}\n","import { InjectionToken, Provider } from '@angular/core';\nimport { inject } from '@angular/core';\n\nimport { injectContentFilesMap } from './inject-content-files';\n\ntype ContentFileLoaderFunction = () => Promise<\n Record<string, () => Promise<string>>\n>;\n\nexport const CONTENT_FILE_LOADER: InjectionToken<ContentFileLoaderFunction> =\n new InjectionToken<ContentFileLoaderFunction>(\n '@analogjs/content/resource File Loader',\n );\n\nexport function injectContentFileLoader() {\n return inject(CONTENT_FILE_LOADER) as ContentFileLoaderFunction;\n}\n\nexport function withContentFileLoader(): Provider {\n return {\n provide: CONTENT_FILE_LOADER,\n useFactory() {\n return async () => injectContentFilesMap();\n },\n };\n}\n","import { InjectionToken, Provider } from '@angular/core';\nimport { inject } from '@angular/core';\n\nimport { ContentFile } from './content-file';\nimport { injectContentFiles } from './inject-content-files';\n\ntype ContentListLoaderFunction<Attributes extends Record<string, any>> =\n () => Promise<ContentFile<Attributes>[]>;\n\nexport const CONTENT_LIST_LOADER: InjectionToken<\n ContentListLoaderFunction<any>\n> = new InjectionToken<ContentListLoaderFunction<any>>(\n '@analogjs/content/resource List Loader',\n);\n\nexport function injectContentListLoader<\n Attributes extends Record<string, any>,\n>() {\n return inject(CONTENT_LIST_LOADER) as ContentListLoaderFunction<Attributes>;\n}\n\nexport function withContentListLoader(): Provider {\n return {\n provide: CONTENT_LIST_LOADER,\n useFactory() {\n return async () => injectContentFiles();\n },\n };\n}\n"],"mappings":";;;;;;;;;;AAWA,IAAa,iBACX,IAAI,eAAuB,2BAA2B;;;;AAKxD,SAAgB,sBAAqC;AACnD,QAAO,OAAO,gBAAkB,EAAA,UAAU,MAAO,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCnD,SAAgB,WAAW,QAAiD;AAC1E,KAAI,OAAO,WAAW,SACpB,QAAO;EAAA,SAAA;EAAA,UAAA;EAAA;AAA2B,QAAA;EAAU,SAAA;EAAA,YAAA,OAAA;EAAA;;;;;;;;;;;;;;;;;AAgBzC,MAAA,MAIC,mBAAe,IAAY,YAAO,MAAA,GAAA,GAAA;;CAMtC,MAAI,qCAAO,IAAA,KAAA;AACT,MAAA,MAAA,QAAkB,MAAA,KAAA,KAAA,SAAA,SAAA,aAAA,CAAA,oBAAA,IAAA,KAAA,SAAA,QAAA,cAAA,YAAA,CAAA;AAOpB,QAAS,MAAA,QAAS,SAAS;;AAQzB,MAAO,K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OAAO,SAAS;AAGpC,QAAO;;AAST,SAAgB,wBAA+D;AAC7E,QAAO,OAAO,oBAAoB;;;;AC9BpC,IAAa,sBACX,IAAI,eACF,yCACD;AAEH,SAAgB,0BAA0B;AACxC,QAAO,OAAO,oBAAoB;;AAGpC,SAAgB,wBAAkC;AAChD,QAAO;EACL,SAAS;EACT,aAAa;AACJ,UAAA,YAAY,uBAAuB;;EAE7C;;;;ACfH,IAAa,sBAET,IAAI,eACN,yCACD;AAED,SAAgB,0BAEZ;AACF,QAAO,OAAO,oBAAoB;;AAGpC,SAAgB,wBAAkC;AAChD,QAAO;EACL,SAAS;EACT,aAAa;AACJ,UAAA,YAAY,oBAAoB;;EAE1C"}
@@ -0,0 +1,128 @@
1
+ import * as i0 from "@angular/core";
2
+ import { Injectable, TransferState, inject, makeStateKey } from "@angular/core";
3
+ //#region packages/content/src/lib/content-renderer.ts
4
+ var ContentRenderer = class ContentRenderer {
5
+ async render(content) {
6
+ return {
7
+ content,
8
+ toc: []
9
+ };
10
+ }
11
+ getContentHeadings(_content) {
12
+ return [];
13
+ }
14
+ enhance() {}
15
+ static {
16
+ this.ɵfac = i0.ɵɵngDeclareFactory({
17
+ minVersion: "12.0.0",
18
+ version: "21.2.8",
19
+ ngImport: i0,
20
+ type: ContentRenderer,
21
+ deps: [],
22
+ target: i0.ɵɵFactoryTarget.Injectable
23
+ });
24
+ }
25
+ static {
26
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
27
+ minVersion: "12.0.0",
28
+ version: "21.2.8",
29
+ ngImport: i0,
30
+ type: ContentRenderer
31
+ });
32
+ }
33
+ };
34
+ i0.ɵɵngDeclareClassMetadata({
35
+ minVersion: "12.0.0",
36
+ version: "21.2.8",
37
+ ngImport: i0,
38
+ type: ContentRenderer,
39
+ decorators: [{ type: Injectable }]
40
+ });
41
+ var NoopContentRenderer = class {
42
+ constructor() {
43
+ this.transferState = inject(TransferState);
44
+ this.contentId = 0;
45
+ }
46
+ /**
47
+ * Generates a hash from the content string
48
+ * to be used with the transfer state
49
+ */
50
+ generateHash(str) {
51
+ let hash = 0;
52
+ for (let i = 0, len = str.length; i < len; i++) {
53
+ const chr = str.charCodeAt(i);
54
+ hash = (hash << 5) - hash + chr;
55
+ hash |= 0;
56
+ }
57
+ return hash;
58
+ }
59
+ async render(content) {
60
+ this.contentId = this.generateHash(content);
61
+ const toc = this.getContentHeadings(content);
62
+ const key = makeStateKey(`content-headings-${this.contentId}`);
63
+ return {
64
+ content,
65
+ toc: this.transferState.get(key, toc)
66
+ };
67
+ }
68
+ enhance() {}
69
+ getContentHeadings(content) {
70
+ return this.extractHeadings(content);
71
+ }
72
+ extractHeadings(content) {
73
+ const markdownHeadings = this.extractHeadingsFromMarkdown(content);
74
+ if (markdownHeadings.length > 0) return markdownHeadings;
75
+ return this.extractHeadingsFromHtml(content);
76
+ }
77
+ extractHeadingsFromMarkdown(content) {
78
+ const lines = content.split("\n");
79
+ const toc = [];
80
+ const slugCounts = /* @__PURE__ */ new Map();
81
+ for (const line of lines) {
82
+ const match = /^(#{1,6})\s+(.+?)\s*$/.exec(line);
83
+ if (!match) continue;
84
+ const level = match[1].length;
85
+ const text = match[2].trim();
86
+ if (!text) continue;
87
+ const baseSlug = text.toLowerCase().replace(/[^\w\s-]/g, "").trim().replace(/\s+/g, "-");
88
+ const count = slugCounts.get(baseSlug) ?? 0;
89
+ slugCounts.set(baseSlug, count + 1);
90
+ const id = count === 0 ? baseSlug : `${baseSlug}-${count}`;
91
+ toc.push({
92
+ id,
93
+ level,
94
+ text
95
+ });
96
+ }
97
+ return toc;
98
+ }
99
+ extractHeadingsFromHtml(content) {
100
+ const toc = [];
101
+ const slugCounts = /* @__PURE__ */ new Map();
102
+ for (const match of content.matchAll(/<h([1-6])([^>]*)>([\s\S]*?)<\/h\1>/gi)) {
103
+ const level = Number(match[1]);
104
+ const attrs = match[2] ?? "";
105
+ const text = (match[3] ?? "").replace(/<[^>]+>/g, "").trim();
106
+ if (!text) continue;
107
+ const idMatch = /\sid=(['"])(.*?)\1/i.exec(attrs) ?? /\sid=([^\s>]+)/i.exec(attrs);
108
+ let id = idMatch?.[2] ?? idMatch?.[1] ?? "";
109
+ if (!id) id = this.makeSlug(text, slugCounts);
110
+ toc.push({
111
+ id,
112
+ level,
113
+ text
114
+ });
115
+ }
116
+ return toc;
117
+ }
118
+ makeSlug(text, slugCounts) {
119
+ const baseSlug = text.toLowerCase().replace(/[^\w\s-]/g, "").trim().replace(/\s+/g, "-");
120
+ const count = slugCounts.get(baseSlug) ?? 0;
121
+ slugCounts.set(baseSlug, count + 1);
122
+ return count === 0 ? baseSlug : `${baseSlug}-${count}`;
123
+ }
124
+ };
125
+ //#endregion
126
+ export { NoopContentRenderer as n, ContentRenderer as t };
127
+
128
+ //# sourceMappingURL=content-renderer.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-renderer.mjs","names":[],"sources":["../../src/lib/content-renderer.ts"],"sourcesContent":["/// <reference types=\"vite/client\" />\n\nimport { Injectable, TransferState, inject, makeStateKey } from '@angular/core';\n\nexport type TableOfContentItem = {\n id: string;\n level: number; // starts at 1\n text: string;\n};\n\nexport type RenderedContent = {\n content: string;\n toc: TableOfContentItem[];\n};\n\n@Injectable()\nexport abstract class ContentRenderer {\n async render(content: string): Promise<RenderedContent> {\n return { content, toc: [] };\n }\n\n // Backward-compatible API for consumers that read headings directly.\n getContentHeadings(_content: string): TableOfContentItem[] {\n return [];\n }\n\n // eslint-disable-next-line\n enhance(): void {}\n}\n\nexport class NoopContentRenderer implements ContentRenderer {\n private readonly transferState = inject(TransferState);\n private contentId = 0;\n\n /**\n * Generates a hash from the content string\n * to be used with the transfer state\n */\n private generateHash(str: string) {\n let hash = 0;\n for (let i = 0, len = str.length; i < len; i++) {\n const chr = str.charCodeAt(i);\n hash = (hash << 5) - hash + chr;\n hash |= 0; // Convert to 32bit integer\n }\n return hash;\n }\n\n async render(content: string): Promise<RenderedContent> {\n this.contentId = this.generateHash(content);\n const toc = this.getContentHeadings(content);\n const key = makeStateKey<TableOfContentItem[]>(\n `content-headings-${this.contentId}`,\n );\n\n if (import.meta.env.SSR === true) {\n this.transferState.set(key, toc);\n return { content, toc };\n }\n\n return {\n content,\n toc: this.transferState.get(key, toc),\n };\n }\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n enhance(): void {}\n\n getContentHeadings(content: string): TableOfContentItem[] {\n return this.extractHeadings(content);\n }\n\n private extractHeadings(content: string): TableOfContentItem[] {\n const markdownHeadings = this.extractHeadingsFromMarkdown(content);\n if (markdownHeadings.length > 0) {\n return markdownHeadings;\n }\n\n const htmlHeadings = this.extractHeadingsFromHtml(content);\n return htmlHeadings;\n }\n\n private extractHeadingsFromMarkdown(content: string): TableOfContentItem[] {\n const lines = content.split('\\n');\n const toc: TableOfContentItem[] = [];\n const slugCounts = new Map<string, number>();\n\n for (const line of lines) {\n const match = /^(#{1,6})\\s+(.+?)\\s*$/.exec(line);\n if (!match) {\n continue;\n }\n\n const level = match[1].length;\n const text = match[2].trim();\n if (!text) {\n continue;\n }\n\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 const id = count === 0 ? baseSlug : `${baseSlug}-${count}`;\n\n toc.push({ id, level, text });\n }\n\n return toc;\n }\n\n private extractHeadingsFromHtml(content: string): TableOfContentItem[] {\n const toc: TableOfContentItem[] = [];\n const slugCounts = new Map<string, number>();\n const headingRegex = /<h([1-6])([^>]*)>([\\s\\S]*?)<\\/h\\1>/gi;\n\n for (const match of content.matchAll(headingRegex)) {\n const level = Number(match[1]);\n const attrs = match[2] ?? '';\n const rawInner = match[3] ?? '';\n const text = rawInner.replace(/<[^>]+>/g, '').trim();\n if (!text) {\n continue;\n }\n\n const idMatch =\n /\\sid=(['\"])(.*?)\\1/i.exec(attrs) ?? /\\sid=([^\\s>]+)/i.exec(attrs);\n let id = idMatch?.[2] ?? idMatch?.[1] ?? '';\n if (!id) {\n id = this.makeSlug(text, slugCounts);\n }\n\n toc.push({ id, level, text });\n }\n\n return toc;\n }\n\n private 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}\n"],"mappings":";;;IAiBQ,kBAAA,MAAA,gBAAkD;CACtD,MAAO,OAAA,SAAA;AAAE,SAAA;GAAA;GAAA,KAAA,EAAA;GAAA;;;AAIX,SAAA,EAAA;;CAKA,UAAgB;;;;;;;;;;;;kBAZjB,sBAAY;GAAA,YAAA;GAAA,SAAA;GAAA,UAAA;GAAA,MAAA;GAAA,CAAA;;;AAeb,GAAA,yBAAa;CAAA,YAA+C;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAA,YAAA,CAAA,EAAA,MAAA,YAAA,CAAA;;gCAEtC;;;;;;;;;CAShB,aAAY,KAAI;EAChB,IAAQ,OAAQ;AAChB,OAAQ,IAAA,IAAA,GAAA,MAAA,IAAA,QAAA,IAAA,KAAA,KAAA;;AAEH,WAAA,QAAA,KAAA,OAAA;;;AAIF,SAAA;;CAEL,MAAM,OAAM,SAAA;AAIR,OAAO,YAAS,KAAQ,aAAM,QAAA;EAC3B,MAAA,MAAA,KAAc,mBAAa,QAAA;EAChC,MAAO,MAAA,aAAA,oBAAA,KAAA,YAAA;AAGT,SAAO;GACL;GACK,KAAK,KAAA,cAAuB,IAAA,KAAA,IAAA;GAClC;;CAKH,UAAA;CACE,mBAAY,SAAgB;;;CAI5B,gBAAM,SAAmB;EACrB,MAAA,mBAA0B,KAAG,4BAAA,QAAA;AAC/B,MAAO,iBAAA,SAAA,EAAA,QAAA;SAIF,KAAA,wBAAA,QAAA;;CAIP,4BAA4B,SAAK;EAC3B,MAA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Injectable } from "@angular/core";
3
+ //#region packages/content/src/lib/marked-content-highlighter.ts
4
+ var MarkedContentHighlighter = class MarkedContentHighlighter {
5
+ static {
6
+ this.ɵfac = i0.ɵɵngDeclareFactory({
7
+ minVersion: "12.0.0",
8
+ version: "21.2.8",
9
+ ngImport: i0,
10
+ type: MarkedContentHighlighter,
11
+ deps: [],
12
+ target: i0.ɵɵFactoryTarget.Injectable
13
+ });
14
+ }
15
+ static {
16
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
17
+ minVersion: "12.0.0",
18
+ version: "21.2.8",
19
+ ngImport: i0,
20
+ type: MarkedContentHighlighter
21
+ });
22
+ }
23
+ };
24
+ i0.ɵɵngDeclareClassMetadata({
25
+ minVersion: "12.0.0",
26
+ version: "21.2.8",
27
+ ngImport: i0,
28
+ type: MarkedContentHighlighter,
29
+ decorators: [{ type: Injectable }]
30
+ });
31
+ function withHighlighter(provider) {
32
+ return {
33
+ provide: MarkedContentHighlighter,
34
+ ...provider
35
+ };
36
+ }
37
+ //#endregion
38
+ export { withHighlighter as n, MarkedContentHighlighter as t };
39
+
40
+ //# sourceMappingURL=marked-content-highlighter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"marked-content-highlighter.mjs","names":[],"sources":["../../src/lib/marked-content-highlighter.ts"],"sourcesContent":["import {\n AbstractType,\n Injectable,\n Provider,\n ProviderToken,\n Type,\n} from '@angular/core';\n\n@Injectable()\nexport abstract class MarkedContentHighlighter {\n augmentCodeBlock?(code: string, lang: string): string;\n abstract getHighlightExtension(): import('marked').MarkedExtension;\n}\n\nexport function withHighlighter(\n provider: (\n | { useValue: MarkedContentHighlighter }\n | {\n useClass:\n | Type<MarkedContentHighlighter>\n | AbstractType<MarkedContentHighlighter>;\n }\n | { useFactory: (...deps: any[]) => MarkedContentHighlighter }\n ) & { deps?: ProviderToken<any>[] },\n): Provider {\n return { provide: MarkedContentHighlighter, ...provider } as Provider;\n}\n"],"mappings":";;;AASO,IAAA,2BAAA,MAAA,yBAAe;;oCADrB;GAAA,YAAY;GAAA,SAAA;GAAA,UAAA;GAAA,MAAA;GAAA,MAAA,EAAA;GAAA,QAAA,GAAA,gBAAA;GAAA,CAAA;;;;;;;;;;;AAiBX,GAAA,yBAAO;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAA,YAAA,CAAA,EAAW,MAAA,YAA6B,CAAA;CAAA,CAAA;SAAU,gBAAA,UAAA"}
@@ -0,0 +1,45 @@
1
+ import fm from "front-matter";
2
+ //#region packages/content/src/lib/parse-raw-content-file.ts
3
+ var FrontmatterValidationError = class extends Error {
4
+ constructor(issues, filename) {
5
+ const issueMessages = issues.map((i) => {
6
+ const path = i.path ? ` at "${i.path.map((p) => typeof p === "object" ? p.key : p).join(".")}"` : "";
7
+ return ` - ${i.message}${path}`;
8
+ }).join("\n");
9
+ const prefix = filename ? `"${filename}" f` : "F";
10
+ super(`${prefix}rontmatter validation failed:\n${issueMessages}`);
11
+ this.issues = issues;
12
+ this.filename = filename;
13
+ this.name = "FrontmatterValidationError";
14
+ }
15
+ };
16
+ function parseRawContentFile(rawContentFile, schema, filename) {
17
+ const { body, attributes } = fm(rawContentFile);
18
+ if (schema) {
19
+ const result = schema["~standard"].validate(attributes);
20
+ if (result != null && typeof result.then === "function") throw new Error("parseRawContentFile does not support async schema validation. Use parseRawContentFileAsync() for async schemas.");
21
+ const syncResult = result;
22
+ if (syncResult.issues) throw new FrontmatterValidationError(syncResult.issues, filename);
23
+ return {
24
+ content: body,
25
+ attributes: syncResult.value
26
+ };
27
+ }
28
+ return {
29
+ content: body,
30
+ attributes
31
+ };
32
+ }
33
+ async function parseRawContentFileAsync(rawContentFile, schema, filename) {
34
+ const { body, attributes } = fm(rawContentFile);
35
+ const result = await schema["~standard"].validate(attributes);
36
+ if (result.issues) throw new FrontmatterValidationError(result.issues, filename);
37
+ return {
38
+ content: body,
39
+ attributes: result.value
40
+ };
41
+ }
42
+ //#endregion
43
+ export { parseRawContentFile as n, parseRawContentFileAsync as r, FrontmatterValidationError as t };
44
+
45
+ //# sourceMappingURL=parse-raw-content-file.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-raw-content-file.mjs","names":[],"sources":["../../src/lib/parse-raw-content-file.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport fm from 'front-matter';\n\nexport class FrontmatterValidationError extends Error {\n constructor(\n public readonly issues: ReadonlyArray<StandardSchemaV1.Issue>,\n public readonly filename?: string,\n ) {\n const issueMessages = issues\n .map((i) => {\n const path = i.path\n ? ` at \"${i.path.map((p) => (typeof p === 'object' ? p.key : p)).join('.')}\"`\n : '';\n return ` - ${i.message}${path}`;\n })\n .join('\\n');\n const prefix = filename ? `\"${filename}\" f` : 'F';\n super(`${prefix}rontmatter validation failed:\\n${issueMessages}`);\n this.name = 'FrontmatterValidationError';\n }\n}\n\nexport function parseRawContentFile<\n Attributes extends Record<string, any> = Record<string, any>,\n>(rawContentFile: string): { content: string; attributes: Attributes };\n\nexport function parseRawContentFile<TSchema extends StandardSchemaV1>(\n rawContentFile: string,\n schema: TSchema,\n filename?: string,\n): { content: string; attributes: StandardSchemaV1.InferOutput<TSchema> };\n\nexport function parseRawContentFile(\n rawContentFile: string,\n schema?: StandardSchemaV1,\n filename?: string,\n): { content: string; attributes: unknown } {\n const { body, attributes } = fm(rawContentFile);\n\n if (schema) {\n const result = schema['~standard'].validate(attributes);\n if (\n result != null &&\n typeof (result as PromiseLike<unknown>).then === 'function'\n ) {\n throw new Error(\n 'parseRawContentFile does not support async schema validation. ' +\n 'Use parseRawContentFileAsync() for async schemas.',\n );\n }\n const syncResult = result as StandardSchemaV1.Result<\n StandardSchemaV1.InferOutput<typeof schema>\n >;\n if (syncResult.issues) {\n throw new FrontmatterValidationError(syncResult.issues, filename);\n }\n return { content: body, attributes: syncResult.value };\n }\n\n return { content: body, attributes };\n}\n\nexport async function parseRawContentFileAsync<\n TSchema extends StandardSchemaV1,\n>(\n rawContentFile: string,\n schema: TSchema,\n filename?: string,\n): Promise<{\n content: string;\n attributes: StandardSchemaV1.InferOutput<TSchema>;\n}> {\n const { body, attributes } = fm(rawContentFile);\n const result = await schema['~standard'].validate(attributes);\n if (result.issues) {\n throw new FrontmatterValidationError(result.issues, filename);\n }\n return { content: body, attributes: result.value };\n}\n"],"mappings":";;AAGA,IAAa,6BAAb,cAAgD,MAAM;CACpD,YACE,QACA,UACA;EACM,MAAA,gBAAgB,OAEZ,KAAS,MAAA;GAGR,MAAO,OAAE,EAAA,OAEP,QAAA,EAAA,KAAA,KAAA,MAAA,OAAA,MAAA,WAAA,EAAA,MAAA,EAAA,CAAA,KAAA,IAAA,CAAA,KACE;AACN,UAAO,OAAA,EAAA,UAAA;IAZA,CACA,KAAA,KAAA;EAYX,MAAO,SAAA,WAAA,IAAA,SAAA,OAAA;;;AAcT,OAAA,WAAS;AAKR,OAAE,OAAM;;;AAIZ,SACY,oBACF,gBAAyC,QACjD,UAAA;CACA,MAAM,EAAA,MAAI,eACR,GAAA,eAAA;;EAIE,MAAA,SAAa,OAAA,aAAA,SAAA,WAAA;AAGf,MAAA,UAAW,QACP,OAAI,OAAA,SAAA,WAAA,OAAA,IAAA,MAAA,kHAEL;EAAiB,MAAA,aAAuB;AAAO,MAAA,WAAA,OAAA,OAAA,IAAA,2BAAA,WAAA,QAAA,SAAA;AAG/C,SAAS;GAAA,SAAA;GAAA,YAAA,WAAA;GAAA;;AAAkB,QAAA;EAAA,SAAA;EAAA;EAAA;;AAGtC,eAAsB,yBAGpB,gBACA,QACA,UAIC;CACD,MAAQ,EAAA,MAAM,eAAkB,GAAA,eAAe;CAC/C,MAAM,SAAS,MAAM,OAAO,aAAa,SAAS,WAAW;AAC7D,KAAI,OAAO,OACH,OAAI,IAAA,2BAA2B,OAAO,QAAQ,SAAS;AAE/D,QAAO;EAAA,SAAA;EAAA,YAAA,OAAA;EAAA"}
@@ -0,0 +1,4 @@
1
+ {
2
+ "module": "../fesm2022/analogjs-content-md4x.mjs",
3
+ "typings": "../types/md4x/src/index.d.ts"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "module": "../fesm2022/analogjs-content-mdc.mjs",
3
+ "typings": "../types/mdc/src/index.d.ts"
4
+ }