Skip to content

Commit e35b760

Browse files
feat(content): auto-transform md content to mdx (#104)
1 parent ce3bea5 commit e35b760

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed
File renamed without changes.

cli/convertToMDX.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ function convertCommentsToMDX(content: string): string {
5858
}
5959

6060
async function processFile(file: string): Promise<void> {
61+
if (file.endsWith('.mdx')) {
62+
return
63+
}
64+
6165
const fileContent = await readFile(file, 'utf-8')
6266
const fileDir = path.dirname(file)
6367

src/content.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { glob } from 'astro/loaders'
33

44
import { content } from './content'
55
import type { CollectionDefinition } from '../cli/getConfig'
6+
import { convertToMDX } from '../cli/convertToMDX'
67

78
function defineContent(contentObj: CollectionDefinition) {
89
const { base, packageName, pattern, name } = contentObj
@@ -20,8 +21,11 @@ function defineContent(contentObj: CollectionDefinition) {
2021
'core-component-docs': 'html',
2122
}
2223

24+
convertToMDX(pattern)
25+
const mdxPattern = pattern.replace(/\.md$/, '.mdx')
26+
2327
return defineCollection({
24-
loader: glob({ base: dir, pattern }),
28+
loader: glob({ base: dir, pattern: mdxPattern }),
2529
schema: z.object({
2630
id: z.string(),
2731
section: z.string(),

0 commit comments

Comments
 (0)