fuma-content 1.0.0 → 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 (146) 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 -33
  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 -35
  28. package/dist/collections/mdx/loader-webpack.js.map +1 -0
  29. package/dist/collections/mdx/runtime-browser.d.ts +33 -32
  30. package/dist/collections/mdx/runtime-browser.d.ts.map +1 -0
  31. package/dist/collections/mdx/runtime-browser.js +57 -62
  32. package/dist/collections/mdx/runtime-browser.js.map +1 -0
  33. package/dist/collections/mdx/runtime-dynamic.d.ts +24 -31
  34. package/dist/collections/mdx/runtime-dynamic.d.ts.map +1 -0
  35. package/dist/collections/mdx/runtime-dynamic.js +63 -83
  36. package/dist/collections/mdx/runtime-dynamic.js.map +1 -0
  37. package/dist/collections/mdx/runtime.d.ts +34 -54
  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 -280
  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 -38
  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 -160
  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 -14
  73. package/dist/index.d.ts.map +1 -0
  74. package/dist/index.js +6 -0
  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 -528
  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 -88
  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 -43
  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 -11
  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 -51
  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 +15 -13
  123. package/dist/build-mdx-Q4RMDWYK.js +0 -8
  124. package/dist/bun-DMNX4PBC.js +0 -40
  125. package/dist/chunk-3VQS3KSP.js +0 -39
  126. package/dist/chunk-4RMSJCK2.js +0 -50
  127. package/dist/chunk-6XDQG2GV.js +0 -17
  128. package/dist/chunk-AMBGM4OK.js +0 -412
  129. package/dist/chunk-BTRE6MOX.js +0 -16
  130. package/dist/chunk-E4HRKSP4.js +0 -24
  131. package/dist/chunk-ERBMAQYP.js +0 -33
  132. package/dist/chunk-IGLM4N4P.js +0 -34
  133. package/dist/chunk-LDBQ66H3.js +0 -38
  134. package/dist/chunk-M72VQL5M.js +0 -40
  135. package/dist/chunk-OUJENWQ4.js +0 -45
  136. package/dist/chunk-PNA5UGSL.js +0 -104
  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-Z7KHD7MS.js +0 -368
  141. package/dist/core-DxnSmTRe.d.ts +0 -411
  142. package/dist/load-from-file-MLL4WQ5J.js +0 -7
  143. package/dist/loader-T756NSCS.js +0 -7
  144. package/dist/loader-VGDLYG4T.js +0 -7
  145. package/dist/node-DCMYL4DL.js +0 -34
  146. package/dist/vite-QCUPZHHB.js +0 -32
@@ -0,0 +1,32 @@
1
+ import { parse } from "node:querystring";
2
+
3
+ //#region src/plugins/with-loader/vite.ts
4
+ function toVite(name, test, loader) {
5
+ return {
6
+ name: `fuma-content:${name}`,
7
+ async transform(value, id) {
8
+ if (test && !test.test(id)) return;
9
+ const [file, query = ""] = id.split("?", 2);
10
+ const result = await loader.load({
11
+ filePath: file,
12
+ query: parse(query),
13
+ getSource() {
14
+ return value;
15
+ },
16
+ development: this.environment.mode === "dev",
17
+ compiler: { addDependency: (file$1) => {
18
+ this.addWatchFile(file$1);
19
+ } }
20
+ });
21
+ if (result === null) return null;
22
+ return {
23
+ code: result.code,
24
+ map: result.map
25
+ };
26
+ }
27
+ };
28
+ }
29
+
30
+ //#endregion
31
+ export { toVite };
32
+ //# sourceMappingURL=vite-X-2Al8fq.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-X-2Al8fq.js","names":["file"],"sources":["../src/plugins/with-loader/vite.ts"],"sourcesContent":["import type { SourceMap } from \"rollup\";\nimport type { PluginOption } from \"vite\";\nimport { parse } from \"node:querystring\";\nimport type { Loader } from \"@/plugins/with-loader\";\n\nexport function toVite(\n name: string,\n test: RegExp | undefined,\n loader: Loader,\n): PluginOption {\n return {\n name: `fuma-content:${name}`,\n async transform(value, id) {\n if (test && !test.test(id)) return;\n\n const [file, query = \"\"] = id.split(\"?\", 2);\n const result = await loader.load({\n filePath: file,\n query: parse(query),\n getSource() {\n return value;\n },\n development: this.environment.mode === \"dev\",\n compiler: {\n addDependency: (file) => {\n this.addWatchFile(file);\n },\n },\n });\n\n if (result === null) return null;\n return {\n code: result.code,\n map: result.map as SourceMap,\n };\n },\n };\n}\n"],"mappings":";;;AAKA,SAAgB,OACd,MACA,MACA,QACc;AACd,QAAO;EACL,MAAM,gBAAgB;EACtB,MAAM,UAAU,OAAO,IAAI;AACzB,OAAI,QAAQ,CAAC,KAAK,KAAK,GAAG,CAAE;GAE5B,MAAM,CAAC,MAAM,QAAQ,MAAM,GAAG,MAAM,KAAK,EAAE;GAC3C,MAAM,SAAS,MAAM,OAAO,KAAK;IAC/B,UAAU;IACV,OAAO,MAAM,MAAM;IACnB,YAAY;AACV,YAAO;;IAET,aAAa,KAAK,YAAY,SAAS;IACvC,UAAU,EACR,gBAAgB,WAAS;AACvB,UAAK,aAAaA,OAAK;OAE1B;IACF,CAAC;AAEF,OAAI,WAAW,KAAM,QAAO;AAC5B,UAAO;IACL,MAAM,OAAO;IACb,KAAK,OAAO;IACb;;EAEJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fuma-content",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "The content processing layer for your app.",
5
5
  "keywords": [
6
6
  "Docs",
@@ -65,9 +65,9 @@
65
65
  ],
66
66
  "dependencies": {
67
67
  "@mdx-js/mdx": "^3.1.1",
68
- "@standard-schema/spec": "^1.0.0",
68
+ "@standard-schema/spec": "^1.1.0",
69
69
  "chokidar": "^5.0.0",
70
- "esbuild": "^0.27.1",
70
+ "esbuild": "^0.27.2",
71
71
  "estree-util-value-to-estree": "^3.5.0",
72
72
  "js-yaml": "^4.1.1",
73
73
  "mdast-util-to-markdown": "^2.1.2",
@@ -80,27 +80,29 @@
80
80
  "unist-util-remove-position": "^5.0.0",
81
81
  "unist-util-visit": "^5.0.0",
82
82
  "vfile": "^6.0.3",
83
- "zod": "^4.1.13"
83
+ "zod": "^4.2.1"
84
84
  },
85
85
  "devDependencies": {
86
- "@types/bun": "^1.3.4",
86
+ "@types/bun": "^1.3.5",
87
87
  "@types/js-yaml": "^4.0.9",
88
88
  "@types/mdast": "^4.0.4",
89
89
  "@types/mdx": "^2.0.13",
90
- "@types/node": "^24.10.2",
90
+ "@types/node": "^24.10.4",
91
91
  "@types/picomatch": "^4.0.2",
92
92
  "@types/react": "^19.2.7",
93
- "fumadocs-core": "^16.2.5",
93
+ "fumadocs-core": "^16.3.2",
94
94
  "mdast-util-directive": "^3.1.0",
95
95
  "mdast-util-mdx-jsx": "^3.2.0",
96
- "next": "16.0.10",
96
+ "next": "16.1.0",
97
97
  "react": "^19.2.3",
98
98
  "remark": "^15.0.1",
99
99
  "remark-directive": "^4.0.0",
100
100
  "remark-stringify": "^11.0.0",
101
- "rollup": "^4.53.3",
102
- "vite": "^7.2.7",
103
- "webpack": "^5.103.0",
101
+ "rollup": "^4.54.0",
102
+ "tsdown": "^0.18.2",
103
+ "typescript": "^5.9.3",
104
+ "vite": "^7.3.0",
105
+ "webpack": "^5.104.1",
104
106
  "typescript-config": "0.0.0"
105
107
  },
106
108
  "peerDependencies": {
@@ -123,9 +125,9 @@
123
125
  "access": "public"
124
126
  },
125
127
  "scripts": {
126
- "build": "tsup",
128
+ "build": "tsdown",
127
129
  "clean": "rimraf dist",
128
- "dev": "tsup --watch",
130
+ "dev": "tsdown --watch",
129
131
  "types:check": "tsc --noEmit"
130
132
  }
131
133
  }
@@ -1,8 +0,0 @@
1
- import {
2
- buildMDX
3
- } from "./chunk-AMBGM4OK.js";
4
- import "./chunk-VWJKRQZR.js";
5
- import "./chunk-6XDQG2GV.js";
6
- export {
7
- buildMDX
8
- };
@@ -1,40 +0,0 @@
1
- // src/plugins/with-loader/bun.ts
2
- import { parse } from "querystring";
3
- import { readFileSync } from "fs";
4
- function toBun(test = /.+/, loader) {
5
- function toResult(output) {
6
- if (!output) return;
7
- return {
8
- contents: output.code,
9
- loader: "js"
10
- };
11
- }
12
- return (build) => {
13
- build.onLoad({ filter: test }, (args) => {
14
- const [filePath, query = ""] = args.path.split("?", 2);
15
- const input = {
16
- async getSource() {
17
- return Bun.file(filePath).text();
18
- },
19
- query: parse(query),
20
- filePath,
21
- development: false,
22
- compiler: {
23
- addDependency() {
24
- }
25
- }
26
- };
27
- if (loader.bun?.load) {
28
- return loader.bun.load(readFileSync(filePath).toString(), input);
29
- }
30
- const result = loader.load(input);
31
- if (result instanceof Promise) {
32
- return result.then(toResult);
33
- }
34
- return toResult(result);
35
- });
36
- };
37
- }
38
- export {
39
- toBun
40
- };
@@ -1,39 +0,0 @@
1
- // src/collections/runtime/store.ts
2
- var SimpleCollectionStore = class {
3
- dataMap;
4
- dataList;
5
- constructor(input) {
6
- this.dataMap = input;
7
- this.dataList = Array.from(input.values());
8
- }
9
- get(id) {
10
- return this.dataMap.get(id);
11
- }
12
- list() {
13
- return this.dataList;
14
- }
15
- $data(_cast) {
16
- return this;
17
- }
18
- /**
19
- * in-place transformation on all data
20
- */
21
- transform(fn) {
22
- this.dataList.length = 0;
23
- const dataMap = this.dataMap;
24
- const dataList = this.dataList;
25
- for (const [k, v] of this.dataMap) {
26
- const updated = fn(v);
27
- dataMap.set(k, updated);
28
- dataList.push(updated);
29
- }
30
- return this;
31
- }
32
- get $inferData() {
33
- return void 0;
34
- }
35
- };
36
-
37
- export {
38
- SimpleCollectionStore
39
- };
@@ -1,50 +0,0 @@
1
- import {
2
- ValidationError
3
- } from "./chunk-OUJENWQ4.js";
4
- import {
5
- Core
6
- } from "./chunk-Z7KHD7MS.js";
7
-
8
- // src/plugins/with-loader/webpack.ts
9
- import { parse } from "querystring";
10
- import path from "path";
11
- var core;
12
- function getCore(options) {
13
- return core ??= new Core({
14
- outDir: options.outDir,
15
- configPath: options.configPath
16
- });
17
- }
18
- function toWebpack(loader) {
19
- return async function(source, callback) {
20
- try {
21
- const result = await loader.load({
22
- filePath: this.resourcePath,
23
- query: parse(this.resourceQuery.slice(1)),
24
- getSource() {
25
- return source;
26
- },
27
- development: this.mode === "development",
28
- compiler: this
29
- });
30
- if (result === null) {
31
- callback(void 0, source);
32
- } else {
33
- callback(void 0, result.code, result.map);
34
- }
35
- } catch (error) {
36
- if (error instanceof ValidationError) {
37
- return callback(new Error(await error.toStringFormatted()));
38
- }
39
- if (!(error instanceof Error)) throw error;
40
- const fpath = path.relative(this.context, this.resourcePath);
41
- error.message = `${fpath}:${error.name}: ${error.message}`;
42
- callback(error);
43
- }
44
- };
45
- }
46
-
47
- export {
48
- getCore,
49
- toWebpack
50
- };
@@ -1,17 +0,0 @@
1
- // src/utils/async-cache.ts
2
- function createCache(store = /* @__PURE__ */ new Map()) {
3
- return {
4
- store,
5
- cached(key, fn) {
6
- let cached = store.get(key);
7
- if (cached) return cached;
8
- cached = fn();
9
- store.set(key, cached);
10
- return cached;
11
- }
12
- };
13
- }
14
-
15
- export {
16
- createCache
17
- };
@@ -1,412 +0,0 @@
1
- import {
2
- fumaMatter
3
- } from "./chunk-VWJKRQZR.js";
4
- import {
5
- createCache
6
- } from "./chunk-6XDQG2GV.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,16 +0,0 @@
1
- // src/collections/index.ts
2
- function createCollection(info, init) {
3
- return {
4
- name: "",
5
- handlers: {},
6
- init(options) {
7
- this.name = options.name;
8
- init(this, options);
9
- },
10
- typeInfo: info
11
- };
12
- }
13
-
14
- export {
15
- createCollection
16
- };