next-mdx-remote-client
Version:
A wrapper of the `@mdx-js/mdx` for the `nextjs` applications in order to load MDX content. It is a fork of `next-mdx-remote`.
44 lines • 1.48 kB
JavaScript
/**
* Copyright (c) @talatkuyuk AKA @ipikuka
* SPDX-License-Identifier: MPL-2.0
*/
import { serializeError } from "serialize-error";
import { passVfileDataIntoScope } from "../lib/util.js";
import { prepare } from "../lib/prepare.js";
import { compile } from "../lib/compile.js";
/**
* compiles the MDX source.
*
* the compiled source can be passed into "<MDXClient />" or "hydrate" to be rendered on the client side (csr).
*
*/
export async function serialize({ source, options = {}, }) {
const { mdxOptions = {}, disableExports, disableImports, parseFrontmatter, scope = {}, vfileDataIntoScope, } = options;
const { vfile, frontmatter } = prepare(source, parseFrontmatter);
const compileMDXOptions = {
...mdxOptions,
providerImportSource: "#", // important! doesn't matter "@mdx-js/react" since the outputFormat is "function-body"
};
try {
const { compiledSource } = await compile(vfile, {
mdxOptions: compileMDXOptions,
disableExports,
disableImports,
});
if (vfileDataIntoScope)
passVfileDataIntoScope(compiledSource.data, vfileDataIntoScope, scope);
return {
compiledSource: String(compiledSource),
frontmatter,
scope,
};
}
catch (error) {
return {
error: serializeError(error),
frontmatter,
scope,
};
}
}
//# sourceMappingURL=serialize.js.map