@analogjs/content 3.0.0-alpha.2 → 3.0.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/fesm2022/analogjs-content-md4x.mjs +290 -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 +34 -46
- package/fesm2022/analogjs-content-og.mjs.map +1 -1
- package/fesm2022/analogjs-content-prism-highlighter.mjs +81 -68
- package/fesm2022/analogjs-content-prism-highlighter.mjs.map +1 -1
- package/fesm2022/analogjs-content-resources.mjs +113 -124
- package/fesm2022/analogjs-content-resources.mjs.map +1 -1
- package/fesm2022/analogjs-content-shiki-highlighter.mjs +9 -14
- package/fesm2022/analogjs-content-shiki-highlighter.mjs.map +1 -1
- package/fesm2022/analogjs-content.mjs +658 -636
- package/fesm2022/analogjs-content.mjs.map +1 -1
- package/fesm2022/content-list-loader.mjs +284 -0
- package/fesm2022/content-list-loader.mjs.map +1 -0
- package/md4x/package.json +4 -0
- package/mdc/package.json +4 -0
- package/og/package.json +2 -2
- package/package.json +67 -38
- package/plugin/package.json +2 -22
- package/plugin/src/index.d.ts +4 -2
- package/plugin/src/index.js +6 -3
- package/plugin/src/index.js.map +1 -1
- package/plugin/src/migrations/update-markdown-version/compat.d.ts +6 -2
- package/plugin/src/migrations/update-markdown-version/compat.js +8 -5
- package/plugin/src/migrations/update-markdown-version/compat.js.map +1 -1
- package/plugin/src/migrations/update-markdown-version/update-markdown-version.d.ts +6 -2
- 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 -1
- package/prism-highlighter/package.json +2 -2
- package/resources/package.json +2 -2
- package/shiki-highlighter/package.json +2 -2
- package/src/lib/devtools/content-devtools-client.ts +215 -0
- package/src/lib/devtools/content-devtools.styles.css +194 -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/og/src/index.d.ts +2 -0
- package/types/og/src/lib/og.d.ts +5 -0
- package/types/og/src/lib/options.d.ts +11 -0
- package/types/prism-highlighter/src/index.d.ts +8 -0
- package/types/prism-highlighter/src/lib/prism/angular.d.ts +1 -0
- package/types/prism-highlighter/src/lib/prism-highlighter.d.ts +8 -0
- package/types/resources/src/content-file-resource.d.ts +39 -0
- package/types/resources/src/content-files-resource.d.ts +3 -0
- package/types/resources/src/index.d.ts +2 -0
- package/types/shiki-highlighter/src/index.d.ts +7 -0
- package/types/src/index.d.ts +18 -0
- package/types/src/lib/anchor-navigation.directive.d.ts +9 -0
- package/types/src/lib/content-file-loader.d.ts +6 -0
- package/types/src/lib/content-file.d.ts +8 -0
- package/types/src/lib/content-files-list-token.d.ts +3 -0
- package/types/src/lib/content-files-token.d.ts +3 -0
- package/types/src/lib/content-list-loader.d.ts +7 -0
- package/types/src/lib/content-renderer.d.ts +33 -0
- package/types/src/lib/content.d.ts +14 -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/get-content-files.d.ts +14 -0
- package/types/src/lib/inject-content-files.d.ts +4 -0
- package/types/src/lib/markdown-content-renderer.service.d.ts +10 -0
- package/types/src/lib/markdown-route.component.d.ts +15 -0
- package/types/src/lib/markdown.component.d.ts +26 -0
- package/types/src/lib/marked-content-highlighter.d.ts +17 -0
- package/types/src/lib/marked-setup.service.d.ts +10 -0
- package/types/src/lib/parse-raw-content-file.d.ts +18 -0
- package/types/src/lib/provide-content.d.ts +7 -0
- package/types/src/lib/render-task.service.d.ts +8 -0
- package/types/src/lib/utils/zone-wait-for.d.ts +2 -0
- package/og/README.md +0 -3
- package/plugin/README.md +0 -11
- package/plugin/src/migrations/update-markdown-renderer-feature/compat.d.ts +0 -2
- package/plugin/src/migrations/update-markdown-renderer-feature/compat.js +0 -6
- package/plugin/src/migrations/update-markdown-renderer-feature/compat.js.map +0 -1
- 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
- package/plugin/src/migrations/update-markdown-renderer-feature/update-markdown-renderer-feature.js.map +0 -1
- package/prism-highlighter/README.md +0 -3
- package/resources/README.md +0 -3
- package/shiki-highlighter/README.md +0 -3
- package/types/analogjs-content-og.d.ts +0 -19
- package/types/analogjs-content-prism-highlighter.d.ts +0 -15
- package/types/analogjs-content-resources.d.ts +0 -20
- package/types/analogjs-content-shiki-highlighter.d.ts +0 -11
- package/types/analogjs-content.d.ts +0 -168
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { markedHighlight } from
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
class PrismHighlighter extends MarkedContentHighlighter {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
diff = false;
|
|
24
|
-
console.warn(`Notice:
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { Injectable } from "@angular/core";
|
|
3
|
+
import { ContentRenderer, MarkedContentHighlighter, NoopContentRenderer } from "@analogjs/content";
|
|
4
|
+
import { markedHighlight } from "marked-highlight";
|
|
5
|
+
import Prism$1 from "prismjs";
|
|
6
|
+
import "prismjs/plugins/toolbar/prism-toolbar";
|
|
7
|
+
import "prismjs/plugins/copy-to-clipboard/prism-copy-to-clipboard";
|
|
8
|
+
//#region packages/content/prism-highlighter/src/lib/prism-highlighter.ts
|
|
9
|
+
var PrismHighlighter = class PrismHighlighter extends MarkedContentHighlighter {
|
|
10
|
+
augmentCodeBlock(code, lang) {
|
|
11
|
+
const classes = lang.startsWith("diff") && Prism.languages["diff"] ? `language-${lang} diff-highlight` : `language-${lang.replace("diff-", "")}`;
|
|
12
|
+
return `<pre class="${classes}"><code class="${classes}">${code}</code></pre>`;
|
|
13
|
+
}
|
|
14
|
+
getHighlightExtension() {
|
|
15
|
+
return markedHighlight({
|
|
16
|
+
async: true,
|
|
17
|
+
highlight: (code, lang) => {
|
|
18
|
+
let diff = lang?.startsWith("diff-");
|
|
19
|
+
lang = diff ? lang.replace("diff-", "") : lang || "typescript";
|
|
20
|
+
if (diff && !Prism.languages["diff"]) {
|
|
21
|
+
diff = false;
|
|
22
|
+
console.warn(`Notice:
|
|
25
23
|
---------------------------------------------------------------------------------------
|
|
26
24
|
The \`diff\` language and plugin are not available in the provided setup.
|
|
27
25
|
To enable it, add the following imports your \`app.config.ts\`:
|
|
@@ -29,57 +27,72 @@ class PrismHighlighter extends MarkedContentHighlighter {
|
|
|
29
27
|
import 'prismjs/plugins/diff-highlight/prism-diff-highlight';
|
|
30
28
|
---------------------------------------------------------------------------------------
|
|
31
29
|
`);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
console.warn(`Notice:
|
|
30
|
+
}
|
|
31
|
+
if (!Prism.languages[lang]) {
|
|
32
|
+
if (lang !== "mermaid") console.warn(`Notice:
|
|
36
33
|
---------------------------------------------------------------------------------------
|
|
37
34
|
The requested language '${lang}' is not available in the provided setup.
|
|
38
35
|
To enable it, add the following import your \`app.config.ts\`:
|
|
39
36
|
import 'prismjs/components/prism-${lang}';
|
|
40
37
|
---------------------------------------------------------------------------------------
|
|
41
38
|
`);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
39
|
+
return code;
|
|
40
|
+
}
|
|
41
|
+
return Prism.highlight(code, diff ? Prism.languages["diff"] : Prism.languages[lang], lang);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
static {
|
|
46
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
47
|
+
minVersion: "12.0.0",
|
|
48
|
+
version: "21.2.6",
|
|
49
|
+
ngImport: i0,
|
|
50
|
+
type: PrismHighlighter,
|
|
51
|
+
deps: null,
|
|
52
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
static {
|
|
56
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
57
|
+
minVersion: "12.0.0",
|
|
58
|
+
version: "21.2.6",
|
|
59
|
+
ngImport: i0,
|
|
60
|
+
type: PrismHighlighter
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
65
|
+
minVersion: "12.0.0",
|
|
66
|
+
version: "21.2.6",
|
|
67
|
+
ngImport: i0,
|
|
68
|
+
type: PrismHighlighter,
|
|
69
|
+
decorators: [{ type: Injectable }]
|
|
70
|
+
});
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region packages/content/prism-highlighter/src/lib/prism/angular.ts
|
|
73
|
+
(function() {
|
|
74
|
+
if (typeof Prism$1 === "undefined") return;
|
|
75
|
+
Prism$1.languages["angular"] = Prism$1.languages.extend("markup", {
|
|
76
|
+
keyword: /(?:@if|@for|@switch|@defer|@loading|@error|@placeholder|prefetch)\b/,
|
|
77
|
+
operator: /\b(?:on|when)\b/,
|
|
78
|
+
number: {
|
|
79
|
+
pattern: /\b(minimum|after)\s+\d+(?:s|ms|)/gi,
|
|
80
|
+
lookbehind: true
|
|
81
|
+
},
|
|
82
|
+
builtin: { pattern: /\b(?:viewport|timer|minimum|after|hover|idle|immediate|interaction)/ },
|
|
83
|
+
function: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/
|
|
84
|
+
});
|
|
85
|
+
Prism$1.languages["ng"] = Prism$1.languages["angular"];
|
|
74
86
|
})();
|
|
75
|
-
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region packages/content/prism-highlighter/src/index.ts
|
|
76
89
|
function withPrismHighlighter() {
|
|
77
|
-
|
|
90
|
+
return [{
|
|
91
|
+
provide: ContentRenderer,
|
|
92
|
+
useClass: NoopContentRenderer
|
|
93
|
+
}];
|
|
78
94
|
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Generated bundle index. Do not edit.
|
|
82
|
-
*/
|
|
83
|
-
|
|
95
|
+
//#endregion
|
|
84
96
|
export { PrismHighlighter, withPrismHighlighter };
|
|
85
|
-
|
|
97
|
+
|
|
98
|
+
//# sourceMappingURL=analogjs-content-prism-highlighter.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analogjs-content-prism-highlighter.mjs","sources":["
|
|
1
|
+
{"version":3,"file":"analogjs-content-prism-highlighter.mjs","names":[],"sources":["../../prism-highlighter/src/lib/prism-highlighter.ts","../../prism-highlighter/src/lib/prism/angular.ts","../../prism-highlighter/src/index.ts"],"sourcesContent":["import { MarkedContentHighlighter } from '@analogjs/content';\nimport { Injectable } from '@angular/core';\nimport { markedHighlight } from 'marked-highlight';\n\ndeclare const Prism: typeof import('prismjs');\n\n@Injectable()\nexport class PrismHighlighter extends MarkedContentHighlighter {\n override augmentCodeBlock(code: string, lang: string): string {\n const classes =\n lang.startsWith('diff') && Prism.languages['diff']\n ? `language-${lang} diff-highlight`\n : `language-${lang.replace('diff-', '')}`;\n return `<pre class=\"${classes}\"><code class=\"${classes}\">${code}</code></pre>`;\n }\n\n override getHighlightExtension(): import('marked').MarkedExtension {\n return markedHighlight({\n async: true,\n highlight: (code: string, lang: string) => {\n let diff = lang?.startsWith('diff-');\n lang = diff ? lang.replace('diff-', '') : lang || 'typescript';\n\n if (diff && !Prism.languages['diff']) {\n diff = false;\n console.warn(`Notice:\n ---------------------------------------------------------------------------------------\n The \\`diff\\` language and plugin are not available in the provided setup.\n To enable it, add the following imports your \\`app.config.ts\\`:\n import 'prismjs/components/prism-diff';\n import 'prismjs/plugins/diff-highlight/prism-diff-highlight';\n ---------------------------------------------------------------------------------------\n `);\n }\n\n if (!Prism.languages[lang]) {\n if (lang !== 'mermaid') {\n console.warn(`Notice:\n ---------------------------------------------------------------------------------------\n The requested language '${lang}' is not available in the provided setup.\n To enable it, add the following import your \\`app.config.ts\\`:\n import 'prismjs/components/prism-${lang}';\n ---------------------------------------------------------------------------------------\n `);\n }\n return code;\n }\n return Prism.highlight(\n code,\n diff ? Prism.languages['diff'] : Prism.languages[lang],\n lang,\n );\n },\n });\n }\n}\n","import Prism from 'prismjs';\n\n(function () {\n if (typeof Prism === 'undefined') {\n return;\n }\n\n Prism.languages['angular'] = Prism.languages.extend('markup', {\n keyword:\n /(?:@if|@for|@switch|@defer|@loading|@error|@placeholder|prefetch)\\b/,\n operator: /\\b(?:on|when)\\b/,\n number: {\n pattern: /\\b(minimum|after)\\s+\\d+(?:s|ms|)/gi,\n lookbehind: true,\n },\n builtin: {\n pattern:\n /\\b(?:viewport|timer|minimum|after|hover|idle|immediate|interaction)/,\n },\n function:\n /#?(?!\\s)[_$a-zA-Z\\xA0-\\uFFFF](?:(?!\\s)[$\\w\\xA0-\\uFFFF])*(?=\\s*(?:\\.\\s*(?:apply|bind|call)\\s*)?\\()/,\n });\n\n Prism.languages['ng'] = Prism.languages['angular'];\n})();\n","import { ContentRenderer, NoopContentRenderer } from '@analogjs/content';\nimport { Provider } from '@angular/core';\nimport { PrismHighlighter } from './lib/prism-highlighter';\n\nimport 'prismjs';\nimport 'prismjs/plugins/toolbar/prism-toolbar';\nimport 'prismjs/plugins/copy-to-clipboard/prism-copy-to-clipboard';\nimport './lib/prism/angular';\n\nexport { PrismHighlighter };\n\nexport function withPrismHighlighter(): Provider[] {\n return [{ provide: ContentRenderer, useClass: NoopContentRenderer }];\n}\n"],"mappings":";;;;;;;;AAOO,IAAA,mBAAA,MAAA,yBAAM,yBAAyB;CACpC,iBAA0B,MAAc,MAAsB;EACtD,MAAA,UACC,KAAA,WAAW,OAAW,IAAM,MAAA,UAAU,UAGtC,YAAe,KAAA,mBAAA,YAAA,KAAA,QAAA,SAAA,GAAA;AAGxB,SAAA,eAAmE,QAAA,iBAAA,QAAA,IAAA,KAAA;;CAE/D,wBAAO;AACP,SAAY,gBAA+B;GACrC,OAAO;GACJ,YAAY,MAAA,SAAQ;IAEf,IAAC,OAAM,MAAU,WAAS,QAAA;AAC7B,WAAA,OAAA,KAAA,QAAA,SAAA,GAAA,GAAA,QAAA;AACC,QAAK,QAAA,CAAA,MAAA,UAAA,SAAA;;;;;;;;;cAUV;;AAEO,QAAK,CAAA,MAAA,UAAA,OAAA;qCAEK,KAAK;;;;yCAInB,KAAA;;gBAEC;AAEI,YACX;;AAKJ,WAAA,MAAA,UAAA,MAAA,OAAA,MAAA,UAAA,UAAA,MAAA,UAAA,OAAA,KAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CCnDL,WAAY;AACX,KAAI,OAAO,YAAU,YACnB;AAGF,SAAM,UAAU,aAAa,QAAM,UAAU,OAAO,UAAU;EAC5D,SACE;EACF,UAAU;EACV,QAAQ;GACG,SAAA;GACT,YAAY;GACb;EACD,SACE,EAIA,SAAA,uEACF;EAEI,UAAU;EACd,CAAA;;;;;ACbJ,SAAgB,uBAAmC;AACjD,QAAQ,CAAA;EAAA,SAAA;EAAA,UAAA;EAAA,CAAA"}
|
|
@@ -1,129 +1,118 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
1
|
+
import { computed, inject, resource } from "@angular/core";
|
|
2
|
+
import { ActivatedRoute } from "@angular/router";
|
|
3
|
+
import { from } from "rxjs";
|
|
4
|
+
import { map } from "rxjs/operators";
|
|
5
|
+
import { toSignal } from "@angular/core/rxjs-interop";
|
|
6
|
+
import { ContentRenderer, FrontmatterValidationError, injectContentFileLoader, injectContentListLoader, parseRawContentFile, parseRawContentFileAsync } from "@analogjs/content";
|
|
7
|
+
//#region packages/content/resources/src/content-files-resource.ts
|
|
8
8
|
function contentFilesResource(filterFn) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return resource({
|
|
12
|
-
loader: () => contentList,
|
|
13
|
-
});
|
|
9
|
+
const contentList = injectContentListLoader()().then((items) => filterFn ? items.filter(filterFn) : items);
|
|
10
|
+
return resource({ loader: () => contentList });
|
|
14
11
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const normalizedKey = key
|
|
22
|
-
// replace any prefix up to the content directory with /src/content
|
|
23
|
-
// use a non-greedy match so nested paths containing "/content" are preserved
|
|
24
|
-
.replace(/^(?:.*?)\/content(?=\/)/, '/src/content')
|
|
25
|
-
// normalize duplicate slashes
|
|
26
|
-
.replace(/\/{2,}/g, '/');
|
|
27
|
-
normalizedFiles[normalizedKey] = resolver;
|
|
28
|
-
}
|
|
29
|
-
// Try direct file first, then directory index variants
|
|
30
|
-
const base = `/src/content/${slug}`.replace(/\/{2,}/g, '/');
|
|
31
|
-
const candidates = [
|
|
32
|
-
`${base}.md`,
|
|
33
|
-
`${base}.agx`,
|
|
34
|
-
`${base}/index.md`,
|
|
35
|
-
`${base}/index.agx`,
|
|
36
|
-
];
|
|
37
|
-
const matchKey = candidates.find((k) => k in normalizedFiles);
|
|
38
|
-
const contentFile = matchKey ? normalizedFiles[matchKey] : undefined;
|
|
39
|
-
if (!contentFile) {
|
|
40
|
-
return {
|
|
41
|
-
filename: base,
|
|
42
|
-
attributes: {},
|
|
43
|
-
slug: '',
|
|
44
|
-
content: fallback,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
const resolvedBase = matchKey.replace(/\.(md|agx)$/, '');
|
|
48
|
-
return contentFile().then((contentFile) => {
|
|
49
|
-
if (typeof contentFile === 'string') {
|
|
50
|
-
const { content, attributes } = parseRawContentFile(contentFile);
|
|
51
|
-
return {
|
|
52
|
-
filename: resolvedBase,
|
|
53
|
-
slug,
|
|
54
|
-
attributes,
|
|
55
|
-
content,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
filename: resolvedBase,
|
|
60
|
-
slug,
|
|
61
|
-
attributes: contentFile.metadata,
|
|
62
|
-
content: contentFile.default,
|
|
63
|
-
};
|
|
64
|
-
});
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region packages/content/resources/src/content-file-resource.ts
|
|
14
|
+
async function validateAttributes(schema, attributes, filename) {
|
|
15
|
+
const result = await schema["~standard"].validate(attributes);
|
|
16
|
+
if (result.issues) throw new FrontmatterValidationError(result.issues, filename);
|
|
17
|
+
return result.value;
|
|
65
18
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
*
|
|
69
|
-
* @param params
|
|
70
|
-
* @param fallback
|
|
71
|
-
* @returns
|
|
72
|
-
*/
|
|
73
|
-
function contentFileResource(params, fallback = 'No Content Found') {
|
|
74
|
-
const loaderPromise = injectContentFileLoader();
|
|
75
|
-
const contentRenderer = inject(ContentRenderer);
|
|
76
|
-
const contentFilesMap = toSignal(from(loaderPromise()));
|
|
77
|
-
const input = params ||
|
|
78
|
-
toSignal(inject(ActivatedRoute).paramMap.pipe(map((params) => params.get('slug'))), { requireSync: true });
|
|
79
|
-
return resource({
|
|
80
|
-
params: computed(() => ({ input: input(), files: contentFilesMap() })),
|
|
81
|
-
loader: async ({ params }) => {
|
|
82
|
-
const { input: param, files } = params;
|
|
83
|
-
if (typeof param === 'string') {
|
|
84
|
-
if (param) {
|
|
85
|
-
const file = await getContentFile(files, param, fallback);
|
|
86
|
-
if (typeof file.content === 'string') {
|
|
87
|
-
const rendered = (await contentRenderer.render(file.content));
|
|
88
|
-
return {
|
|
89
|
-
...file,
|
|
90
|
-
toc: rendered.toc ?? [],
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
...file,
|
|
95
|
-
toc: [],
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
filename: '',
|
|
100
|
-
slug: '',
|
|
101
|
-
attributes: {},
|
|
102
|
-
content: fallback,
|
|
103
|
-
toc: [],
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
const file = await getContentFile(files, param.customFilename, fallback);
|
|
108
|
-
if (typeof file.content === 'string') {
|
|
109
|
-
const rendered = (await contentRenderer.render(file.content));
|
|
110
|
-
return {
|
|
111
|
-
...file,
|
|
112
|
-
toc: rendered.toc ?? [],
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
...file,
|
|
117
|
-
toc: [],
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
});
|
|
19
|
+
function getValidationFilename(filename) {
|
|
20
|
+
return filename.replace(/^\/src\/content\//, "");
|
|
122
21
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
22
|
+
async function getContentFile(contentFiles, slug, fallback, schema) {
|
|
23
|
+
const normalizedFiles = {};
|
|
24
|
+
const stemToKey = {};
|
|
25
|
+
for (const [key, resolver] of Object.entries(contentFiles)) {
|
|
26
|
+
const normalizedKey = key.replace(/^(?:.*?)\/content(?=\/)/, "/src/content").replace(/\/{2,}/g, "/");
|
|
27
|
+
normalizedFiles[normalizedKey] = resolver;
|
|
28
|
+
const stem = normalizedKey.split("/").pop()?.replace(/\.[^.]+$/, "");
|
|
29
|
+
if (stem && !stemToKey[stem]) stemToKey[stem] = normalizedKey;
|
|
30
|
+
}
|
|
31
|
+
const base = `/src/content/${slug}`.replace(/\/{2,}/g, "/");
|
|
32
|
+
const matchKey = [`${base}.md`, `${base}/index.md`].find((k) => k in normalizedFiles) ?? stemToKey[slug];
|
|
33
|
+
const contentFile = matchKey ? normalizedFiles[matchKey] : void 0;
|
|
34
|
+
if (!contentFile) return {
|
|
35
|
+
filename: base,
|
|
36
|
+
attributes: {},
|
|
37
|
+
slug: "",
|
|
38
|
+
content: fallback
|
|
39
|
+
};
|
|
40
|
+
const resolvedBase = matchKey.replace(/\.md$/, "");
|
|
41
|
+
const validationFilename = getValidationFilename(matchKey);
|
|
42
|
+
return contentFile().then(async (contentFile) => {
|
|
43
|
+
if (typeof contentFile === "string") {
|
|
44
|
+
const { content, attributes } = schema ? await parseRawContentFileAsync(contentFile, schema, validationFilename) : parseRawContentFile(contentFile);
|
|
45
|
+
return {
|
|
46
|
+
filename: resolvedBase,
|
|
47
|
+
slug,
|
|
48
|
+
attributes,
|
|
49
|
+
content
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
filename: resolvedBase,
|
|
54
|
+
slug,
|
|
55
|
+
attributes: schema ? await validateAttributes(schema, contentFile.metadata, validationFilename) : contentFile.metadata,
|
|
56
|
+
content: contentFile.default
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function contentFileResource(paramsOrOptions, fallbackArg = "No Content Found") {
|
|
61
|
+
const isOptionsObject = paramsOrOptions && typeof paramsOrOptions === "object" && !("set" in paramsOrOptions) && ("schema" in paramsOrOptions || "params" in paramsOrOptions || "fallback" in paramsOrOptions);
|
|
62
|
+
const params = isOptionsObject ? paramsOrOptions.params : paramsOrOptions;
|
|
63
|
+
const fallback = isOptionsObject ? paramsOrOptions.fallback ?? "No Content Found" : fallbackArg;
|
|
64
|
+
const schema = isOptionsObject ? paramsOrOptions.schema : void 0;
|
|
65
|
+
const loaderPromise = injectContentFileLoader();
|
|
66
|
+
const contentRenderer = inject(ContentRenderer);
|
|
67
|
+
const contentFilesMap = toSignal(from(loaderPromise()));
|
|
68
|
+
const input = params || toSignal(inject(ActivatedRoute).paramMap.pipe(map((params) => params.get("slug"))), { requireSync: true });
|
|
69
|
+
return resource({
|
|
70
|
+
params: computed(() => ({
|
|
71
|
+
input: input(),
|
|
72
|
+
files: contentFilesMap()
|
|
73
|
+
})),
|
|
74
|
+
loader: async ({ params: resourceParams }) => {
|
|
75
|
+
const { input: param, files } = resourceParams;
|
|
76
|
+
if (typeof param === "string") {
|
|
77
|
+
if (param) {
|
|
78
|
+
const file = await getContentFile(files, param, fallback, schema);
|
|
79
|
+
if (typeof file.content === "string") {
|
|
80
|
+
const rendered = await contentRenderer.render(file.content);
|
|
81
|
+
return {
|
|
82
|
+
...file,
|
|
83
|
+
toc: rendered.toc ?? []
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
...file,
|
|
88
|
+
toc: []
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
filename: "",
|
|
93
|
+
slug: "",
|
|
94
|
+
attributes: {},
|
|
95
|
+
content: fallback,
|
|
96
|
+
toc: []
|
|
97
|
+
};
|
|
98
|
+
} else {
|
|
99
|
+
const file = await getContentFile(files, param.customFilename, fallback, schema);
|
|
100
|
+
if (typeof file.content === "string") {
|
|
101
|
+
const rendered = await contentRenderer.render(file.content);
|
|
102
|
+
return {
|
|
103
|
+
...file,
|
|
104
|
+
toc: rendered.toc ?? []
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
...file,
|
|
109
|
+
toc: []
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
128
116
|
export { contentFileResource, contentFilesResource };
|
|
129
|
-
|
|
117
|
+
|
|
118
|
+
//# sourceMappingURL=analogjs-content-resources.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analogjs-content-resources.mjs","sources":["../../../../packages/content/resources/src/content-files-resource.ts","../../../../packages/content/resources/src/content-file-resource.ts","../../../../packages/content/resources/src/analogjs-content-resources.ts"],"sourcesContent":["import { resource } from '@angular/core';\nimport {\n injectContentListLoader,\n InjectContentFilesFilterFunction,\n} from '@analogjs/content';\n\nexport function contentFilesResource<Attributes extends Record<string, any>>(\n filterFn?: InjectContentFilesFilterFunction<Attributes> | undefined,\n) {\n const contentListLoader = injectContentListLoader<Attributes>();\n const contentList = contentListLoader().then((items) =>\n filterFn ? items.filter(filterFn) : items,\n );\n\n return resource({\n loader: () => contentList,\n });\n}\n","import { computed, inject, resource, Signal } from '@angular/core';\nimport {\n ContentFile,\n ContentRenderer,\n parseRawContentFile,\n injectContentFileLoader,\n} from '@analogjs/content';\nimport { ActivatedRoute } from '@angular/router';\n\nimport { toSignal } from '@angular/core/rxjs-interop';\nimport { from } from 'rxjs';\nimport { map } from 'rxjs/operators';\n\ntype ContentFileParams = Signal<\n | string\n | {\n customFilename: string;\n }\n>;\n\nasync function getContentFile<\n Attributes extends Record<string, any> = Record<string, any>,\n>(\n contentFiles: Record<string, () => Promise<string>>,\n slug: string,\n fallback: string,\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, () => Promise<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 }\n\n // Try direct file first, then directory index variants\n const base = `/src/content/${slug}`.replace(/\\/{2,}/g, '/');\n const candidates = [\n `${base}.md`,\n `${base}.agx`,\n `${base}/index.md`,\n `${base}/index.agx`,\n ];\n\n const matchKey = candidates.find((k) => k in normalizedFiles);\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|agx)$/, '');\n\n return contentFile().then(\n (contentFile: string | { default: any; metadata: any }) => {\n if (typeof contentFile === 'string') {\n const { content, attributes } =\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 return {\n filename: resolvedBase,\n slug,\n attributes: contentFile.metadata,\n content: contentFile.default,\n } as ContentFile<Attributes | Record<string, never>>;\n },\n );\n}\n\n/**\n * Resource for requesting an individual content file\n *\n * @param params\n * @param fallback\n * @returns\n */\nexport function contentFileResource<\n Attributes extends Record<string, any> = Record<string, any>,\n>(params?: ContentFileParams, fallback = 'No Content Found') {\n const loaderPromise = injectContentFileLoader();\n const contentRenderer = inject(ContentRenderer);\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 }) => {\n const { input: param, files } = params;\n\n if (typeof param === 'string') {\n if (param) {\n const file = await getContentFile<Attributes>(\n files!,\n param,\n fallback,\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 } as ContentFile<Attributes | Record<string, never>>;\n } else {\n const file = await getContentFile<Attributes>(\n files!,\n param.customFilename,\n fallback,\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","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;AAMM,SAAU,oBAAoB,CAClC,QAAmE,EAAA;AAEnE,IAAA,MAAM,iBAAiB,GAAG,uBAAuB,EAAc;IAC/D,MAAM,WAAW,GAAG,iBAAiB,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,KACjD,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,KAAK,CAC1C;AAED,IAAA,OAAO,QAAQ,CAAC;AACd,QAAA,MAAM,EAAE,MAAM,WAAW;AAC1B,KAAA,CAAC;AACJ;;ACGA,eAAe,cAAc,CAG3B,YAAmD,EACnD,IAAY,EACZ,QAAgB,EAAA;;;IAIhB,MAAM,eAAe,GAA0C,EAAE;AACjE,IAAA,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,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;wBACD,OAAO;AACL,4BAAA,GAAG,IAAI;AACP,4BAAA,GAAG,EAAE,QAAQ,CAAC,GAAG,IAAI,EAAE;yBACxB;oBACH;oBACA,OAAO;AACL,wBAAA,GAAG,IAAI;AACP,wBAAA,GAAG,EAAE,EAAE;qBACR;gBACH;gBAEA,OAAO;AACL,oBAAA,QAAQ,EAAE,EAAE;AACZ,oBAAA,IAAI,EAAE,EAAE;AACR,oBAAA,UAAU,EAAE,EAAE;AACd,oBAAA,OAAO,EAAE,QAAQ;AACjB,oBAAA,GAAG,EAAE,EAAE;iBAC2C;YACtD;iBAAO;AACL,gBAAA,MAAM,IAAI,GAAG,MAAM,cAAc,CAC/B,KAAM,EACN,KAAK,CAAC,cAAc,EACpB,QAAQ,CACT;AACD,gBAAA,IAAI,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,EAAE;AACpC,oBAAA,MAAM,QAAQ,IAAI,MAAM,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAE3D;oBACD,OAAO;AACL,wBAAA,GAAG,IAAI;AACP,wBAAA,GAAG,EAAE,QAAQ,CAAC,GAAG,IAAI,EAAE;qBACxB;gBACH;gBACA,OAAO;AACL,oBAAA,GAAG,IAAI;AACP,oBAAA,GAAG,EAAE,EAAE;iBACR;YACH;QACF,CAAC;AACF,KAAA,CAAC;AACJ;;ACrKA;;AAEG;;;;"}
|
|
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 {\n ContentFile,\n injectContentListLoader,\n InjectContentFilesFilterFunction,\n} from '@analogjs/content';\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 contentList = contentListLoader().then((items) =>\n filterFn ? items.filter(filterFn) : items,\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 {\n ContentFile,\n ContentRenderer,\n FrontmatterValidationError,\n parseRawContentFile,\n parseRawContentFileAsync,\n injectContentFileLoader,\n} from '@analogjs/content';\nimport { ActivatedRoute } from '@angular/router';\n\nimport { toSignal } from '@angular/core/rxjs-interop';\nimport { from } from 'rxjs';\nimport { map } from 'rxjs/operators';\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, () => Promise<string>>,\n slug: string,\n fallback: string,\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, () => Promise<string>> = {};\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 const matchKey =\n candidates.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(\n async (contentFile: string | { default: any; metadata: any }) => {\n if (typeof contentFile === 'string') {\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/**\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 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(files!, param, fallback, schema);\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 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":";;;;;;;AAOA,SAAgB,qBACd,UACoD;CAEpD,MAAM,cADoB,yBAAqC,EACvB,CAAA,MAAM,UAC5C,WAAW,MAAM,OAAO,SAAY,GAAA,MACrC;AAED,QAAO,SACL,EAAA,cAAA,aAAA,CAAA;;;;ACiBJ,eAAe,mBACb,QACA,YACA,UACA;CACA,MAAM,SAAS,MAAM,OAAO,aAAa,SAAS,WAAW;AAC7D,KAAI,OAAO,OACH,OAAI,IAAA,2BAA2B,OAAO,QAAQ,SAAS;AAG/D,QAAO,OAAO;;AAGhB,SAAS,sBAAsB,UAA0B;AACvD,QAAO,SAAS,QAAQ,qBAAwB,GAAA;;AAGlD,eAAe,eAGb,cACA,MACA,UACA,QAC0D;CAK1D,MAAK,kBAAY,EAAA;CACf,MAAM,YAAA,EAAgB;AAMtB,MAAA,MAAA,CAAA,KAAgB,aAAA,OAAiB,QAAA,aAAA,EAAA;EAE3B,MAAA,gBACH,IAAA,QAAA,2BAAA,eAAA,CASC,QAAO,WAAgB,IAAA;AACvB,kBAAiB,iBAAc;EAI/B,MAAA,OAAc,cAEf,MAAa,IAAA,CACT,KAAA,EACK,QAAA,YAAA,GAAA;AACV,MAAA,QAAc,CAAA,UAAA,MACR,WAAA,QAAA;;CAKV,MAAM,OAAA,gBAAyB,OAAQ,QAAS,WAAG,IAAA;CAGnD,MAAO,WAFD,CAAA,GAAA,KAAqB,MAAA,GAAA,KAAA,WAAsB,CAG/C,MAAO,MAAA,KAAA,gBAA0D,IAAA,UAAA;CAC/D,MAAI,cAAO,WAAgB,gBAAU,YAAA,KAAA;AACnC,KAAA,CAAM,YAQN,QAAO;EACL,UAAU;EACV,YA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AAA;OACN,KAAA,SAAA,OAAA,EAAA;;;AAGL,YAAA"}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ContentRenderer, NoopContentRenderer } from "@analogjs/content";
|
|
2
|
+
//#region packages/content/shiki-highlighter/src/index.ts
|
|
3
3
|
function withShikiHighlighter(_opts = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
},
|
|
9
|
-
];
|
|
4
|
+
return [{
|
|
5
|
+
provide: ContentRenderer,
|
|
6
|
+
useClass: NoopContentRenderer
|
|
7
|
+
}];
|
|
10
8
|
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Generated bundle index. Do not edit.
|
|
14
|
-
*/
|
|
15
|
-
|
|
9
|
+
//#endregion
|
|
16
10
|
export { withShikiHighlighter };
|
|
17
|
-
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=analogjs-content-shiki-highlighter.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analogjs-content-shiki-highlighter.mjs","sources":["
|
|
1
|
+
{"version":3,"file":"analogjs-content-shiki-highlighter.mjs","names":[],"sources":["../../shiki-highlighter/src/index.ts"],"sourcesContent":["import { ContentRenderer, NoopContentRenderer } from '@analogjs/content';\nimport { Provider } from '@angular/core';\nimport type {\n BundledLanguage,\n BundledTheme,\n CodeOptionsMeta,\n CodeOptionsMultipleThemes,\n CodeOptionsSingleTheme,\n CodeToHastOptionsCommon,\n} from 'shiki';\n\nexport type ShikiHighlightOptions = Partial<\n Omit<CodeToHastOptionsCommon<BundledLanguage>, 'lang'>\n> &\n CodeOptionsMeta &\n Partial<CodeOptionsSingleTheme<BundledTheme>> &\n Partial<CodeOptionsMultipleThemes<BundledTheme>>;\n\nexport type WithShikiHighlighterOptions = ShikiHighlightOptions & {\n container?: string;\n};\n\nexport function withShikiHighlighter(\n _opts: WithShikiHighlighterOptions = {},\n): Provider[] {\n return [\n {\n provide: ContentRenderer,\n useClass: NoopContentRenderer,\n },\n ];\n}\n"],"mappings":";;AAsBA,SAAgB,qBACd,QAAqC,EAAE,EAC3B;AACZ,QACE,CACE;EACU,SAAA;EAEb,UAAA"}
|