@analogjs/content 3.0.0-alpha.3 → 3.0.0-alpha.31
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/devtools/package.json +4 -0
- package/fesm2022/analogjs-content-devtools.mjs +162 -0
- package/fesm2022/analogjs-content-devtools.mjs.map +1 -0
- package/fesm2022/analogjs-content-md4x.mjs +291 -0
- package/fesm2022/analogjs-content-md4x.mjs.map +1 -0
- package/fesm2022/analogjs-content-mdc.mjs +170 -0
- package/fesm2022/analogjs-content-mdc.mjs.map +1 -0
- package/fesm2022/analogjs-content-og.mjs.map +1 -0
- package/fesm2022/analogjs-content-prism-highlighter.mjs +5 -4
- package/fesm2022/analogjs-content-prism-highlighter.mjs.map +1 -0
- package/fesm2022/analogjs-content-resources.mjs +39 -25
- package/fesm2022/analogjs-content-resources.mjs.map +1 -0
- package/fesm2022/analogjs-content-shiki-highlighter.mjs +1 -1
- package/fesm2022/analogjs-content-shiki-highlighter.mjs.map +1 -0
- package/fesm2022/analogjs-content.mjs +29 -353
- package/fesm2022/analogjs-content.mjs.map +1 -0
- package/fesm2022/content-list-loader.mjs +248 -0
- package/fesm2022/content-list-loader.mjs.map +1 -0
- package/fesm2022/content-renderer.mjs +128 -0
- package/fesm2022/content-renderer.mjs.map +1 -0
- package/fesm2022/marked-content-highlighter.mjs +40 -0
- package/fesm2022/marked-content-highlighter.mjs.map +1 -0
- package/fesm2022/parse-raw-content-file.mjs +45 -0
- package/fesm2022/parse-raw-content-file.mjs.map +1 -0
- package/md4x/package.json +4 -0
- package/mdc/package.json +4 -0
- package/package.json +72 -36
- package/plugin/migrations.json +1 -1
- package/plugin/package.json +2 -22
- package/plugin/src/index.d.ts +3 -1
- package/plugin/src/index.d.ts.map +1 -0
- package/plugin/src/index.js +5 -4
- package/plugin/src/index.js.map +1 -0
- package/plugin/src/migrations/update-markdown-version/compat.d.ts +5 -2
- package/plugin/src/migrations/update-markdown-version/compat.d.ts.map +1 -0
- package/plugin/src/migrations/update-markdown-version/compat.js +8 -7
- package/plugin/src/migrations/update-markdown-version/compat.js.map +1 -0
- package/plugin/src/migrations/update-markdown-version/update-markdown-version.d.ts +6 -2
- package/plugin/src/migrations/update-markdown-version/update-markdown-version.d.ts.map +1 -0
- package/plugin/src/migrations/update-markdown-version/update-markdown-version.js +18 -20
- package/plugin/src/migrations/update-markdown-version/update-markdown-version.js.map +1 -0
- package/src/lib/devtools/content-devtools-client.ts +215 -0
- package/src/lib/devtools/content-devtools.styles.css +194 -0
- package/types/devtools/src/index.d.ts +1 -0
- package/types/md4x/src/index.d.ts +5 -0
- package/types/md4x/src/lib/md4x-content-renderer.service.d.ts +33 -0
- package/types/md4x/src/lib/md4x-wasm-content-renderer.service.d.ts +16 -0
- package/types/md4x/src/lib/provide-md4x.d.ts +26 -0
- package/types/md4x/src/lib/streaming-markdown-renderer.d.ts +21 -0
- package/types/mdc/src/index.d.ts +2 -0
- package/types/mdc/src/lib/mdc-component-registry.d.ts +25 -0
- package/types/mdc/src/lib/mdc-renderer.directive.d.ts +33 -0
- package/types/prism-highlighter/src/lib/prism-highlighter.d.ts +1 -1
- package/types/resources/src/content-file-resource.d.ts +32 -7
- package/types/resources/src/content-files-resource.d.ts +2 -1
- package/types/src/index.d.ts +6 -3
- package/types/src/lib/content-locale.d.ts +68 -0
- package/types/src/lib/devtools/content-devtools-plugin.d.ts +23 -0
- package/types/src/lib/devtools/content-devtools-renderer.d.ts +23 -0
- package/types/src/lib/devtools/index.d.ts +23 -0
- package/types/src/lib/parse-raw-content-file.d.ts +15 -1
- package/plugin/README.md +0 -11
- package/plugin/src/migrations/update-markdown-renderer-feature/compat.d.ts +0 -3
- package/plugin/src/migrations/update-markdown-renderer-feature/compat.js +0 -8
- package/plugin/src/migrations/update-markdown-renderer-feature/update-markdown-renderer-feature.d.ts +0 -2
- package/plugin/src/migrations/update-markdown-renderer-feature/update-markdown-renderer-feature.js +0 -48
|
@@ -0,0 +1,248 @@
|
|
|
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
|
+
* Returns the list of content files by filename with ?analog-content-list=true.
|
|
90
|
+
* We use the query param to transform the return into an array of
|
|
91
|
+
* just front matter attributes.
|
|
92
|
+
*
|
|
93
|
+
* @returns
|
|
94
|
+
*/
|
|
95
|
+
var getContentFilesList = () => {
|
|
96
|
+
return {};
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Returns the lazy loaded content files for lookups.
|
|
100
|
+
*
|
|
101
|
+
* @returns
|
|
102
|
+
*/
|
|
103
|
+
var getContentFiles = () => {
|
|
104
|
+
return {};
|
|
105
|
+
};
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region packages/content/src/lib/content-files-list-token.ts
|
|
108
|
+
function getSlug(filename) {
|
|
109
|
+
const base = (filename.split(/[/\\]/).pop() || "").trim().replace(/\.[^./\\]+$/, "");
|
|
110
|
+
return base === "index" ? "" : base;
|
|
111
|
+
}
|
|
112
|
+
var CONTENT_FILES_LIST_TOKEN = new InjectionToken("@analogjs/content Content Files List", {
|
|
113
|
+
providedIn: "root",
|
|
114
|
+
factory() {
|
|
115
|
+
const contentFiles = getContentFilesList();
|
|
116
|
+
return Object.keys(contentFiles).map((filename) => {
|
|
117
|
+
const attributes = contentFiles[filename];
|
|
118
|
+
const slug = attributes["slug"];
|
|
119
|
+
return {
|
|
120
|
+
filename,
|
|
121
|
+
attributes,
|
|
122
|
+
slug: slug ? encodeURI(slug) : encodeURI(getSlug(filename))
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region packages/content/src/lib/content-files-token.ts
|
|
129
|
+
var CONTENT_FILES_TOKEN = new InjectionToken("@analogjs/content Content Files", {
|
|
130
|
+
providedIn: "root",
|
|
131
|
+
factory() {
|
|
132
|
+
const allFiles = { ...getContentFiles() };
|
|
133
|
+
const contentFilesList = inject(CONTENT_FILES_LIST_TOKEN);
|
|
134
|
+
const lookup = {};
|
|
135
|
+
contentFilesList.forEach((item) => {
|
|
136
|
+
const contentFilename = item.filename.replace(/(.*?)\/content/, "/src/content");
|
|
137
|
+
const fileParts = contentFilename.split("/");
|
|
138
|
+
const filePath = fileParts.slice(0, fileParts.length - 1).join("/");
|
|
139
|
+
const fileNameParts = fileParts[fileParts.length - 1].split(".");
|
|
140
|
+
const ext = fileNameParts[fileNameParts.length - 1];
|
|
141
|
+
let slug = item.slug ?? "";
|
|
142
|
+
if (slug === "") slug = "index";
|
|
143
|
+
lookup[contentFilename] = `${slug.includes("/") ? `/src/content/${slug}` : `${filePath}/${slug}`}.${ext}`.replace(/\/{2,}/g, "/");
|
|
144
|
+
});
|
|
145
|
+
const objectUsingSlugAttribute = {};
|
|
146
|
+
Object.entries(allFiles).forEach((entry) => {
|
|
147
|
+
const filename = entry[0];
|
|
148
|
+
const value = entry[1];
|
|
149
|
+
const newFilename = lookup[filename.replace(/^\/(.*?)\/content/, "/src/content")];
|
|
150
|
+
if (newFilename !== void 0) {
|
|
151
|
+
const objectFilename = newFilename.replace(/^\/(.*?)\/content/, "/src/content");
|
|
152
|
+
objectUsingSlugAttribute[objectFilename] = value;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
return objectUsingSlugAttribute;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
new InjectionToken("@analogjs/content Content Files", {
|
|
159
|
+
providedIn: "root",
|
|
160
|
+
factory() {
|
|
161
|
+
return signal(inject(CONTENT_FILES_TOKEN));
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region packages/content/src/lib/render-task.service.ts
|
|
166
|
+
var RenderTaskService = class RenderTaskService {
|
|
167
|
+
#pendingTasks = inject(ɵPendingTasksInternal);
|
|
168
|
+
addRenderTask() {
|
|
169
|
+
return this.#pendingTasks.add();
|
|
170
|
+
}
|
|
171
|
+
clearRenderTask(clear) {
|
|
172
|
+
if (typeof clear === "function") clear();
|
|
173
|
+
else if (typeof this.#pendingTasks.remove === "function") this.#pendingTasks.remove(clear);
|
|
174
|
+
}
|
|
175
|
+
static {
|
|
176
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
177
|
+
minVersion: "12.0.0",
|
|
178
|
+
version: "21.2.8",
|
|
179
|
+
ngImport: i0,
|
|
180
|
+
type: RenderTaskService,
|
|
181
|
+
deps: [],
|
|
182
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
static {
|
|
186
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
187
|
+
minVersion: "12.0.0",
|
|
188
|
+
version: "21.2.8",
|
|
189
|
+
ngImport: i0,
|
|
190
|
+
type: RenderTaskService
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
195
|
+
minVersion: "12.0.0",
|
|
196
|
+
version: "21.2.8",
|
|
197
|
+
ngImport: i0,
|
|
198
|
+
type: RenderTaskService,
|
|
199
|
+
decorators: [{ type: Injectable }]
|
|
200
|
+
});
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region packages/content/src/lib/inject-content-files.ts
|
|
203
|
+
function injectContentFiles(filterFn) {
|
|
204
|
+
const renderTaskService = inject(RenderTaskService);
|
|
205
|
+
const task = renderTaskService.addRenderTask();
|
|
206
|
+
const allContentFiles = inject(CONTENT_FILES_LIST_TOKEN);
|
|
207
|
+
const locale = inject(CONTENT_LOCALE, { optional: true });
|
|
208
|
+
renderTaskService.clearRenderTask(task);
|
|
209
|
+
let results = allContentFiles;
|
|
210
|
+
if (locale) results = filterByLocale(results, locale);
|
|
211
|
+
if (filterFn) results = results.filter(filterFn);
|
|
212
|
+
return results;
|
|
213
|
+
}
|
|
214
|
+
function injectContentFilesMap() {
|
|
215
|
+
return inject(CONTENT_FILES_TOKEN);
|
|
216
|
+
}
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region packages/content/src/lib/content-file-loader.ts
|
|
219
|
+
var CONTENT_FILE_LOADER = new InjectionToken("@analogjs/content/resource File Loader");
|
|
220
|
+
function injectContentFileLoader() {
|
|
221
|
+
return inject(CONTENT_FILE_LOADER);
|
|
222
|
+
}
|
|
223
|
+
function withContentFileLoader() {
|
|
224
|
+
return {
|
|
225
|
+
provide: CONTENT_FILE_LOADER,
|
|
226
|
+
useFactory() {
|
|
227
|
+
return async () => injectContentFilesMap();
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region packages/content/src/lib/content-list-loader.ts
|
|
233
|
+
var CONTENT_LIST_LOADER = new InjectionToken("@analogjs/content/resource List Loader");
|
|
234
|
+
function injectContentListLoader() {
|
|
235
|
+
return inject(CONTENT_LIST_LOADER);
|
|
236
|
+
}
|
|
237
|
+
function withContentListLoader() {
|
|
238
|
+
return {
|
|
239
|
+
provide: CONTENT_LIST_LOADER,
|
|
240
|
+
useFactory() {
|
|
241
|
+
return async () => injectContentFiles();
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
//#endregion
|
|
246
|
+
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 };
|
|
247
|
+
|
|
248
|
+
//# 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 * 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 *\n * @returns\n */\nexport const getContentFilesList = () => {\n const ANALOG_CONTENT_FILE_LIST = {};\n\n return ANALOG_CONTENT_FILE_LIST as Record<string, Record<string, any>>;\n};\n\n/**\n * Returns the lazy loaded content files for lookups.\n *\n * @returns\n */\nexport const getContentFiles = (): Record<string, () => Promise<string>> => {\n const ANALOG_CONTENT_ROUTE_FILES = {};\n\n return ANALOG_CONTENT_ROUTE_FILES as Record<string, () => Promise<string>>;\n};\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 // If slug contains path separators, treat it as root-relative to /src/content\n const newBase = slug.includes('/')\n ? `/src/content/${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: CONTEN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AAA;;CAGjC,gBAAgB,OAAoC;AAC9C,MAAA,OAAO,UAAU,WACZ,QAAA;WAEDA,OAAsB,MAAA,aAAa,WAAA,WAAA,OAAA,aAAA,OAAA,MAAA;;;oCAZlC;GAAA,YAAA;GAAA,SAAA;GAAA,UAAA;GAAA,MAAA;GAAA,MAAA,EAAA;GAAA,QAAA,GAAA,gBAAA;GAAA,CAAA;;;;;;;;;;;;;;;;;;;;ACKb,SAAgB,mBACd,UAC2B;CAC3B,MAAM,oBAAoB,OAAO,kBAAkB;CACnD,MAAM,OAAO,kBAAkB,eAAe;CAC9C,MAAM,kBAAkB,OACtB,yBACD;CACD,MAAM,SAAS,OAAO,gBAAkB,EAAA,UAAU,MAAO,CAAA;AACzD,mBAAkB,gBAAgB,KAAK;CAEvC,IAAI,UAAU;AAEd,KAAI,OACF,WAAU,eAAe,SAAS,OAAO;AAG3C,KAAI,SACF,WAAU,QAAQ,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,MAA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OAAA,KAAA;IAAA;IAAA;IAAA;IAAA,CAAA;;AAAW,SAAA;;;EAGxB,MAAO,WAAA,KAAA,aAAA,CAGQ,QAAc,aAAyC,GAAA,CAChE,MAAW,CAKX,QAAQ,QAAW,IAAI;EAC7B,MAAW,QAAI,WAAU,IAAU,SAAA,IAAA;AACnC,aAAiB,IAAI,UAAA,QAAc,EAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { 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"}
|
package/mdc/package.json
ADDED