summaryrefslogtreecommitdiff
path: root/packages/integrations/mdx/src/index.ts
diff options
context:
space:
mode:
authorGravatar Ben Holmes <hey@bholmes.dev> 2023-01-03 16:31:19 -0500
committerGravatar GitHub <noreply@github.com> 2023-01-03 16:31:19 -0500
commite2019be6ffa46fa33d92cfd346f9ecbe51bb7144 (patch)
tree413c13945ae992c26111e78314a567f5c0136c67 /packages/integrations/mdx/src/index.ts
parent16c7d0bfd49d2b9bfae45385f506bcd642f9444a (diff)
downloadastro-e2019be6ffa46fa33d92cfd346f9ecbe51bb7144.tar.gz
astro-e2019be6ffa46fa33d92cfd346f9ecbe51bb7144.tar.zst
astro-e2019be6ffa46fa33d92cfd346f9ecbe51bb7144.zip
Change frontmatter injection ordering (#5687)
* feat: make user frontmatter accessible in md * test: new frontmatter injection * refactor: move injection utils to remark pkg * fix: add dist/internal to remark exports * feat: update frontmater injection in mdx * tests: new mdx injection * chore: changeset * chore: simplify frontmatter destructuring * fix: remove old _internal references * refactor: injectedFrontmatter -> remarkPluginFrontmatter * docs: add content collections change * chore: changeset heading levels
Diffstat (limited to 'packages/integrations/mdx/src/index.ts')
-rw-r--r--packages/integrations/mdx/src/index.ts15
1 files changed, 6 insertions, 9 deletions
diff --git a/packages/integrations/mdx/src/index.ts b/packages/integrations/mdx/src/index.ts
index d788a171a..e9d81ca1f 100644
--- a/packages/integrations/mdx/src/index.ts
+++ b/packages/integrations/mdx/src/index.ts
@@ -1,3 +1,4 @@
+import { toRemarkInitializeAstroData } from '@astrojs/markdown-remark/dist/internal.js';
import { compile as mdxCompile } from '@mdx-js/mdx';
import { PluggableList } from '@mdx-js/mdx/lib/core.js';
import mdxPlugin, { Options as MdxRollupPluginOptions } from '@mdx-js/rollup';
@@ -7,12 +8,7 @@ import fs from 'node:fs/promises';
import type { Options as RemarkRehypeOptions } from 'remark-rehype';
import { VFile } from 'vfile';
import type { Plugin as VitePlugin } from 'vite';
-import {
- getRehypePlugins,
- getRemarkPlugins,
- recmaInjectImportMetaEnvPlugin,
- rehypeApplyFrontmatterExport,
-} from './plugins.js';
+import { getRehypePlugins, getRemarkPlugins, recmaInjectImportMetaEnvPlugin } from './plugins.js';
import { getFileInfo, parseFrontmatter } from './utils.js';
const RAW_CONTENT_ERROR =
@@ -86,9 +82,10 @@ export default function mdx(mdxOptions: MdxOptions = {}): AstroIntegration {
const { data: frontmatter, content: pageContent } = parseFrontmatter(code, id);
const compiled = await mdxCompile(new VFile({ value: pageContent, path: id }), {
...mdxPluginOpts,
- rehypePlugins: [
- ...(mdxPluginOpts.rehypePlugins ?? []),
- () => rehypeApplyFrontmatterExport(frontmatter),
+ remarkPlugins: [
+ // Ensure `data.astro` is available to all remark plugins
+ toRemarkInitializeAstroData({ userFrontmatter: frontmatter }),
+ ...(mdxPluginOpts.remarkPlugins ?? []),
],
recmaPlugins: [
...(mdxPluginOpts.recmaPlugins ?? []),