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`.
31 lines • 1.04 kB
JavaScript
/**
* Copyright (c) @talatkuyuk AKA @ipikuka
* SPDX-License-Identifier: MPL-2.0
*/
import { VFile } from "vfile";
import { matter } from "vfile-matter";
/**
* turns the source into vfile, gets the fronmatter, strips it out from the vfile
*
* @param source markdown or MDX source
* @param parseFrontmatter indicates whether or not the frontmatter should be parsed out of the source
* @returns the frontmatter and stripped vfile
*/
export function prepare(source, parseFrontmatter) {
const vfile = looksLikeAVFile(source) ? source : new VFile(source);
// makes frontmatter available via vfile.data.matter
if (parseFrontmatter)
matter(vfile, { strip: true });
const frontmatter = (vfile.data.matter ?? {});
return {
vfile,
frontmatter,
};
}
/**
* taken from @mdx-js/mdx/lib/util/resolve-file-and-options.js
*/
function looksLikeAVFile(value) {
return Boolean(value && typeof value === "object" && "message" in value && "messages" in value);
}
//# sourceMappingURL=prepare.js.map