fuma-content 1.0.1 → 1.0.2

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 (147) hide show
  1. package/dist/async-cache-BM9Yf4Nw.js +29 -0
  2. package/dist/async-cache-BM9Yf4Nw.js.map +1 -0
  3. package/dist/bin.d.ts +1 -1
  4. package/dist/bin.js +21 -14
  5. package/dist/bin.js.map +1 -0
  6. package/dist/build-D8A5ByFk.js +42 -0
  7. package/dist/build-D8A5ByFk.js.map +1 -0
  8. package/dist/build-mdx-C1PZsGp2.js +395 -0
  9. package/dist/build-mdx-C1PZsGp2.js.map +1 -0
  10. package/dist/build-mdx-DFndaVbS.js +4 -0
  11. package/dist/bun/index.d.ts +6 -13
  12. package/dist/bun/index.d.ts.map +1 -0
  13. package/dist/bun/index.js +23 -34
  14. package/dist/bun/index.js.map +1 -0
  15. package/dist/bun-QKQnqgIi.js +35 -0
  16. package/dist/bun-QKQnqgIi.js.map +1 -0
  17. package/dist/code-generator-gPtrfZ6Q.js +133 -0
  18. package/dist/code-generator-gPtrfZ6Q.js.map +1 -0
  19. package/dist/collections/handlers/fs.d.ts +2 -10
  20. package/dist/collections/handlers/fs.js +28 -6
  21. package/dist/collections/handlers/fs.js.map +1 -0
  22. package/dist/collections/index.d.ts +2 -10
  23. package/dist/collections/index.js +16 -6
  24. package/dist/collections/index.js.map +1 -0
  25. package/dist/collections/mdx/loader-webpack.d.ts +6 -14
  26. package/dist/collections/mdx/loader-webpack.d.ts.map +1 -0
  27. package/dist/collections/mdx/loader-webpack.js +23 -36
  28. package/dist/collections/mdx/loader-webpack.js.map +1 -0
  29. package/dist/collections/mdx/runtime-browser.d.ts +27 -37
  30. package/dist/collections/mdx/runtime-browser.d.ts.map +1 -0
  31. package/dist/collections/mdx/runtime-browser.js +57 -70
  32. package/dist/collections/mdx/runtime-browser.js.map +1 -0
  33. package/dist/collections/mdx/runtime-dynamic.d.ts +22 -30
  34. package/dist/collections/mdx/runtime-dynamic.d.ts.map +1 -0
  35. package/dist/collections/mdx/runtime-dynamic.js +63 -85
  36. package/dist/collections/mdx/runtime-dynamic.js.map +1 -0
  37. package/dist/collections/mdx/runtime.d.ts +31 -52
  38. package/dist/collections/mdx/runtime.d.ts.map +1 -0
  39. package/dist/collections/mdx/runtime.js +24 -34
  40. package/dist/collections/mdx/runtime.js.map +1 -0
  41. package/dist/collections/mdx.d.ts +2 -10
  42. package/dist/collections/mdx.js +240 -284
  43. package/dist/collections/mdx.js.map +1 -0
  44. package/dist/collections/meta/loader-webpack.d.ts +6 -14
  45. package/dist/collections/meta/loader-webpack.d.ts.map +1 -0
  46. package/dist/collections/meta/loader-webpack.js +25 -39
  47. package/dist/collections/meta/loader-webpack.js.map +1 -0
  48. package/dist/collections/meta/runtime.d.ts +7 -15
  49. package/dist/collections/meta/runtime.d.ts.map +1 -0
  50. package/dist/collections/meta/runtime.js +9 -15
  51. package/dist/collections/meta/runtime.js.map +1 -0
  52. package/dist/collections/meta.d.ts +2 -10
  53. package/dist/collections/meta.js +128 -164
  54. package/dist/collections/meta.js.map +1 -0
  55. package/dist/collections/runtime/file-store.d.ts +17 -14
  56. package/dist/collections/runtime/file-store.d.ts.map +1 -0
  57. package/dist/collections/runtime/file-store.js +30 -6
  58. package/dist/collections/runtime/file-store.js.map +1 -0
  59. package/dist/collections/runtime/store.d.ts +3 -28
  60. package/dist/collections/runtime/store.js +3 -6
  61. package/dist/config/index.d.ts +2 -10
  62. package/dist/config/index.js +6 -5
  63. package/dist/config/index.js.map +1 -0
  64. package/dist/core-Bkh-SI_3.d.ts +561 -0
  65. package/dist/core-Bkh-SI_3.d.ts.map +1 -0
  66. package/dist/core-ZuoVBkeg.js +170 -0
  67. package/dist/core-ZuoVBkeg.js.map +1 -0
  68. package/dist/dynamic-B40uAtdo.js +28 -0
  69. package/dist/dynamic-B40uAtdo.js.map +1 -0
  70. package/dist/fuma-matter-O4fA6nSx.js +27 -0
  71. package/dist/fuma-matter-O4fA6nSx.js.map +1 -0
  72. package/dist/index.d.ts +13 -16
  73. package/dist/index.d.ts.map +1 -0
  74. package/dist/index.js +6 -8
  75. package/dist/load-from-file-1f4WaHsf.js +38 -0
  76. package/dist/load-from-file-1f4WaHsf.js.map +1 -0
  77. package/dist/load-from-file-BTNnBu6f.js +3 -0
  78. package/dist/loader-80abXEHx.js +4 -0
  79. package/dist/loader-BFhPyg3z.js +4 -0
  80. package/dist/loader-CXnMFuyE.js +80 -0
  81. package/dist/loader-CXnMFuyE.js.map +1 -0
  82. package/dist/loader-gk94iHf5.js +66 -0
  83. package/dist/loader-gk94iHf5.js.map +1 -0
  84. package/dist/next/index.cjs +459 -551
  85. package/dist/next/index.d.ts +16 -22
  86. package/dist/next/index.d.ts.map +1 -0
  87. package/dist/next/index.js +71 -89
  88. package/dist/next/index.js.map +1 -0
  89. package/dist/node/loader.d.ts +4 -2
  90. package/dist/node/loader.d.ts.map +1 -0
  91. package/dist/node/loader.js +32 -44
  92. package/dist/node/loader.js.map +1 -0
  93. package/dist/node-CGIIJIcs.js +31 -0
  94. package/dist/node-CGIIJIcs.js.map +1 -0
  95. package/dist/pipe-5cnvE6KY.js +31 -0
  96. package/dist/pipe-5cnvE6KY.js.map +1 -0
  97. package/dist/plugins/git.d.ts +2 -10
  98. package/dist/plugins/git.js +57 -65
  99. package/dist/plugins/git.js.map +1 -0
  100. package/dist/plugins/json-schema.d.ts +2 -10
  101. package/dist/plugins/json-schema.js +60 -58
  102. package/dist/plugins/json-schema.js.map +1 -0
  103. package/dist/plugins/with-loader/index.d.ts +2 -61
  104. package/dist/plugins/with-loader/index.js +28 -6
  105. package/dist/plugins/with-loader/index.js.map +1 -0
  106. package/dist/plugins/with-loader/webpack.d.ts +10 -18
  107. package/dist/plugins/with-loader/webpack.d.ts.map +1 -0
  108. package/dist/plugins/with-loader/webpack.js +43 -12
  109. package/dist/plugins/with-loader/webpack.js.map +1 -0
  110. package/dist/store-0LQ2PlH6.js +37 -0
  111. package/dist/store-0LQ2PlH6.js.map +1 -0
  112. package/dist/store-DEjYYF6a.d.ts +31 -0
  113. package/dist/store-DEjYYF6a.d.ts.map +1 -0
  114. package/dist/validation-BOJKRAp5.js +28 -0
  115. package/dist/validation-BOJKRAp5.js.map +1 -0
  116. package/dist/vite/index.d.ts +22 -28
  117. package/dist/vite/index.d.ts.map +1 -0
  118. package/dist/vite/index.js +37 -52
  119. package/dist/vite/index.js.map +1 -0
  120. package/dist/vite-X-2Al8fq.js +32 -0
  121. package/dist/vite-X-2Al8fq.js.map +1 -0
  122. package/package.json +7 -6
  123. package/dist/build-mdx-I4NROXCF.js +0 -8
  124. package/dist/bun-DMNX4PBC.js +0 -40
  125. package/dist/chunk-3VQS3KSP.js +0 -39
  126. package/dist/chunk-BTRE6MOX.js +0 -16
  127. package/dist/chunk-E4HRKSP4.js +0 -24
  128. package/dist/chunk-ERBMAQYP.js +0 -33
  129. package/dist/chunk-GGL4EF6H.js +0 -38
  130. package/dist/chunk-JBZTQ55D.js +0 -30
  131. package/dist/chunk-KH5GT2Y5.js +0 -104
  132. package/dist/chunk-LUM7SIZN.js +0 -40
  133. package/dist/chunk-MT7RY65Y.js +0 -167
  134. package/dist/chunk-NRZ4GE5O.js +0 -207
  135. package/dist/chunk-OQQNA7L7.js +0 -412
  136. package/dist/chunk-OUJENWQ4.js +0 -45
  137. package/dist/chunk-RMSV4HP6.js +0 -85
  138. package/dist/chunk-RXR7OL76.js +0 -37
  139. package/dist/chunk-VWJKRQZR.js +0 -19
  140. package/dist/chunk-W6HENTK7.js +0 -44
  141. package/dist/chunk-XR5N6ZXJ.js +0 -50
  142. package/dist/core-Bo8KaWQz.d.ts +0 -411
  143. package/dist/load-from-file-HL2VEY3M.js +0 -7
  144. package/dist/loader-NFSL6P5I.js +0 -7
  145. package/dist/loader-T756NSCS.js +0 -7
  146. package/dist/node-DCMYL4DL.js +0 -34
  147. package/dist/vite-QCUPZHHB.js +0 -32
@@ -1,207 +0,0 @@
1
- import {
2
- CodeGenerator
3
- } from "./chunk-MT7RY65Y.js";
4
-
5
- // src/core.ts
6
- import path from "path";
7
- import fs from "fs/promises";
8
- async function getPlugins(pluginOptions) {
9
- const plugins = [];
10
- for (const option of await Promise.all(pluginOptions)) {
11
- if (!option) continue;
12
- if (Array.isArray(option)) plugins.push(...await getPlugins(option));
13
- else plugins.push(option);
14
- }
15
- return plugins;
16
- }
17
- var Core = class _Core {
18
- workspaces = /* @__PURE__ */ new Map();
19
- options;
20
- plugins = [];
21
- config;
22
- static defaultOptions = {
23
- configPath: "content.config.ts",
24
- outDir: ".content"
25
- };
26
- /**
27
- * Convenient cache store, reset when config changes.
28
- *
29
- * You can group namespaces in cache key with ":", like `my-plugin:data`
30
- */
31
- cache = /* @__PURE__ */ new Map();
32
- constructor(options) {
33
- this.options = options;
34
- }
35
- async init({ config: newConfig }) {
36
- this.config = await newConfig;
37
- this.cache.clear();
38
- this.workspaces.clear();
39
- const loadedCollectionTypeIds = /* @__PURE__ */ new Set();
40
- this.plugins = await getPlugins([
41
- this.options.plugins,
42
- this.config.plugins,
43
- ...this.config.collections.values().map(({ typeInfo }) => {
44
- if (loadedCollectionTypeIds.has(typeInfo.id)) return false;
45
- loadedCollectionTypeIds.add(typeInfo.id);
46
- return typeInfo.plugins;
47
- })
48
- ]);
49
- const ctx = this.getPluginContext();
50
- for (const plugin of this.plugins) {
51
- const out = await plugin.config?.call(ctx, this.config);
52
- if (out) this.config = out;
53
- }
54
- const { workspace, outDir } = this.options;
55
- if (!workspace) {
56
- await Promise.all(
57
- Object.entries(this.config.workspaces).map(
58
- async ([name, workspace2]) => {
59
- const child = new _Core({
60
- ...this.options,
61
- outDir: path.join(outDir, name),
62
- workspace: {
63
- name,
64
- parent: this,
65
- dir: workspace2.dir
66
- }
67
- });
68
- await child.init({ config: workspace2.config });
69
- this.workspaces.set(name, child);
70
- }
71
- )
72
- );
73
- }
74
- await Promise.all(
75
- this.config.collections.values().map(async (collection) => {
76
- for (const plugin of this.plugins) {
77
- await plugin.collection?.call(ctx, collection);
78
- }
79
- })
80
- );
81
- }
82
- getWorkspaces() {
83
- return this.workspaces;
84
- }
85
- getOptions() {
86
- return this.options;
87
- }
88
- getConfig() {
89
- return this.config;
90
- }
91
- /**
92
- * The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
93
- */
94
- getCompiledConfigPath() {
95
- return path.join(this.options.outDir, "content.config.mjs");
96
- }
97
- getPlugins(workspace = false) {
98
- if (workspace) {
99
- const plugins = [...this.plugins];
100
- for (const workspace2 of this.workspaces.values()) {
101
- plugins.push(...workspace2.plugins);
102
- }
103
- return plugins;
104
- }
105
- return this.plugins;
106
- }
107
- getCollections(workspace = false) {
108
- const list = Array.from(this.config.collections.values());
109
- if (workspace) {
110
- for (const workspace2 of this.workspaces.values()) {
111
- list.push(...workspace2.getCollections());
112
- }
113
- }
114
- return list;
115
- }
116
- getCollection(name) {
117
- return this.config.collections.get(name);
118
- }
119
- getPluginContext() {
120
- return {
121
- core: this
122
- };
123
- }
124
- async initServer(server) {
125
- const ctx = this.getPluginContext();
126
- const promises = [];
127
- for (const plugin of this.plugins) {
128
- promises.push(plugin.configureServer?.call(ctx, server));
129
- }
130
- for (const workspace of this.workspaces.values()) {
131
- promises.push(workspace.initServer(server));
132
- }
133
- await Promise.all(promises);
134
- }
135
- async emit(emitOptions = {}) {
136
- const {
137
- workspace,
138
- outDir,
139
- emit: { target, jsExtension } = {}
140
- } = this.options;
141
- const { filterPlugin, filterWorkspace, write = false } = emitOptions;
142
- const start = performance.now();
143
- const globCache = /* @__PURE__ */ new Map();
144
- const ctx = {
145
- ...this.getPluginContext(),
146
- createCodeGenerator: async (path2, content) => {
147
- const codegen = new CodeGenerator({
148
- target,
149
- outDir,
150
- jsExtension,
151
- globCache
152
- });
153
- await content({
154
- core: this,
155
- codegen,
156
- workspace: workspace?.name
157
- });
158
- return {
159
- path: path2,
160
- content: codegen.toString()
161
- };
162
- }
163
- };
164
- const added = /* @__PURE__ */ new Set();
165
- const out = {
166
- entries: [],
167
- workspaces: {}
168
- };
169
- for (const li of await Promise.all(
170
- this.plugins.map((plugin) => {
171
- if (filterPlugin && !filterPlugin(plugin) || !plugin.emit)
172
- return null;
173
- return plugin.emit.call(ctx);
174
- })
175
- )) {
176
- if (!li) continue;
177
- for (const item of li) {
178
- if (added.has(item.path)) continue;
179
- out.entries.push(item);
180
- added.add(item.path);
181
- }
182
- }
183
- if (write) {
184
- await Promise.all(
185
- out.entries.map(async (entry) => {
186
- const file = path.join(outDir, entry.path);
187
- await fs.mkdir(path.dirname(file), { recursive: true });
188
- await fs.writeFile(file, entry.content);
189
- })
190
- );
191
- console.log(
192
- workspace ? `[MDX: ${workspace.name}] generated files in ${performance.now() - start}ms` : `[MDX] generated files in ${performance.now() - start}ms`
193
- );
194
- }
195
- await Promise.all(
196
- this.workspaces.entries().map(async ([name, workspace2]) => {
197
- if (filterWorkspace && !filterWorkspace(name)) return;
198
- out.workspaces[name] = (await workspace2.emit(emitOptions)).entries;
199
- })
200
- );
201
- return out;
202
- }
203
- };
204
-
205
- export {
206
- Core
207
- };
@@ -1,412 +0,0 @@
1
- import {
2
- fumaMatter
3
- } from "./chunk-VWJKRQZR.js";
4
- import {
5
- createCache
6
- } from "./chunk-JBZTQ55D.js";
7
-
8
- // src/collections/mdx/build-mdx.ts
9
- import { createProcessor } from "@mdx-js/mdx";
10
- import { VFile as VFile2 } from "vfile";
11
-
12
- // src/collections/mdx/remark-include.ts
13
- import {
14
- unified
15
- } from "unified";
16
- import { visit as visit2 } from "unist-util-visit";
17
- import * as path from "path";
18
- import * as fs from "fs/promises";
19
- import { VFile } from "vfile";
20
-
21
- // src/collections/mdx/remark-unravel.ts
22
- import { visit } from "unist-util-visit";
23
- function remarkMarkAndUnravel() {
24
- return (tree) => {
25
- visit(tree, (node, index, parent) => {
26
- let offset = -1;
27
- let all = true;
28
- let oneOrMore = false;
29
- if (parent && typeof index === "number" && node.type === "paragraph") {
30
- const children = node.children;
31
- while (++offset < children.length) {
32
- const child = children[offset];
33
- if (child.type === "mdxJsxTextElement" || child.type === "mdxTextExpression") {
34
- oneOrMore = true;
35
- } else if (child.type === "text" && child.value.trim().length === 0) {
36
- } else {
37
- all = false;
38
- break;
39
- }
40
- }
41
- if (all && oneOrMore) {
42
- offset = -1;
43
- const newChildren = [];
44
- while (++offset < children.length) {
45
- const child = children[offset];
46
- if (child.type === "mdxJsxTextElement") {
47
- child.type = "mdxJsxFlowElement";
48
- }
49
- if (child.type === "mdxTextExpression") {
50
- child.type = "mdxFlowExpression";
51
- }
52
- if (child.type === "text" && /^[\t\r\n ]+$/.test(String(child.value))) {
53
- } else {
54
- newChildren.push(child);
55
- }
56
- }
57
- parent.children.splice(index, 1, ...newChildren);
58
- return index;
59
- }
60
- }
61
- });
62
- };
63
- }
64
-
65
- // src/collections/mdx/mdast-utils.ts
66
- function flattenNode(node) {
67
- if ("children" in node)
68
- return node.children.map((child) => flattenNode(child)).join("");
69
- if ("value" in node) return node.value;
70
- return "";
71
- }
72
-
73
- // src/collections/mdx/remark-include.ts
74
- var ElementLikeTypes = [
75
- "mdxJsxFlowElement",
76
- "mdxJsxTextElement",
77
- "containerDirective",
78
- "textDirective",
79
- "leafDirective"
80
- ];
81
- function isElementLike(node) {
82
- return ElementLikeTypes.includes(node.type);
83
- }
84
- function parseElementAttributes(element) {
85
- if (Array.isArray(element.attributes)) {
86
- const attributes = {};
87
- for (const attr of element.attributes) {
88
- if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
89
- attributes[attr.name] = attr.value;
90
- }
91
- }
92
- return attributes;
93
- }
94
- return element.attributes ?? {};
95
- }
96
- function parseSpecifier(specifier) {
97
- const idx = specifier.lastIndexOf("#");
98
- if (idx === -1) return { file: specifier };
99
- return {
100
- file: specifier.slice(0, idx),
101
- section: specifier.slice(idx + 1)
102
- };
103
- }
104
- function extractSection(root, section) {
105
- let nodes;
106
- let capturingHeadingContent = false;
107
- visit2(root, (node) => {
108
- if (node.type === "heading") {
109
- if (capturingHeadingContent) {
110
- return false;
111
- }
112
- if (node.data?.hProperties?.id === section) {
113
- capturingHeadingContent = true;
114
- nodes = [node];
115
- return "skip";
116
- }
117
- return;
118
- }
119
- if (capturingHeadingContent) {
120
- nodes?.push(node);
121
- return "skip";
122
- }
123
- if (isElementLike(node) && node.name === "section") {
124
- const attributes = parseElementAttributes(node);
125
- if (attributes.id === section) {
126
- nodes = node.children;
127
- return false;
128
- }
129
- }
130
- });
131
- if (nodes)
132
- return {
133
- type: "root",
134
- children: nodes
135
- };
136
- }
137
- function remarkInclude({ preprocess = [] } = {}) {
138
- const TagName = "include";
139
- const preprocessor = unified().use(remarkMarkAndUnravel).use(preprocess);
140
- const embedContent = async (targetPath, heading, params, parent) => {
141
- const { _getProcessor = () => this, _compiler } = parent.data;
142
- let content;
143
- try {
144
- content = (await fs.readFile(targetPath)).toString();
145
- } catch (e) {
146
- throw new Error(
147
- `failed to read file ${targetPath}
148
- ${e instanceof Error ? e.message : String(e)}`,
149
- { cause: e }
150
- );
151
- }
152
- const ext = path.extname(targetPath);
153
- _compiler?.addDependency(targetPath);
154
- if (params.lang || ext !== ".md" && ext !== ".mdx") {
155
- const lang = params.lang ?? ext.slice(1);
156
- return {
157
- type: "code",
158
- lang,
159
- meta: params.meta,
160
- value: content,
161
- data: {}
162
- };
163
- }
164
- const parser = await _getProcessor(ext === ".mdx" ? "mdx" : "md");
165
- const parsed = fumaMatter(content);
166
- const targetFile = new VFile({
167
- path: targetPath,
168
- value: parsed.content,
169
- data: {
170
- ...parent.data,
171
- frontmatter: parsed.data
172
- }
173
- });
174
- let mdast = await preprocessor.run(
175
- parser.parse(targetFile),
176
- targetFile
177
- );
178
- if (heading) {
179
- const extracted = extractSection(mdast, heading);
180
- if (!extracted)
181
- throw new Error(
182
- `Cannot find section ${heading} in ${targetPath}, make sure you have encapsulated the section in a <section id="${heading}"> tag, or a :::section directive with remark-directive configured.`
183
- );
184
- mdast = extracted;
185
- }
186
- await update(mdast, targetFile);
187
- return mdast;
188
- };
189
- async function update(tree, file) {
190
- const queue = [];
191
- visit2(tree, ElementLikeTypes, (_node, _, parent) => {
192
- const node = _node;
193
- if (node.name !== TagName) return;
194
- const specifier = flattenNode(node);
195
- if (specifier.length === 0) return "skip";
196
- const attributes = parseElementAttributes(node);
197
- const { file: relativePath, section } = parseSpecifier(specifier);
198
- const targetPath = path.resolve(
199
- "cwd" in attributes ? file.cwd : file.dirname ?? "",
200
- relativePath
201
- );
202
- queue.push(
203
- embedContent(targetPath, section, attributes, file).then((replace) => {
204
- Object.assign(
205
- parent && parent.type === "paragraph" ? parent : node,
206
- replace
207
- );
208
- })
209
- );
210
- return "skip";
211
- });
212
- await Promise.all(queue);
213
- }
214
- return async (tree, file) => {
215
- await update(tree, file);
216
- };
217
- }
218
-
219
- // src/collections/mdx/remark-postprocess.ts
220
- import { visit as visit3 } from "unist-util-visit";
221
- import { toMarkdown } from "mdast-util-to-markdown";
222
- import { valueToEstree } from "estree-util-value-to-estree";
223
- import { removePosition } from "unist-util-remove-position";
224
- import remarkMdx from "remark-mdx";
225
- function remarkPostprocess({
226
- _format,
227
- includeProcessedMarkdown = false,
228
- includeMDAST = false,
229
- extractLinkReferences = false,
230
- valueToExport = []
231
- }) {
232
- let _stringifyProcessor;
233
- const getStringifyProcessor = () => {
234
- return _stringifyProcessor ??= _format === "mdx" ? this : (
235
- // force Markdown processor to stringify MDX nodes
236
- this().use(remarkMdx).freeze()
237
- );
238
- };
239
- return (tree, file) => {
240
- const frontmatter = file.data.frontmatter ??= {};
241
- if (!frontmatter.title) {
242
- visit3(tree, "heading", (node) => {
243
- if (node.depth === 1) {
244
- frontmatter.title = flattenNode(node);
245
- return false;
246
- }
247
- });
248
- }
249
- file.data["mdx-export"] ??= [];
250
- file.data["mdx-export"].push({
251
- name: "frontmatter",
252
- value: frontmatter
253
- });
254
- if (extractLinkReferences) {
255
- const urls = [];
256
- visit3(tree, "link", (node) => {
257
- urls.push({
258
- href: node.url
259
- });
260
- return "skip";
261
- });
262
- file.data["mdx-export"].push({
263
- name: "extractedReferences",
264
- value: urls
265
- });
266
- }
267
- if (includeProcessedMarkdown) {
268
- const processor = getStringifyProcessor();
269
- const markdown = toMarkdown(tree, {
270
- ...processor.data("settings"),
271
- // from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
272
- extensions: processor.data("toMarkdownExtensions") || []
273
- });
274
- file.data["mdx-export"].push({
275
- name: "_markdown",
276
- value: markdown
277
- });
278
- }
279
- if (includeMDAST) {
280
- const options = includeMDAST === true ? {} : includeMDAST;
281
- const mdast = JSON.stringify(
282
- options.removePosition ? removePosition(structuredClone(tree)) : tree
283
- );
284
- file.data["mdx-export"].push({
285
- name: "_mdast",
286
- value: mdast
287
- });
288
- }
289
- for (const { name, value } of file.data["mdx-export"]) {
290
- tree.children.unshift(getMdastExport(name, value));
291
- }
292
- file.data["mdx-export"] = [];
293
- for (const name of valueToExport) {
294
- if (!(name in file.data)) continue;
295
- tree.children.unshift(getMdastExport(name, file.data[name]));
296
- }
297
- };
298
- }
299
- function getMdastExport(name, value) {
300
- return {
301
- type: "mdxjsEsm",
302
- value: "",
303
- data: {
304
- estree: {
305
- type: "Program",
306
- sourceType: "module",
307
- body: [
308
- {
309
- type: "ExportNamedDeclaration",
310
- specifiers: [],
311
- attributes: [],
312
- source: null,
313
- declaration: {
314
- type: "VariableDeclaration",
315
- kind: "let",
316
- declarations: [
317
- {
318
- type: "VariableDeclarator",
319
- id: {
320
- type: "Identifier",
321
- name
322
- },
323
- init: valueToEstree(value)
324
- }
325
- ]
326
- }
327
- }
328
- ]
329
- }
330
- }
331
- };
332
- }
333
-
334
- // src/collections/mdx/remark-preprocess.ts
335
- function remarkPreprocess(options) {
336
- return async (tree, file) => {
337
- if (file.data._preprocessed) return;
338
- file.data._preprocessed = true;
339
- if (options?.preprocessor) {
340
- return await options.preprocessor.run(tree);
341
- }
342
- };
343
- }
344
-
345
- // src/collections/mdx/build-mdx.ts
346
- async function buildMDX(core, collection, {
347
- filePath,
348
- frontmatter,
349
- source,
350
- _compiler,
351
- environment,
352
- isDevelopment
353
- }) {
354
- const handler = collection?.handlers.mdx;
355
- const processorCache = createCache(core.cache);
356
- function getProcessor(format) {
357
- const key = `build-mdx:${collection?.name ?? "global"}:${format}`;
358
- return processorCache.cached(key, async () => {
359
- const mdxOptions = await handler?.getMDXOptions?.(environment);
360
- const preprocessPlugin = [
361
- remarkPreprocess,
362
- handler?.preprocess
363
- ];
364
- const postprocessOptions = {
365
- _format: format,
366
- ...handler?.postprocess
367
- };
368
- const remarkIncludeOptions = {
369
- preprocess: [preprocessPlugin]
370
- };
371
- return createProcessor({
372
- outputFormat: "program",
373
- development: isDevelopment,
374
- ...mdxOptions,
375
- remarkPlugins: [
376
- preprocessPlugin,
377
- [remarkInclude, remarkIncludeOptions],
378
- ...mdxOptions?.remarkPlugins ?? [],
379
- [remarkPostprocess, postprocessOptions]
380
- ],
381
- format
382
- });
383
- });
384
- }
385
- let vfile = new VFile2({
386
- value: source,
387
- path: filePath,
388
- cwd: handler?.cwd,
389
- data: {
390
- frontmatter,
391
- _compiler,
392
- _getProcessor: getProcessor
393
- }
394
- });
395
- if (collection && handler?.vfile) {
396
- vfile = await handler.vfile.call(
397
- {
398
- collection,
399
- filePath,
400
- source
401
- },
402
- vfile
403
- );
404
- }
405
- return (await getProcessor(filePath.endsWith(".mdx") ? "mdx" : "md")).process(
406
- vfile
407
- );
408
- }
409
-
410
- export {
411
- buildMDX
412
- };
@@ -1,45 +0,0 @@
1
- // src/utils/validation.ts
2
- var ValidationError = class extends Error {
3
- title;
4
- issues;
5
- constructor(message, issues) {
6
- super(
7
- `${message}:
8
- ${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
9
- );
10
- this.title = message;
11
- this.issues = issues;
12
- }
13
- async toStringFormatted() {
14
- const picocolorsModule = await import("picocolors");
15
- const picocolors = picocolorsModule.default ?? picocolorsModule;
16
- return [
17
- picocolors.bold(`[MDX] ${this.title}:`),
18
- ...this.issues.map(
19
- (issue) => picocolors.redBright(
20
- `- ${picocolors.bold(issue.path?.join(".") ?? "*")}: ${issue.message}`
21
- )
22
- )
23
- ].join("\n");
24
- }
25
- };
26
- async function validate(schema, data, context, errorMessage) {
27
- if (typeof schema === "function" && !("~standard" in schema)) {
28
- schema = schema(context);
29
- }
30
- if ("~standard" in schema) {
31
- const result = await schema["~standard"].validate(
32
- data
33
- );
34
- if (result.issues) {
35
- throw new ValidationError(errorMessage, result.issues);
36
- }
37
- return result.value;
38
- }
39
- return data;
40
- }
41
-
42
- export {
43
- ValidationError,
44
- validate
45
- };