Skip to content

Commit 7adb490

Browse files
committed
update readmes
1 parent 14d69b2 commit 7adb490

File tree

3 files changed

+61
-90
lines changed

3 files changed

+61
-90
lines changed

examples/app-router/readme.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,22 @@ You can check out the demo of [this page](https://github.com/mintlify/mdx/blob/m
1010

1111
## How to use
1212

13-
1. Call the `getCompiledServerMdx` function inside your async React Server Component which will give you the `frontmatter` and `content`.
13+
1. Use the `MDXRemote` component directly inside your async React Server Component.
1414

1515
```tsx
16-
import { getCompiledServerMdx } from '@mintlify/mdx';
16+
import { MDXRemote } from '@mintlify/mdx';
1717

1818
export default async function Home() {
19-
const { content, frontmatter } = await getCompiledServerMdx({
20-
source: `---
21-
title: Title
22-
---
23-
24-
## Markdown H2
25-
`,
26-
});
19+
const source: `---
20+
title: Title
21+
---
22+
23+
## Markdown H2
24+
`;
2725

2826
return (
2927
<article className="prose mx-auto py-8">
30-
<h1>{String(frontmatter.title)}</h1>
31-
32-
{content}
28+
<MDXRemote source={source} parseFrontmatter />
3329
</article>
3430
);
3531
}

examples/pages-router/readme.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ You can check out the demo of [this page](https://github.com/mintlify/mdx/blob/m
1010

1111
## How to use
1212

13-
1. Call the `getCompiledMdx` function inside `getStaticProps` and return the `mdxSource` object.
13+
1. Call the `serialize` function inside `getStaticProps` and return the `mdxSource` object.
1414

1515
```tsx
1616
export const getStaticProps = (async () => {
17-
const mdxSource = await getCompiledMdx({
17+
const mdxSource = await serialize({
1818
source: '## Markdown H2',
1919
});
2020

21-
return {
22-
props: {
23-
mdxSource,
24-
},
25-
};
21+
if ('error' in mdxSource) {
22+
// handle error case
23+
}
24+
25+
return { props: { mdxSource } };
2626
}) satisfies GetStaticProps<{
27-
mdxSource: MDXCompiledResult;
27+
mdxSource: SerializeSuccess;
2828
}>;
2929
```
3030

3131
2. Pass the `mdxSource` object as props inside the `MDXComponent`.
3232

3333
```tsx
3434
export default function Page({ mdxSource }: InferGetStaticPropsType<typeof getStaticProps>) {
35-
return <MDXComponent {...mdxSource} />;
35+
return <MDXClient {...mdxSource} />;
3636
}
3737
```
3838

readme.md

Lines changed: 43 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
# Mintlify's markdown parser
3030

31-
**@mintlify/mdx** is a thin layer on top of [next-mdx-remote](https://github.com/hashicorp/next-mdx-remote) that provides a better developer experience for Next.js users by adding support for syntax highlighting.
31+
**@mintlify/mdx** is a thin layer on top of [next-mdx-remote-client](https://github.com/ipikuka/next-mdx-remote-client) that provides a better developer experience for Next.js users by adding support for syntax highlighting.
3232

3333
## Installation
3434

@@ -49,29 +49,29 @@ pnpm add @mintlify/mdx
4949

5050
[You can check the example app here](https://github.com/mintlify/mdx/tree/main/examples/pages-router).
5151

52-
1. Call the `getCompiledMdx` function inside `getStaticProps` and return the `mdxSource` object.
52+
1. Call the `serialize` function inside `getStaticProps` and return the `mdxSource` object.
5353

5454
```tsx
5555
export const getStaticProps = (async () => {
56-
const mdxSource = await getCompiledMdx({
56+
const mdxSource = await serialize({
5757
source: '## Markdown H2',
5858
});
5959

60-
return {
61-
props: {
62-
mdxSource,
63-
},
64-
};
60+
if ('error' in mdxSource) {
61+
// handle error case
62+
}
63+
64+
return { props: { mdxSource } };
6565
}) satisfies GetStaticProps<{
66-
mdxSource: MDXCompiledResult;
66+
mdxSource: SerializeSuccess;
6767
}>;
6868
```
6969

7070
2. Pass the `mdxSource` object as props inside the `MDXComponent`.
7171

7272
```tsx
7373
export default function Page({ mdxSource }: InferGetStaticPropsType<typeof getStaticProps>) {
74-
return <MDXComponent {...mdxSource} />;
74+
return <MDXClient {...mdxSource} />;
7575
}
7676
```
7777

@@ -90,26 +90,22 @@ pnpm add @mintlify/mdx
9090

9191
[You can check the example app here](https://github.com/mintlify/mdx/tree/main/examples/app-router).
9292

93-
1. Call the `getCompiledServerMdx` function inside your async React Server Component which will give you the `frontmatter` and `content`.
93+
1. Use the `MDXRemote` component directly inside your async React Server Component.
9494

9595
```tsx
96-
import { getCompiledServerMdx } from '@mintlify/mdx';
96+
import { MDXRemote } from '@mintlify/mdx';
9797

9898
export default async function Home() {
99-
const { content, frontmatter } = await getCompiledServerMdx({
100-
source: `---
101-
title: Title
102-
---
103-
104-
## Markdown H2
105-
`,
106-
});
99+
const source: `---
100+
title: Title
101+
---
102+
103+
## Markdown H2
104+
`;
107105

108106
return (
109107
<article className="prose mx-auto py-8">
110-
<h1>{String(frontmatter.title)}</h1>
111-
112-
{content}
108+
<MDXRemote source={source} parseFrontmatter />
113109
</article>
114110
);
115111
}
@@ -137,19 +133,18 @@ pnpm add @mintlify/mdx
137133

138134
## APIs
139135

140-
Similar to [next-mdx-remote](https://github.com/hashicorp/next-mdx-remote), this package exports the following APIs:
136+
Similar to [next-mdx-remote-client](https://github.com/ipikuka/next-mdx-remote-client), this package exports the following APIs:
141137

142-
- `getCompiledMdx` - a function that compiles MDX source to MDXCompiledResult.
143-
- `MDXComponent` - a component that renders MDXCompiledResult.
144-
- `getCompiledServerMdx` - a function that compiles MDX source to return `content` and `frontmatter ` and should be used inside async React Server Component.
145-
- `MDXServerComponent` - a component that renders `content` and `frontmatter ` and should be used inside async React Server Component.
138+
- `serialize` - a function that compiles MDX source to SerializeResult.
139+
- `MDXClient` - a component that renders SerializeSuccess on the client.
140+
- `MDXRemote` - a component that both serializes and renders the source - should be used inside async React Server Component.
146141

147-
### getCompiledMdx
142+
### serialize
148143

149144
```tsx
150-
import { getCompiledMdx } from '@mintlify/mdx';
145+
import { serialize } from '@mintlify/mdx';
151146

152-
const mdxSource = await getCompiledMdx({
147+
const mdxSource = await serialize({
153148
source: '## Markdown H2',
154149
mdxOptions: {
155150
remarkPlugins: [
@@ -162,59 +157,39 @@ const mdxSource = await getCompiledMdx({
162157
});
163158
```
164159

165-
### MDXComponent
160+
### MDXClient
166161

167162
```tsx
168-
import { MDXComponent } from '@mintlify/mdx';
169-
170-
<MDXComponent
171-
components={
172-
{
173-
// Your custom components
174-
}
175-
}
163+
'use client';
164+
165+
import { MDXClient } from '@mintlify/mdx';
166+
167+
<MDXClient
168+
components={{
169+
// Your custom components
170+
}}
176171
{...mdxSource}
177172
/>;
178173
```
179174

180-
### getCompiledServerMdx
175+
### MDXRemote
181176

182177
```tsx
183-
import { getCompiledServerMdx } from '@mintlify/mdx';
184-
185-
const { content, frontmatter } = await getCompiledServerMdx({
186-
source: `---
187-
title: Title
188-
---
178+
import { MDXRemote } from '@mintlify/mdx';
189179

190-
## Markdown H2
191-
`,
192-
mdxOptions: {
180+
<MDXRemote
181+
source="## Markdown H2"
182+
mdxOptions={{
193183
remarkPlugins: [
194184
// Remark plugins
195185
],
196186
rehypePlugins: [
197187
// Rehype plugins
198188
],
199-
},
200-
components: {
189+
}}
190+
components={{
201191
// Your custom components
202-
},
203-
});
204-
```
205-
206-
### MDXServerComponent
207-
208-
```tsx
209-
import { MDXServerComponent } from '@mintlify/mdx';
210-
211-
<MDXServerComponent
212-
source="## Markdown H2"
213-
components={
214-
{
215-
// Your custom components
216-
}
217-
}
192+
}}
218193
/>;
219194
```
220195

0 commit comments

Comments
 (0)