mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-27 09:19:53 +00:00
- Synced with upstream fumadocs changes - Accepted upstream changes for all conflicts - Deleted files that no longer exist upstream - Maintains @hanzo package namespace
37 lines
913 B
TypeScript
37 lines
913 B
TypeScript
import type { TableOfContents } from '@hanzo/docs-core/toc';
|
|
import type { MdxContent } from '@/render';
|
|
|
|
export * from './compile';
|
|
export { parseFrontmatter } from './utils';
|
|
|
|
/**
|
|
* @deprecated Use `compiler.render` instead
|
|
*/
|
|
export async function executeMdx(compiled: string, scope: object, baseUrl?: string | URL) {
|
|
let jsxRuntime;
|
|
|
|
if (process.env.NODE_ENV === 'production') {
|
|
jsxRuntime = await import('react/jsx-runtime');
|
|
} else {
|
|
jsxRuntime = await import('react/jsx-dev-runtime');
|
|
}
|
|
|
|
const fullScope = {
|
|
opts: {
|
|
...jsxRuntime,
|
|
baseUrl,
|
|
},
|
|
...scope,
|
|
};
|
|
|
|
const values = Object.values(fullScope);
|
|
const params = Object.keys(fullScope);
|
|
params.push(`return (async () => { ${compiled} })()`);
|
|
const hydrateFn = new Function(...params);
|
|
|
|
return (await hydrateFn.apply(hydrateFn, values)) as {
|
|
default: MdxContent;
|
|
toc?: TableOfContents;
|
|
};
|
|
}
|