diff options
Diffstat (limited to 'packages/integrations/mdx/src/index.ts')
-rw-r--r-- | packages/integrations/mdx/src/index.ts | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/packages/integrations/mdx/src/index.ts b/packages/integrations/mdx/src/index.ts index f92a10a53..17fe0cd74 100644 --- a/packages/integrations/mdx/src/index.ts +++ b/packages/integrations/mdx/src/index.ts @@ -26,6 +26,12 @@ const DEFAULT_REMARK_PLUGINS: MdxRollupPluginOptions['remarkPlugins'] = [ ]; const DEFAULT_REHYPE_PLUGINS: MdxRollupPluginOptions['rehypePlugins'] = []; +const RAW_CONTENT_ERROR = + 'MDX does not support rawContent()! If you need to read the Markdown contents to calculate values (ex. reading time), we suggest injecting frontmatter via remark plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins'; + +const COMPILED_CONTENT_ERROR = + 'MDX does not support compiledContent()! If you need to read the HTML contents to calculate values (ex. reading time), we suggest injecting frontmatter via rehype plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins'; + function handleExtends<T>(config: WithExtends<T[] | undefined>, defaults: T[] = []): T[] { if (Array.isArray(config)) return config; @@ -127,6 +133,19 @@ export default function mdx(mdxOptions: MdxOptions = {}): AstroIntegration { if (!moduleExports.includes('file')) { code += `\nexport const file = ${JSON.stringify(fileId)};`; } + if (!moduleExports.includes('rawContent')) { + code += `\nexport function rawContent() { throw new Error(${JSON.stringify( + RAW_CONTENT_ERROR + )}) };`; + } + if (!moduleExports.includes('compiledContent')) { + code += `\nexport function compiledContent() { throw new Error(${JSON.stringify( + COMPILED_CONTENT_ERROR + )}) };`; + } + if (!moduleExports.includes('Content')) { + code += `\nexport const Content = MDXContent;`; + } if (command === 'dev') { // TODO: decline HMR updates until we have a stable approach |