@@ -6,6 +6,7 @@ import mdxPlugin, { Options as MdxRollupPluginOptions } from '@mdx-js/rollup';
6
6
import type { AstroIntegration } from 'astro' ;
7
7
import { parse as parseESM } from 'es-module-lexer' ;
8
8
import fs from 'node:fs/promises' ;
9
+ import { fileURLToPath } from 'node:url' ;
9
10
import type { Options as RemarkRehypeOptions } from 'remark-rehype' ;
10
11
import { VFile } from 'vfile' ;
11
12
import type { Plugin as VitePlugin } from 'vite' ;
@@ -22,12 +23,33 @@ export type MdxOptions = Omit<typeof markdownConfigDefaults, 'remarkPlugins' | '
22
23
remarkRehype : RemarkRehypeOptions ;
23
24
} ;
24
25
26
+ const contentEntryType = {
27
+ extensions : [ '.mdx' ] ,
28
+ async getEntryInfo ( { fileUrl } : { fileUrl : URL } ) {
29
+ const rawContents = await fs . readFile ( fileUrl , 'utf-8' ) ;
30
+ const parsed = parseFrontmatter ( rawContents , fileURLToPath ( fileUrl ) ) ;
31
+ return {
32
+ data : parsed . data ,
33
+ body : parsed . content ,
34
+ slug : parsed . data . slug ,
35
+ rawData : parsed . matter ,
36
+ } ;
37
+ } ,
38
+ } ;
39
+
25
40
export default function mdx ( partialMdxOptions : Partial < MdxOptions > = { } ) : AstroIntegration {
26
41
return {
27
42
name : '@astrojs/mdx' ,
28
43
hooks : {
29
- 'astro:config:setup' : async ( { updateConfig, config, addPageExtension, command } : any ) => {
44
+ 'astro:config:setup' : async ( {
45
+ updateConfig,
46
+ config,
47
+ addPageExtension,
48
+ addContentEntryType,
49
+ command,
50
+ } : any ) => {
30
51
addPageExtension ( '.mdx' ) ;
52
+ addContentEntryType ( contentEntryType ) ;
31
53
32
54
const extendMarkdownConfig =
33
55
partialMdxOptions . extendMarkdownConfig ?? defaultOptions . extendMarkdownConfig ;
0 commit comments