@astrojs/mdx 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +10 -0
- package/README.md +55 -59
- package/dist/astro-data-utils.d.ts +1 -1
- package/dist/astro-data-utils.js +5 -24
- package/dist/index.d.ts +0 -7
- package/dist/index.js +1 -7
- package/package.json +2 -3
- package/src/astro-data-utils.ts +6 -28
- package/src/index.ts +1 -12
- package/test/mdx-frontmatter.test.js +0 -17
- package/test/fixtures/mdx-custom-frontmatter-name/src/pages/glob.json.js +0 -9
- package/test/fixtures/mdx-custom-frontmatter-name/src/pages/index.mdx +0 -6
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
[32m@astrojs/mdx:build: [0mcache hit, replaying output [
|
|
1
|
+
[32m@astrojs/mdx:build: [0mcache hit, replaying output [2mfb941ae7dc16611b[0m
|
|
2
2
|
[32m@astrojs/mdx:build: [0m
|
|
3
|
-
[32m@astrojs/mdx:build: [0m> @astrojs/mdx@0.
|
|
3
|
+
[32m@astrojs/mdx:build: [0m> @astrojs/mdx@0.8.0 build /home/runner/work/astro/astro/packages/integrations/mdx
|
|
4
4
|
[32m@astrojs/mdx:build: [0m> astro-scripts build "src/**/*.ts" && tsc
|
|
5
5
|
[32m@astrojs/mdx:build: [0m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @astrojs/mdx
|
|
2
2
|
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#4204](https://github.com/withastro/astro/pull/4204) [`4c2ca5352`](https://github.com/withastro/astro/commit/4c2ca5352d0c4119ed2a9e5e0b78ce71eb1b414a) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Remove `frontmatterOptions` from MDX config
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#4205](https://github.com/withastro/astro/pull/4205) [`6c9736cbc`](https://github.com/withastro/astro/commit/6c9736cbc90162f1de3ebccd7cfe98332749b639) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Add frontmatter injection instructions to README
|
|
12
|
+
|
|
3
13
|
## 0.7.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -20,33 +20,30 @@ Check out [“What is MDX?”](https://mdxjs.com/docs/what-is-mdx/), a deep-dive
|
|
|
20
20
|
|
|
21
21
|
## Installation
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
<summary>Quick Install</summary>
|
|
23
|
+
### Quick Install
|
|
25
24
|
|
|
26
25
|
The `astro add` command-line tool automates the installation for you. Run one of the following commands in a new terminal window. (If you aren't sure which package manager you're using, run the first command.) Then, follow the prompts, and type "y" in the terminal (meaning "yes") for each one.
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
```sh
|
|
28
|
+
# Using NPM
|
|
29
|
+
npx astro add mdx
|
|
30
|
+
# Using Yarn
|
|
31
|
+
yarn astro add mdx
|
|
32
|
+
# Using PNPM
|
|
33
|
+
pnpx astro add mdx
|
|
34
|
+
```
|
|
36
35
|
|
|
37
36
|
Then, restart the dev server by typing `CTRL-C` and then `npm run astro dev` in the terminal window that was running Astro.
|
|
38
37
|
|
|
39
38
|
Because this command is new, it might not properly set things up. If that happens, [feel free to log an issue on our GitHub](https://github.com/withastro/astro/issues) and try the manual installation steps below.
|
|
40
|
-
</details>
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
<summary>Manual Install</summary>
|
|
40
|
+
### Manual Install
|
|
44
41
|
|
|
45
42
|
First, install the `@astrojs/mdx` package using your package manager. If you're using npm or aren't sure, run this in the terminal:
|
|
46
43
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
```sh
|
|
45
|
+
npm install @astrojs/mdx
|
|
46
|
+
```
|
|
50
47
|
|
|
51
48
|
Then, apply this integration to your `astro.config.*` file using the `integrations` property:
|
|
52
49
|
|
|
@@ -63,11 +60,14 @@ export default defineConfig({
|
|
|
63
60
|
```
|
|
64
61
|
|
|
65
62
|
Finally, restart the dev server.
|
|
66
|
-
</details>
|
|
67
63
|
|
|
68
64
|
## Usage
|
|
69
65
|
|
|
70
|
-
|
|
66
|
+
You can [add MDX pages to your project](https://docs.astro.build/en/guides/markdown-content/#markdown-and-mdx-pages) by adding `.mdx` files within your `src/pages/` directory.
|
|
67
|
+
|
|
68
|
+
### Components
|
|
69
|
+
|
|
70
|
+
To use components in your MDX pages in Astro, head to our [UI framework documentation][astro-ui-frameworks]. You'll explore:
|
|
71
71
|
- 📦 how framework components are loaded,
|
|
72
72
|
- 💧 client-side hydration options, and
|
|
73
73
|
- 🪆 opportunities to mix and nest frameworks together
|
|
@@ -76,8 +76,6 @@ To write your first MDX page in Astro, head to our [UI framework documentation][
|
|
|
76
76
|
|
|
77
77
|
> **Note**: `.mdx` files adhere to strict JSX syntax rather than Astro's HTML-like syntax.
|
|
78
78
|
|
|
79
|
-
Also check our [Astro Integration Documentation][astro-integration] for more on integrations.
|
|
80
|
-
|
|
81
79
|
### Variables
|
|
82
80
|
|
|
83
81
|
MDX supports `export` statements to add variables to your templates. These variables are accessible both from the template itself _and_ as named properties when importing the template somewhere else.
|
|
@@ -123,7 +121,7 @@ A function that returns an array of all headings (i.e. `h1 -> h6` elements) in t
|
|
|
123
121
|
|
|
124
122
|
### Frontmatter
|
|
125
123
|
|
|
126
|
-
Astro also supports YAML-based frontmatter out-of-the-box
|
|
124
|
+
Astro also supports YAML-based frontmatter out-of-the-box. By default, all variables declared in a frontmatter fence (`---`) will be accessible via the `frontmatter` export.
|
|
127
125
|
|
|
128
126
|
For example, we can add a `title` and `publishDate` to an MDX page or component like so:
|
|
129
127
|
|
|
@@ -152,6 +150,40 @@ const posts = await Astro.glob('./*.mdx');
|
|
|
152
150
|
))}
|
|
153
151
|
```
|
|
154
152
|
|
|
153
|
+
### Inject frontmatter via remark or rehype plugins
|
|
154
|
+
|
|
155
|
+
You may want to inject frontmatter properties across all of your MDX files. By using a [remark](#remarkPlugins) or [rehype](#remarkplugins) plugin, you can generate these properties based on a file’s contents.
|
|
156
|
+
|
|
157
|
+
You can append to the `data.astro.frontmatter` property from your plugin’s `file` argument like so:
|
|
158
|
+
|
|
159
|
+
```js
|
|
160
|
+
// example-remark-plugin.mjs
|
|
161
|
+
export function exampleRemarkPlugin() {
|
|
162
|
+
// All remark and rehype plugins return a separate function
|
|
163
|
+
return function (tree, file) {
|
|
164
|
+
file.data.astro.frontmatter.customProperty = 'Generated property';
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
After applying this plugin to your MDX integration config:
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
// astro.config.mjs
|
|
173
|
+
import mdx from '@astrojs/mdx';
|
|
174
|
+
import { exampleRemarkPlugin } from './example-remark-plugin.mjs';
|
|
175
|
+
|
|
176
|
+
export default {
|
|
177
|
+
integrations: [
|
|
178
|
+
mdx({
|
|
179
|
+
remarkPlugins: [exampleRemarkPlugin],
|
|
180
|
+
}),
|
|
181
|
+
],
|
|
182
|
+
};
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
…every MDX file will have `customProperty` in its frontmatter! See [our Markdown documentation](https://docs.astro.build/en/guides/markdown-content/#injecting-frontmatter) for more usage instructions and a [reading time plugin example](https://docs.astro.build/en/guides/markdown-content/#example-calculate-reading-time).
|
|
186
|
+
|
|
155
187
|
### Layouts
|
|
156
188
|
|
|
157
189
|
Layouts can be applied [in the same way as standard Astro Markdown](https://docs.astro.build/en/guides/markdown-content/#markdown-layouts). You can add a `layout` to [your frontmatter](#frontmatter) like so:
|
|
@@ -255,8 +287,7 @@ This applies a minimal Prism renderer with added support for `astro` code blocks
|
|
|
255
287
|
|
|
256
288
|
## Configuration
|
|
257
289
|
|
|
258
|
-
|
|
259
|
-
<summary><strong>remarkPlugins</strong></summary>
|
|
290
|
+
### remarkPlugins
|
|
260
291
|
|
|
261
292
|
**Default plugins:** [remark-gfm](https://github.com/remarkjs/remark-gfm), [remark-smartypants](https://github.com/silvenon/remark-smartypants)
|
|
262
293
|
|
|
@@ -292,10 +323,7 @@ export default {
|
|
|
292
323
|
}
|
|
293
324
|
```
|
|
294
325
|
|
|
295
|
-
</
|
|
296
|
-
|
|
297
|
-
<details>
|
|
298
|
-
<summary><strong>rehypePlugins</strong></summary>
|
|
326
|
+
### rehypePlugins</strong>
|
|
299
327
|
|
|
300
328
|
[Rehype plugins](https://github.com/rehypejs/rehype/blob/main/doc/plugins.md) allow you to transform the HTML that your Markdown generates. We recommend checking the [Remark plugin](https://github.com/remarkjs/remark/blob/main/doc/plugins.md) catalog first _before_ considering rehype plugins, since most users want to transform their Markdown syntax instead. If HTML transforms are what you need, we encourage you to browse [awesome-rehype](https://github.com/rehypejs/awesome-rehype) for a full curated list of plugins!
|
|
301
329
|
|
|
@@ -313,38 +341,6 @@ export default {
|
|
|
313
341
|
})],
|
|
314
342
|
}
|
|
315
343
|
```
|
|
316
|
-
</details>
|
|
317
|
-
|
|
318
|
-
<details>
|
|
319
|
-
<summary><strong>frontmatterOptions</strong></summary>
|
|
320
|
-
|
|
321
|
-
**Default:** `{ name: 'frontmatter' }`
|
|
322
|
-
|
|
323
|
-
We use [remark-mdx-frontmatter](https://github.com/remcohaszing/remark-mdx-frontmatter) to parse YAML-based frontmatter in your MDX files. If you want to override our default configuration or extend remark-mdx-frontmatter (ex. to [apply a custom frontmatter parser](https://github.com/remcohaszing/remark-mdx-frontmatter#parsers)), you can supply a `frontmatterOptions` configuration.
|
|
324
|
-
|
|
325
|
-
For example, say you want to access frontmatter as root-level variables without a nested `frontmatter` object. You can override the [`name` configuration option](https://github.com/remcohaszing/remark-mdx-frontmatter#name) like so:
|
|
326
|
-
|
|
327
|
-
```js
|
|
328
|
-
// astro.config.mjs
|
|
329
|
-
export default {
|
|
330
|
-
integrations: [mdx({
|
|
331
|
-
frontmatterOptions: {
|
|
332
|
-
name: '',
|
|
333
|
-
}
|
|
334
|
-
})],
|
|
335
|
-
}
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
```mdx
|
|
339
|
-
---
|
|
340
|
-
title: I'm just a variable now!
|
|
341
|
-
---
|
|
342
|
-
|
|
343
|
-
# {title}
|
|
344
|
-
```
|
|
345
|
-
|
|
346
|
-
See the [remark-mdx-frontmatter README](https://github.com/remcohaszing/remark-mdx-frontmatter#options) for a complete list of options.
|
|
347
|
-
</details>
|
|
348
344
|
|
|
349
345
|
## Examples
|
|
350
346
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { MarkdownAstroData } from 'astro';
|
|
2
2
|
import type { Data, VFile } from 'vfile';
|
|
3
3
|
export declare function remarkInitializeAstroData(): (tree: any, vfile: VFile) => void;
|
|
4
|
-
export declare function rehypeApplyFrontmatterExport(pageFrontmatter: Record<string, any
|
|
4
|
+
export declare function rehypeApplyFrontmatterExport(pageFrontmatter: Record<string, any>): (tree: any, vfile: VFile) => void;
|
|
5
5
|
/**
|
|
6
6
|
* Copied from markdown utils
|
|
7
7
|
* @see "vite-plugin-utils"
|
package/dist/astro-data-utils.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { name as isValidIdentifierName } from "estree-util-is-identifier-name";
|
|
2
1
|
import { jsToTreeNode } from "./utils.js";
|
|
3
2
|
function remarkInitializeAstroData() {
|
|
4
3
|
return function(tree, vfile) {
|
|
@@ -7,32 +6,14 @@ function remarkInitializeAstroData() {
|
|
|
7
6
|
}
|
|
8
7
|
};
|
|
9
8
|
}
|
|
10
|
-
|
|
9
|
+
const EXPORT_NAME = "frontmatter";
|
|
10
|
+
function rehypeApplyFrontmatterExport(pageFrontmatter) {
|
|
11
11
|
return function(tree, vfile) {
|
|
12
|
-
if (!isValidIdentifierName(exportName)) {
|
|
13
|
-
throw new Error(
|
|
14
|
-
`[MDX] ${JSON.stringify(
|
|
15
|
-
exportName
|
|
16
|
-
)} is not a valid frontmatter export name! Make sure "frontmatterOptions.name" could be used as a JS export (i.e. "export const frontmatterName = ...")`
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
12
|
const { frontmatter: injectedFrontmatter } = safelyGetAstroData(vfile.data);
|
|
20
13
|
const frontmatter = { ...injectedFrontmatter, ...pageFrontmatter };
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (!isValidIdentifierName(k)) {
|
|
25
|
-
throw new Error(
|
|
26
|
-
`[MDX] A remark or rehype plugin tried to inject ${JSON.stringify(
|
|
27
|
-
k
|
|
28
|
-
)} as a top-level export, which is not a valid export name.`
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
return jsToTreeNode(`export const ${k} = ${JSON.stringify(v)};`);
|
|
32
|
-
});
|
|
33
|
-
} else {
|
|
34
|
-
exportNodes = [jsToTreeNode(`export const ${exportName} = ${JSON.stringify(frontmatter)};`)];
|
|
35
|
-
}
|
|
14
|
+
const exportNodes = [
|
|
15
|
+
jsToTreeNode(`export const ${EXPORT_NAME} = ${JSON.stringify(frontmatter)};`)
|
|
16
|
+
];
|
|
36
17
|
tree.children = exportNodes.concat(tree.children);
|
|
37
18
|
};
|
|
38
19
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import { Options as MdxRollupPluginOptions } from '@mdx-js/rollup';
|
|
2
2
|
import type { AstroIntegration } from 'astro';
|
|
3
|
-
import type { RemarkMdxFrontmatterOptions } from 'remark-mdx-frontmatter';
|
|
4
3
|
declare type WithExtends<T> = T | {
|
|
5
4
|
extends: T;
|
|
6
5
|
};
|
|
7
6
|
declare type MdxOptions = {
|
|
8
7
|
remarkPlugins?: WithExtends<MdxRollupPluginOptions['remarkPlugins']>;
|
|
9
8
|
rehypePlugins?: WithExtends<MdxRollupPluginOptions['rehypePlugins']>;
|
|
10
|
-
/**
|
|
11
|
-
* Configure the remark-mdx-frontmatter plugin
|
|
12
|
-
* @see https://github.com/remcohaszing/remark-mdx-frontmatter#options for a full list of options
|
|
13
|
-
* @default {{ name: 'frontmatter' }}
|
|
14
|
-
*/
|
|
15
|
-
frontmatterOptions?: RemarkMdxFrontmatterOptions;
|
|
16
9
|
};
|
|
17
10
|
export default function mdx(mdxOptions?: MdxOptions): AstroIntegration;
|
|
18
11
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -83,13 +83,7 @@ return <Layout frontmatter={frontmatter} content={frontmatter} headings={getHead
|
|
|
83
83
|
...mdxPluginOpts,
|
|
84
84
|
rehypePlugins: [
|
|
85
85
|
...mdxPluginOpts.rehypePlugins ?? [],
|
|
86
|
-
() =>
|
|
87
|
-
var _a;
|
|
88
|
-
return rehypeApplyFrontmatterExport(
|
|
89
|
-
frontmatter,
|
|
90
|
-
(_a = mdxOptions.frontmatterOptions) == null ? void 0 : _a.name
|
|
91
|
-
);
|
|
92
|
-
}
|
|
86
|
+
() => rehypeApplyFrontmatterExport(frontmatter)
|
|
93
87
|
]
|
|
94
88
|
});
|
|
95
89
|
return {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/mdx",
|
|
3
3
|
"description": "Use MDX within Astro",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
"rehype-raw": "^6.1.1",
|
|
34
34
|
"remark-frontmatter": "^4.0.1",
|
|
35
35
|
"remark-gfm": "^3.0.1",
|
|
36
|
-
"remark-mdx-frontmatter": "^2.0.2",
|
|
37
36
|
"remark-shiki-twoslash": "^3.1.0",
|
|
38
37
|
"remark-smartypants": "^2.0.0",
|
|
39
38
|
"shiki": "^0.10.1",
|
|
@@ -44,7 +43,7 @@
|
|
|
44
43
|
"@types/chai": "^4.3.1",
|
|
45
44
|
"@types/mocha": "^9.1.1",
|
|
46
45
|
"@types/yargs-parser": "^21.0.0",
|
|
47
|
-
"astro": "1.0.0-rc.
|
|
46
|
+
"astro": "1.0.0-rc.8",
|
|
48
47
|
"astro-scripts": "0.0.6",
|
|
49
48
|
"chai": "^4.3.6",
|
|
50
49
|
"linkedom": "^0.14.12",
|
package/src/astro-data-utils.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { MarkdownAstroData } from 'astro';
|
|
2
|
-
import { name as isValidIdentifierName } from 'estree-util-is-identifier-name';
|
|
3
|
-
import type { MdxjsEsm } from 'mdast-util-mdx';
|
|
4
2
|
import type { Data, VFile } from 'vfile';
|
|
5
3
|
import { jsToTreeNode } from './utils.js';
|
|
6
4
|
|
|
@@ -12,35 +10,15 @@ export function remarkInitializeAstroData() {
|
|
|
12
10
|
};
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
) {
|
|
13
|
+
const EXPORT_NAME = 'frontmatter';
|
|
14
|
+
|
|
15
|
+
export function rehypeApplyFrontmatterExport(pageFrontmatter: Record<string, any>) {
|
|
19
16
|
return function (tree: any, vfile: VFile) {
|
|
20
|
-
if (!isValidIdentifierName(exportName)) {
|
|
21
|
-
throw new Error(
|
|
22
|
-
`[MDX] ${JSON.stringify(
|
|
23
|
-
exportName
|
|
24
|
-
)} is not a valid frontmatter export name! Make sure "frontmatterOptions.name" could be used as a JS export (i.e. "export const frontmatterName = ...")`
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
17
|
const { frontmatter: injectedFrontmatter } = safelyGetAstroData(vfile.data);
|
|
28
18
|
const frontmatter = { ...injectedFrontmatter, ...pageFrontmatter };
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (!isValidIdentifierName(k)) {
|
|
33
|
-
throw new Error(
|
|
34
|
-
`[MDX] A remark or rehype plugin tried to inject ${JSON.stringify(
|
|
35
|
-
k
|
|
36
|
-
)} as a top-level export, which is not a valid export name.`
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
return jsToTreeNode(`export const ${k} = ${JSON.stringify(v)};`);
|
|
40
|
-
});
|
|
41
|
-
} else {
|
|
42
|
-
exportNodes = [jsToTreeNode(`export const ${exportName} = ${JSON.stringify(frontmatter)};`)];
|
|
43
|
-
}
|
|
19
|
+
const exportNodes = [
|
|
20
|
+
jsToTreeNode(`export const ${EXPORT_NAME} = ${JSON.stringify(frontmatter)};`),
|
|
21
|
+
];
|
|
44
22
|
tree.children = exportNodes.concat(tree.children);
|
|
45
23
|
};
|
|
46
24
|
}
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type { AstroConfig, AstroIntegration } from 'astro';
|
|
|
4
4
|
import { parse as parseESM } from 'es-module-lexer';
|
|
5
5
|
import rehypeRaw from 'rehype-raw';
|
|
6
6
|
import remarkGfm from 'remark-gfm';
|
|
7
|
-
import type { RemarkMdxFrontmatterOptions } from 'remark-mdx-frontmatter';
|
|
8
7
|
import remarkShikiTwoslash from 'remark-shiki-twoslash';
|
|
9
8
|
import remarkSmartypants from 'remark-smartypants';
|
|
10
9
|
import { VFile } from 'vfile';
|
|
@@ -19,12 +18,6 @@ type WithExtends<T> = T | { extends: T };
|
|
|
19
18
|
type MdxOptions = {
|
|
20
19
|
remarkPlugins?: WithExtends<MdxRollupPluginOptions['remarkPlugins']>;
|
|
21
20
|
rehypePlugins?: WithExtends<MdxRollupPluginOptions['rehypePlugins']>;
|
|
22
|
-
/**
|
|
23
|
-
* Configure the remark-mdx-frontmatter plugin
|
|
24
|
-
* @see https://github.com/remcohaszing/remark-mdx-frontmatter#options for a full list of options
|
|
25
|
-
* @default {{ name: 'frontmatter' }}
|
|
26
|
-
*/
|
|
27
|
-
frontmatterOptions?: RemarkMdxFrontmatterOptions;
|
|
28
21
|
};
|
|
29
22
|
|
|
30
23
|
const DEFAULT_REMARK_PLUGINS: MdxRollupPluginOptions['remarkPlugins'] = [
|
|
@@ -119,11 +112,7 @@ export default function mdx(mdxOptions: MdxOptions = {}): AstroIntegration {
|
|
|
119
112
|
...mdxPluginOpts,
|
|
120
113
|
rehypePlugins: [
|
|
121
114
|
...(mdxPluginOpts.rehypePlugins ?? []),
|
|
122
|
-
() =>
|
|
123
|
-
rehypeApplyFrontmatterExport(
|
|
124
|
-
frontmatter,
|
|
125
|
-
mdxOptions.frontmatterOptions?.name
|
|
126
|
-
),
|
|
115
|
+
() => rehypeApplyFrontmatterExport(frontmatter),
|
|
127
116
|
],
|
|
128
117
|
});
|
|
129
118
|
|
|
@@ -56,21 +56,4 @@ describe('MDX frontmatter', () => {
|
|
|
56
56
|
expect(headingSlugs).to.contain('section-1');
|
|
57
57
|
expect(headingSlugs).to.contain('section-2');
|
|
58
58
|
});
|
|
59
|
-
|
|
60
|
-
it('extracts frontmatter to "customFrontmatter" export when configured', async () => {
|
|
61
|
-
const customFixture = await loadFixture({
|
|
62
|
-
root: new URL('./fixtures/mdx-custom-frontmatter-name/', import.meta.url),
|
|
63
|
-
integrations: [
|
|
64
|
-
mdx({
|
|
65
|
-
frontmatterOptions: {
|
|
66
|
-
name: 'customFrontmatter',
|
|
67
|
-
},
|
|
68
|
-
}),
|
|
69
|
-
],
|
|
70
|
-
});
|
|
71
|
-
await customFixture.build();
|
|
72
|
-
|
|
73
|
-
const { titles } = JSON.parse(await customFixture.readFile('/glob.json'));
|
|
74
|
-
expect(titles).to.include('Using YAML frontmatter');
|
|
75
|
-
});
|
|
76
59
|
});
|