fuma-content 0.0.1 → 1.0.0
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/dist/bin.d.ts +1 -0
- package/dist/bin.js +18 -0
- package/dist/build-mdx-Q4RMDWYK.js +8 -0
- package/dist/bun/index.d.ts +16 -0
- package/dist/bun/index.js +36 -0
- package/dist/bun-DMNX4PBC.js +40 -0
- package/dist/chunk-3VQS3KSP.js +39 -0
- package/dist/chunk-4RMSJCK2.js +50 -0
- package/dist/chunk-6XDQG2GV.js +17 -0
- package/dist/chunk-AMBGM4OK.js +412 -0
- package/dist/chunk-BTRE6MOX.js +16 -0
- package/dist/chunk-E4HRKSP4.js +24 -0
- package/dist/chunk-ERBMAQYP.js +33 -0
- package/dist/chunk-IGLM4N4P.js +34 -0
- package/dist/chunk-LDBQ66H3.js +38 -0
- package/dist/chunk-M72VQL5M.js +40 -0
- package/dist/chunk-OUJENWQ4.js +45 -0
- package/dist/chunk-PNA5UGSL.js +104 -0
- package/dist/chunk-RMSV4HP6.js +85 -0
- package/dist/chunk-RXR7OL76.js +37 -0
- package/dist/chunk-VWJKRQZR.js +19 -0
- package/dist/chunk-Z7KHD7MS.js +368 -0
- package/dist/collections/handlers/fs.d.ts +10 -0
- package/dist/collections/handlers/fs.js +6 -0
- package/dist/collections/index.d.ts +10 -0
- package/dist/collections/index.js +6 -0
- package/dist/collections/mdx/loader-webpack.d.ts +17 -0
- package/dist/collections/mdx/loader-webpack.js +38 -0
- package/dist/collections/mdx/runtime-browser.d.ts +44 -0
- package/dist/collections/mdx/runtime-browser.js +74 -0
- package/dist/collections/mdx/runtime-dynamic.d.ts +42 -0
- package/dist/collections/mdx/runtime-dynamic.js +94 -0
- package/dist/collections/mdx/runtime.d.ts +69 -0
- package/dist/collections/mdx/runtime.js +45 -0
- package/dist/collections/mdx.d.ts +10 -0
- package/dist/collections/mdx.js +287 -0
- package/dist/collections/meta/loader-webpack.d.ts +17 -0
- package/dist/collections/meta/loader-webpack.js +41 -0
- package/dist/collections/meta/runtime.d.ts +19 -0
- package/dist/collections/meta/runtime.js +18 -0
- package/dist/collections/meta.d.ts +10 -0
- package/dist/collections/meta.js +166 -0
- package/dist/collections/runtime/file-store.d.ts +19 -0
- package/dist/collections/runtime/file-store.js +7 -0
- package/dist/collections/runtime/store.d.ts +28 -0
- package/dist/collections/runtime/store.js +6 -0
- package/dist/config/index.d.ts +10 -0
- package/dist/config/index.js +7 -0
- package/dist/core-DxnSmTRe.d.ts +411 -0
- package/dist/index.d.ts +13 -31
- package/dist/index.js +0 -53
- package/dist/load-from-file-MLL4WQ5J.js +7 -0
- package/dist/loader-T756NSCS.js +7 -0
- package/dist/loader-VGDLYG4T.js +7 -0
- package/dist/next/index.cjs +571 -0
- package/dist/next/index.d.ts +27 -0
- package/dist/next/index.js +99 -0
- package/dist/node/loader.d.ts +5 -0
- package/dist/node/loader.js +46 -0
- package/dist/node-DCMYL4DL.js +34 -0
- package/dist/plugins/git.d.ts +10 -0
- package/dist/plugins/git.js +70 -0
- package/dist/plugins/json-schema.d.ts +10 -0
- package/dist/plugins/json-schema.js +59 -0
- package/dist/plugins/with-loader/index.d.ts +61 -0
- package/dist/plugins/with-loader/index.js +6 -0
- package/dist/plugins/with-loader/webpack.d.ts +27 -0
- package/dist/plugins/with-loader/webpack.js +11 -0
- package/dist/vite/index.d.ts +33 -0
- package/dist/vite/index.js +60 -0
- package/dist/vite-QCUPZHHB.js +32 -0
- package/package.json +103 -36
- package/dist/internal.d.ts +0 -108
- package/dist/internal.js +0 -384
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildMDX
|
|
3
|
+
} from "../../chunk-AMBGM4OK.js";
|
|
4
|
+
import {
|
|
5
|
+
FileCollectionStore
|
|
6
|
+
} from "../../chunk-RXR7OL76.js";
|
|
7
|
+
import {
|
|
8
|
+
fumaMatter
|
|
9
|
+
} from "../../chunk-VWJKRQZR.js";
|
|
10
|
+
import "../../chunk-3VQS3KSP.js";
|
|
11
|
+
import {
|
|
12
|
+
buildConfig
|
|
13
|
+
} from "../../chunk-IGLM4N4P.js";
|
|
14
|
+
import {
|
|
15
|
+
Core
|
|
16
|
+
} from "../../chunk-Z7KHD7MS.js";
|
|
17
|
+
import {
|
|
18
|
+
createCache
|
|
19
|
+
} from "../../chunk-6XDQG2GV.js";
|
|
20
|
+
|
|
21
|
+
// src/collections/mdx/runtime-dynamic.ts
|
|
22
|
+
import { pathToFileURL } from "url";
|
|
23
|
+
import fs from "fs/promises";
|
|
24
|
+
import jsxRuntimeDefault from "react/jsx-runtime";
|
|
25
|
+
import path from "path";
|
|
26
|
+
var core;
|
|
27
|
+
async function mdxStoreDynamic(config, coreOptions, name, base, _frontmatter) {
|
|
28
|
+
core ??= (async () => {
|
|
29
|
+
const core2 = new Core(coreOptions);
|
|
30
|
+
await core2.init({
|
|
31
|
+
config: buildConfig(config)
|
|
32
|
+
});
|
|
33
|
+
return core2;
|
|
34
|
+
})();
|
|
35
|
+
const frontmatter = _frontmatter;
|
|
36
|
+
const collection = (await core).getCollection(name);
|
|
37
|
+
if (!collection || !collection.handlers.mdx)
|
|
38
|
+
throw new Error("invalid collection name");
|
|
39
|
+
const merged = {};
|
|
40
|
+
const cache = createCache();
|
|
41
|
+
for (const [k, v] of Object.entries(frontmatter)) {
|
|
42
|
+
merged[k] = {
|
|
43
|
+
id: k,
|
|
44
|
+
frontmatter: v,
|
|
45
|
+
async compile() {
|
|
46
|
+
return cache.cached(k, async () => {
|
|
47
|
+
const filePath = path.join(base, k);
|
|
48
|
+
let content = (await fs.readFile(filePath)).toString();
|
|
49
|
+
content = fumaMatter(content).content;
|
|
50
|
+
const compiled = await buildMDX(await core, collection, {
|
|
51
|
+
filePath,
|
|
52
|
+
source: content,
|
|
53
|
+
frontmatter: v,
|
|
54
|
+
isDevelopment: false,
|
|
55
|
+
environment: "runtime"
|
|
56
|
+
});
|
|
57
|
+
return await executeMdx(String(compiled.value), {
|
|
58
|
+
baseUrl: pathToFileURL(filePath)
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return new FileCollectionStore(base, merged);
|
|
65
|
+
}
|
|
66
|
+
var AsyncFunction = Object.getPrototypeOf(executeMdx).constructor;
|
|
67
|
+
async function executeMdx(compiled, options = {}) {
|
|
68
|
+
const { opts: scopeOpts, ...scope } = options.scope ?? {};
|
|
69
|
+
const fullScope = {
|
|
70
|
+
opts: {
|
|
71
|
+
...scopeOpts,
|
|
72
|
+
...options.jsxRuntime ?? jsxRuntimeDefault,
|
|
73
|
+
baseUrl: options.baseUrl
|
|
74
|
+
},
|
|
75
|
+
...scope
|
|
76
|
+
};
|
|
77
|
+
const hydrateFn = new AsyncFunction(...Object.keys(fullScope), compiled);
|
|
78
|
+
return await hydrateFn.apply(hydrateFn, Object.values(fullScope));
|
|
79
|
+
}
|
|
80
|
+
function $attachCompiled() {
|
|
81
|
+
return (data) => data;
|
|
82
|
+
}
|
|
83
|
+
function $extractedReferences() {
|
|
84
|
+
return $attachCompiled();
|
|
85
|
+
}
|
|
86
|
+
function $versionControl() {
|
|
87
|
+
return $attachCompiled();
|
|
88
|
+
}
|
|
89
|
+
export {
|
|
90
|
+
$attachCompiled,
|
|
91
|
+
$extractedReferences,
|
|
92
|
+
$versionControl,
|
|
93
|
+
mdxStoreDynamic
|
|
94
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { GetCollectionConfig } from '../../index.js';
|
|
2
|
+
import { M as MDXCollection, E as ExtractedReference, V as VersionControlFileData } from '../../core-DxnSmTRe.js';
|
|
3
|
+
import { FileCollectionStore } from '../runtime/file-store.js';
|
|
4
|
+
import { FC } from 'react';
|
|
5
|
+
import { MDXProps } from 'mdx/types';
|
|
6
|
+
import 'chokidar';
|
|
7
|
+
import '@mdx-js/mdx';
|
|
8
|
+
import 'vfile';
|
|
9
|
+
import '@standard-schema/spec';
|
|
10
|
+
import 'unified';
|
|
11
|
+
import 'mdast';
|
|
12
|
+
import 'vite';
|
|
13
|
+
import 'next';
|
|
14
|
+
import 'node:module';
|
|
15
|
+
import '../runtime/store.js';
|
|
16
|
+
|
|
17
|
+
type CompiledMDXProperties<Frontmatter = Record<string, unknown>> = {
|
|
18
|
+
frontmatter: Frontmatter;
|
|
19
|
+
default: FC<MDXProps>;
|
|
20
|
+
/**
|
|
21
|
+
* Enable from `postprocess` option.
|
|
22
|
+
*/
|
|
23
|
+
_markdown?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Enable from `postprocess` option.
|
|
26
|
+
*/
|
|
27
|
+
_mdast?: string;
|
|
28
|
+
} & Record<string, unknown>;
|
|
29
|
+
interface MDXStoreData<Frontmatter> {
|
|
30
|
+
id: string;
|
|
31
|
+
compiled: CompiledMDXProperties<Frontmatter>;
|
|
32
|
+
}
|
|
33
|
+
declare function mdxStore<Config, Name extends string>(_name: Name, base: string, _input: Record<string, unknown>): FileCollectionStore<MDXStoreData<GetCollectionConfig<Config, Name> extends MDXCollection<infer Frontmatter> ? Frontmatter : never>>;
|
|
34
|
+
interface MDXStoreLazyData<Frontmatter> {
|
|
35
|
+
id: string;
|
|
36
|
+
frontmatter: Frontmatter;
|
|
37
|
+
load: () => Promise<CompiledMDXProperties<Frontmatter>>;
|
|
38
|
+
}
|
|
39
|
+
declare function mdxStoreLazy<Config, Name extends string>(_name: Name, base: string, _input: {
|
|
40
|
+
head: Record<string, unknown>;
|
|
41
|
+
body: Record<string, () => Promise<unknown>>;
|
|
42
|
+
}): FileCollectionStore<MDXStoreLazyData<GetCollectionConfig<Config, Name> extends MDXCollection<infer Frontmatter> ? Frontmatter : never>>;
|
|
43
|
+
declare function $attachCompiled<Add>(): <T>(data: T) => T extends MDXStoreData<unknown> ? T & {
|
|
44
|
+
compiled: Add;
|
|
45
|
+
} : T extends MDXStoreLazyData<unknown> ? T & {
|
|
46
|
+
load: () => Promise<Awaited<ReturnType<T["load"]>> & Add>;
|
|
47
|
+
} : T;
|
|
48
|
+
declare function $extractedReferences(): <T>(data: T) => T extends MDXStoreData<unknown> ? T & {
|
|
49
|
+
compiled: {
|
|
50
|
+
/**
|
|
51
|
+
* extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
|
|
52
|
+
*/
|
|
53
|
+
extractedReferences: ExtractedReference[];
|
|
54
|
+
};
|
|
55
|
+
} : T extends MDXStoreLazyData<unknown> ? T & {
|
|
56
|
+
load: () => Promise<Awaited<ReturnType<T["load"]>> & {
|
|
57
|
+
/**
|
|
58
|
+
* extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
|
|
59
|
+
*/
|
|
60
|
+
extractedReferences: ExtractedReference[];
|
|
61
|
+
}>;
|
|
62
|
+
} : T;
|
|
63
|
+
declare function $versionControl(): <T>(data: T) => T extends MDXStoreData<unknown> ? T & {
|
|
64
|
+
compiled: VersionControlFileData;
|
|
65
|
+
} : T extends MDXStoreLazyData<unknown> ? T & {
|
|
66
|
+
load: () => Promise<Awaited<ReturnType<T["load"]>> & VersionControlFileData>;
|
|
67
|
+
} : T;
|
|
68
|
+
|
|
69
|
+
export { $attachCompiled, $extractedReferences, $versionControl, type CompiledMDXProperties, type MDXStoreData, type MDXStoreLazyData, mdxStore, mdxStoreLazy };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FileCollectionStore
|
|
3
|
+
} from "../../chunk-RXR7OL76.js";
|
|
4
|
+
import "../../chunk-3VQS3KSP.js";
|
|
5
|
+
|
|
6
|
+
// src/collections/mdx/runtime.ts
|
|
7
|
+
function mdxStore(_name, base, _input) {
|
|
8
|
+
const input = _input;
|
|
9
|
+
const merged = input;
|
|
10
|
+
for (const [key, value] of Object.entries(input)) {
|
|
11
|
+
merged[key] = {
|
|
12
|
+
id: key,
|
|
13
|
+
compiled: value
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return new FileCollectionStore(base, merged);
|
|
17
|
+
}
|
|
18
|
+
function mdxStoreLazy(_name, base, _input) {
|
|
19
|
+
const input = _input;
|
|
20
|
+
const merged = {};
|
|
21
|
+
for (const [key, value] of Object.entries(input.head)) {
|
|
22
|
+
merged[key] = {
|
|
23
|
+
id: key,
|
|
24
|
+
frontmatter: value,
|
|
25
|
+
load: input.body[key]
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return new FileCollectionStore(base, merged);
|
|
29
|
+
}
|
|
30
|
+
function $attachCompiled() {
|
|
31
|
+
return (data) => data;
|
|
32
|
+
}
|
|
33
|
+
function $extractedReferences() {
|
|
34
|
+
return $attachCompiled();
|
|
35
|
+
}
|
|
36
|
+
function $versionControl() {
|
|
37
|
+
return $attachCompiled();
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
$attachCompiled,
|
|
41
|
+
$extractedReferences,
|
|
42
|
+
$versionControl,
|
|
43
|
+
mdxStore,
|
|
44
|
+
mdxStoreLazy
|
|
45
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { M as MDXCollection, b as MDXCollectionConfig, o as MDXCollectionHandler, p as defineMDX } from '../core-DxnSmTRe.js';
|
|
2
|
+
import '@mdx-js/mdx';
|
|
3
|
+
import 'vfile';
|
|
4
|
+
import '@standard-schema/spec';
|
|
5
|
+
import 'chokidar';
|
|
6
|
+
import 'unified';
|
|
7
|
+
import 'mdast';
|
|
8
|
+
import 'vite';
|
|
9
|
+
import 'next';
|
|
10
|
+
import 'node:module';
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import {
|
|
2
|
+
withLoader
|
|
3
|
+
} from "../chunk-ERBMAQYP.js";
|
|
4
|
+
import {
|
|
5
|
+
buildFileHandler
|
|
6
|
+
} from "../chunk-E4HRKSP4.js";
|
|
7
|
+
import {
|
|
8
|
+
createCollection
|
|
9
|
+
} from "../chunk-BTRE6MOX.js";
|
|
10
|
+
|
|
11
|
+
// src/collections/mdx.ts
|
|
12
|
+
import path from "path";
|
|
13
|
+
var mdxTypeInfo = {
|
|
14
|
+
id: "mdx",
|
|
15
|
+
plugins: [plugin()]
|
|
16
|
+
};
|
|
17
|
+
var RuntimePaths = {
|
|
18
|
+
browser: "fuma-content/collections/mdx/runtime-browser",
|
|
19
|
+
dynamic: "fuma-content/collections/mdx/runtime-dynamic",
|
|
20
|
+
server: "fuma-content/collections/mdx/runtime"
|
|
21
|
+
};
|
|
22
|
+
function defineMDX(config) {
|
|
23
|
+
const { lazy = false, dynamic = false } = config;
|
|
24
|
+
return createCollection(mdxTypeInfo, (collection, options) => {
|
|
25
|
+
collection.handlers.fs = buildFileHandler(options, config, ["mdx", "md"]);
|
|
26
|
+
collection.handlers.mdx = {
|
|
27
|
+
cwd: options.workspace ? path.resolve(options.workspace.dir) : process.cwd(),
|
|
28
|
+
postprocess: config.postprocess,
|
|
29
|
+
getMDXOptions: config.options,
|
|
30
|
+
dynamic,
|
|
31
|
+
lazy,
|
|
32
|
+
onGenerateStore(initializer) {
|
|
33
|
+
const mdxHandler = collection.handlers.mdx;
|
|
34
|
+
if (mdxHandler?.postprocess?.extractLinkReferences) {
|
|
35
|
+
this.codegen.addNamedImport(
|
|
36
|
+
["$extractedReferences"],
|
|
37
|
+
RuntimePaths[this.environment]
|
|
38
|
+
);
|
|
39
|
+
initializer += ".$data($extractedReferences())";
|
|
40
|
+
}
|
|
41
|
+
return initializer;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
collection.handlers["version-control"] = {
|
|
45
|
+
client({ client }) {
|
|
46
|
+
const mdxHandler = collection.handlers.mdx;
|
|
47
|
+
if (!mdxHandler) return;
|
|
48
|
+
const { onGenerateStore, vfile } = mdxHandler;
|
|
49
|
+
mdxHandler.onGenerateStore = function(initializer) {
|
|
50
|
+
this.codegen.addNamedImport(
|
|
51
|
+
["$versionControl"],
|
|
52
|
+
RuntimePaths[this.environment]
|
|
53
|
+
);
|
|
54
|
+
initializer += ".$data($versionControl())";
|
|
55
|
+
return onGenerateStore?.call(this, initializer) ?? initializer;
|
|
56
|
+
};
|
|
57
|
+
mdxHandler.vfile = async function(file) {
|
|
58
|
+
const vcData = await client.getFileData({ filePath: file.path });
|
|
59
|
+
file.data["mdx-export"] ??= [];
|
|
60
|
+
file.data["mdx-export"].push(
|
|
61
|
+
{
|
|
62
|
+
name: "lastModified",
|
|
63
|
+
value: vcData.lastModified
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "creationDate",
|
|
67
|
+
value: vcData.creationDate
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
if (vfile) return vfile?.call(this, file);
|
|
71
|
+
return file;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function plugin() {
|
|
78
|
+
const mdxLoaderGlob = /\.mdx?(\?.+?)?$/;
|
|
79
|
+
function generateDocCollectionFrontmatterGlob(context, collection, eager = false) {
|
|
80
|
+
const handler = collection.handlers.fs;
|
|
81
|
+
if (!handler) return "";
|
|
82
|
+
return context.codegen.generateGlobImport(handler.patterns, {
|
|
83
|
+
query: {
|
|
84
|
+
collection: collection.name,
|
|
85
|
+
only: "frontmatter",
|
|
86
|
+
workspace: context.workspace
|
|
87
|
+
},
|
|
88
|
+
import: "frontmatter",
|
|
89
|
+
base: handler.dir,
|
|
90
|
+
eager
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function generateDocCollectionGlob(context, collection, eager = false) {
|
|
94
|
+
const handler = collection.handlers.fs;
|
|
95
|
+
if (!handler) return "";
|
|
96
|
+
return context.codegen.generateGlobImport(handler.patterns, {
|
|
97
|
+
query: {
|
|
98
|
+
collection: collection.name,
|
|
99
|
+
workspace: context.workspace
|
|
100
|
+
},
|
|
101
|
+
base: handler.dir,
|
|
102
|
+
eager
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
async function generateCollectionStoreServer(context, collection) {
|
|
106
|
+
const mdxHandler = collection.handlers.mdx;
|
|
107
|
+
const fsHandler = collection.handlers.fs;
|
|
108
|
+
if (!fsHandler || !mdxHandler) return;
|
|
109
|
+
const { core, codegen } = context;
|
|
110
|
+
const runtimePath = RuntimePaths.server;
|
|
111
|
+
const base2 = path.relative(process.cwd(), fsHandler.dir);
|
|
112
|
+
let initializer;
|
|
113
|
+
codegen.addNamedImport(
|
|
114
|
+
["default as Config"],
|
|
115
|
+
codegen.formatImportPath(core.getOptions().configPath),
|
|
116
|
+
true
|
|
117
|
+
);
|
|
118
|
+
if (mdxHandler.lazy) {
|
|
119
|
+
codegen.addNamedImport(["mdxStoreLazy"], runtimePath);
|
|
120
|
+
const [headGlob, bodyGlob] = await Promise.all([
|
|
121
|
+
generateDocCollectionFrontmatterGlob(context, collection, true),
|
|
122
|
+
generateDocCollectionGlob(context, collection)
|
|
123
|
+
]);
|
|
124
|
+
initializer = `mdxStoreLazy<typeof Config, "${collection.name}">("${collection.name}", "${base2}", { head: ${headGlob}, body: ${bodyGlob} })`;
|
|
125
|
+
} else {
|
|
126
|
+
codegen.addNamedImport(["mdxStore"], runtimePath);
|
|
127
|
+
initializer = `mdxStore<typeof Config, "${collection.name}">("${collection.name}", "${base2}", ${await generateDocCollectionGlob(context, collection, true)})`;
|
|
128
|
+
}
|
|
129
|
+
initializer = mdxHandler.onGenerateStore?.call(
|
|
130
|
+
{ ...context, environment: "server" },
|
|
131
|
+
initializer
|
|
132
|
+
) ?? initializer;
|
|
133
|
+
codegen.push(`export const ${collection.name} = ${initializer};`);
|
|
134
|
+
}
|
|
135
|
+
async function generateCollectionStoreBrowser(context, collection) {
|
|
136
|
+
const mdxHandler = collection.handlers.mdx;
|
|
137
|
+
const fsHandler = collection.handlers.fs;
|
|
138
|
+
if (!fsHandler || !mdxHandler) return;
|
|
139
|
+
const { core, codegen } = context;
|
|
140
|
+
const runtimePath = RuntimePaths.browser;
|
|
141
|
+
codegen.addNamedImport(["mdxStoreBrowser"], runtimePath);
|
|
142
|
+
codegen.addNamedImport(
|
|
143
|
+
["default as Config"],
|
|
144
|
+
codegen.formatImportPath(core.getOptions().configPath),
|
|
145
|
+
true
|
|
146
|
+
);
|
|
147
|
+
let initializer = `mdxStoreBrowser<typeof Config, "${collection.name}">("${collection.name}", ${await generateDocCollectionGlob(context, collection)})`;
|
|
148
|
+
initializer = mdxHandler.onGenerateStore?.call(
|
|
149
|
+
{ ...context, environment: "browser" },
|
|
150
|
+
initializer
|
|
151
|
+
) ?? initializer;
|
|
152
|
+
codegen.push(`export const ${collection.name} = ${initializer};`);
|
|
153
|
+
}
|
|
154
|
+
async function generateCollectionStoreDynamic(context, collection) {
|
|
155
|
+
const mdxHandler = collection.handlers.mdx;
|
|
156
|
+
const fsHandler = collection.handlers.fs;
|
|
157
|
+
if (!fsHandler || !mdxHandler || !mdxHandler.dynamic) return;
|
|
158
|
+
const { core, codegen } = context;
|
|
159
|
+
const { configPath, workspace, outDir } = core.getOptions();
|
|
160
|
+
const runtimePath = RuntimePaths.dynamic;
|
|
161
|
+
const base2 = path.relative(process.cwd(), fsHandler.dir);
|
|
162
|
+
codegen.addNamedImport(
|
|
163
|
+
["default as Config"],
|
|
164
|
+
codegen.formatImportPath(configPath)
|
|
165
|
+
);
|
|
166
|
+
codegen.addNamedImport(["mdxStoreDynamic"], runtimePath);
|
|
167
|
+
const coreOptions = {
|
|
168
|
+
configPath,
|
|
169
|
+
workspace,
|
|
170
|
+
outDir
|
|
171
|
+
};
|
|
172
|
+
let initializer = `mdxStoreDynamic<typeof Config, "${collection.name}">(Config, ${JSON.stringify(
|
|
173
|
+
coreOptions
|
|
174
|
+
)}, "${collection.name}", "${base2}", ${await generateDocCollectionFrontmatterGlob(context, collection, true)})`;
|
|
175
|
+
initializer = mdxHandler.onGenerateStore?.call(
|
|
176
|
+
{ ...context, environment: "dynamic" },
|
|
177
|
+
initializer
|
|
178
|
+
) ?? initializer;
|
|
179
|
+
codegen.push(`export const ${collection.name} = ${initializer};`);
|
|
180
|
+
}
|
|
181
|
+
const base = {
|
|
182
|
+
name: "mdx",
|
|
183
|
+
configureServer(server) {
|
|
184
|
+
if (!server.watcher) return;
|
|
185
|
+
server.watcher.on("all", async (event, file) => {
|
|
186
|
+
const updatedCollection = this.core.getCollections().find((collection) => {
|
|
187
|
+
const handlers = collection.handlers;
|
|
188
|
+
if (!handlers.mdx || !handlers.fs) return false;
|
|
189
|
+
if (event === "change" && !handlers.mdx.dynamic) return false;
|
|
190
|
+
return handlers.fs.hasFile(file);
|
|
191
|
+
});
|
|
192
|
+
if (!updatedCollection) return;
|
|
193
|
+
await this.core.emit({
|
|
194
|
+
filterPlugin: (plugin2) => plugin2.name === base.name,
|
|
195
|
+
filterWorkspace: () => false,
|
|
196
|
+
write: true
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
},
|
|
200
|
+
emit() {
|
|
201
|
+
return Promise.all([
|
|
202
|
+
this.createCodeGenerator("mdx.ts", async (ctx) => {
|
|
203
|
+
for (const collection of this.core.getCollections()) {
|
|
204
|
+
await generateCollectionStoreServer(ctx, collection);
|
|
205
|
+
}
|
|
206
|
+
}),
|
|
207
|
+
this.createCodeGenerator("mdx-browser.ts", async (ctx) => {
|
|
208
|
+
for (const collection of this.core.getCollections()) {
|
|
209
|
+
await generateCollectionStoreBrowser(ctx, collection);
|
|
210
|
+
}
|
|
211
|
+
ctx.codegen.push(
|
|
212
|
+
`export { useRenderer } from "${RuntimePaths.browser}";`
|
|
213
|
+
);
|
|
214
|
+
}),
|
|
215
|
+
this.createCodeGenerator("mdx-dynamic.ts", async (ctx) => {
|
|
216
|
+
for (const collection of this.core.getCollections()) {
|
|
217
|
+
await generateCollectionStoreDynamic(ctx, collection);
|
|
218
|
+
}
|
|
219
|
+
})
|
|
220
|
+
]);
|
|
221
|
+
},
|
|
222
|
+
next: {
|
|
223
|
+
config(nextConfig) {
|
|
224
|
+
const { configPath, outDir } = this.core.getOptions();
|
|
225
|
+
const loaderPath = "fuma-content/collections/mdx/loader-webpack";
|
|
226
|
+
const loaderOptions = {
|
|
227
|
+
configPath,
|
|
228
|
+
outDir,
|
|
229
|
+
absoluteCompiledConfigPath: path.resolve(
|
|
230
|
+
this.core.getCompiledConfigPath()
|
|
231
|
+
),
|
|
232
|
+
isDev: process.env.NODE_ENV === "development"
|
|
233
|
+
};
|
|
234
|
+
return {
|
|
235
|
+
...nextConfig,
|
|
236
|
+
turbopack: {
|
|
237
|
+
...nextConfig.turbopack,
|
|
238
|
+
rules: {
|
|
239
|
+
...nextConfig.turbopack?.rules,
|
|
240
|
+
"*.{md,mdx}": {
|
|
241
|
+
loaders: [
|
|
242
|
+
{
|
|
243
|
+
loader: loaderPath,
|
|
244
|
+
options: loaderOptions
|
|
245
|
+
}
|
|
246
|
+
],
|
|
247
|
+
as: "*.js"
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
pageExtensions: [
|
|
252
|
+
...nextConfig.pageExtensions ?? ["js", "jsx", "tsx", "ts"],
|
|
253
|
+
"mdx",
|
|
254
|
+
"md"
|
|
255
|
+
],
|
|
256
|
+
webpack(config, options) {
|
|
257
|
+
config.module ||= {};
|
|
258
|
+
config.module.rules ||= [];
|
|
259
|
+
config.module.rules.push({
|
|
260
|
+
test: mdxLoaderGlob,
|
|
261
|
+
use: [
|
|
262
|
+
options.defaultLoaders.babel,
|
|
263
|
+
{
|
|
264
|
+
loader: loaderPath,
|
|
265
|
+
options: loaderOptions
|
|
266
|
+
}
|
|
267
|
+
]
|
|
268
|
+
});
|
|
269
|
+
return nextConfig.webpack?.(config, options) ?? config;
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
return withLoader(base, {
|
|
276
|
+
test: mdxLoaderGlob,
|
|
277
|
+
async createLoader() {
|
|
278
|
+
const { createMdxLoader } = await import("../loader-VGDLYG4T.js");
|
|
279
|
+
return createMdxLoader({
|
|
280
|
+
getCore: () => this.core
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
export {
|
|
286
|
+
defineMDX
|
|
287
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LoaderContext } from 'webpack';
|
|
2
|
+
import { WebpackLoaderOptions } from '../../plugins/with-loader/webpack.js';
|
|
3
|
+
import '../../plugins/with-loader/index.js';
|
|
4
|
+
import '../../core-DxnSmTRe.js';
|
|
5
|
+
import 'chokidar';
|
|
6
|
+
import '@mdx-js/mdx';
|
|
7
|
+
import 'vfile';
|
|
8
|
+
import '@standard-schema/spec';
|
|
9
|
+
import 'unified';
|
|
10
|
+
import 'mdast';
|
|
11
|
+
import 'vite';
|
|
12
|
+
import 'next';
|
|
13
|
+
import 'node:module';
|
|
14
|
+
|
|
15
|
+
declare function loader(this: LoaderContext<WebpackLoaderOptions>, source: string): Promise<void>;
|
|
16
|
+
|
|
17
|
+
export { loader as default };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createMetaLoader
|
|
3
|
+
} from "../../chunk-RMSV4HP6.js";
|
|
4
|
+
import {
|
|
5
|
+
getCore,
|
|
6
|
+
toWebpack
|
|
7
|
+
} from "../../chunk-4RMSJCK2.js";
|
|
8
|
+
import "../../chunk-OUJENWQ4.js";
|
|
9
|
+
import {
|
|
10
|
+
createDynamicCore
|
|
11
|
+
} from "../../chunk-LDBQ66H3.js";
|
|
12
|
+
import "../../chunk-Z7KHD7MS.js";
|
|
13
|
+
import "../../chunk-6XDQG2GV.js";
|
|
14
|
+
|
|
15
|
+
// src/collections/meta/loader-webpack.ts
|
|
16
|
+
var instance;
|
|
17
|
+
async function loader(source) {
|
|
18
|
+
const callback = this.async();
|
|
19
|
+
const options = this.getOptions();
|
|
20
|
+
this.cacheable(true);
|
|
21
|
+
this.addDependency(options.absoluteCompiledConfigPath);
|
|
22
|
+
if (!instance) {
|
|
23
|
+
instance = toWebpack(
|
|
24
|
+
createMetaLoader(
|
|
25
|
+
createDynamicCore({
|
|
26
|
+
core: getCore(options),
|
|
27
|
+
buildConfig: false,
|
|
28
|
+
mode: options.isDev ? "dev" : "production"
|
|
29
|
+
}),
|
|
30
|
+
{
|
|
31
|
+
json: "json",
|
|
32
|
+
yaml: "js"
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
await instance.call(this, source, callback);
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
loader as default
|
|
41
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { GetCollectionConfig } from '../../index.js';
|
|
2
|
+
import { FileCollectionStore } from '../runtime/file-store.js';
|
|
3
|
+
import { c as MetaCollection } from '../../core-DxnSmTRe.js';
|
|
4
|
+
import '../runtime/store.js';
|
|
5
|
+
import 'chokidar';
|
|
6
|
+
import '@mdx-js/mdx';
|
|
7
|
+
import 'vfile';
|
|
8
|
+
import '@standard-schema/spec';
|
|
9
|
+
import 'unified';
|
|
10
|
+
import 'mdast';
|
|
11
|
+
import 'vite';
|
|
12
|
+
import 'next';
|
|
13
|
+
import 'node:module';
|
|
14
|
+
|
|
15
|
+
declare function metaStore<Config, Name extends string>(_name: Name, base: string, input: Record<string, unknown>): FileCollectionStore<{
|
|
16
|
+
data: GetCollectionConfig<Config, Name> extends MetaCollection<infer Data> ? Data : never;
|
|
17
|
+
}>;
|
|
18
|
+
|
|
19
|
+
export { metaStore };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FileCollectionStore
|
|
3
|
+
} from "../../chunk-RXR7OL76.js";
|
|
4
|
+
import "../../chunk-3VQS3KSP.js";
|
|
5
|
+
|
|
6
|
+
// src/collections/meta/runtime.ts
|
|
7
|
+
function metaStore(_name, base, input) {
|
|
8
|
+
const merged = input;
|
|
9
|
+
for (const [key, value] of Object.entries(input)) {
|
|
10
|
+
merged[key] = {
|
|
11
|
+
data: value
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return new FileCollectionStore(base, merged);
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
metaStore
|
|
18
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { c as MetaCollection, s as MetaCollectionConfig, r as MetaCollectionHandler, q as MetaContext, t as defineMeta } from '../core-DxnSmTRe.js';
|
|
2
|
+
import '@standard-schema/spec';
|
|
3
|
+
import 'chokidar';
|
|
4
|
+
import '@mdx-js/mdx';
|
|
5
|
+
import 'vfile';
|
|
6
|
+
import 'unified';
|
|
7
|
+
import 'mdast';
|
|
8
|
+
import 'vite';
|
|
9
|
+
import 'next';
|
|
10
|
+
import 'node:module';
|