Skip to content

Commit c63afe4

Browse files
committed
added load-remote-url component
1 parent 298f16a commit c63afe4

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

src/components/markdown/index.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { MDXRemote } from 'next-mdx-remote/rsc';
2-
import rehypePrettyCode from 'rehype-pretty-code';
3-
import rehypeSlug from 'rehype-slug';
4-
import remarkBreaks from 'remark-breaks';
5-
import remarkGfm from 'remark-gfm';
2+
63
import style from './style.module.scss';
74
import { MDXInjectComponents } from './inject-components';
5+
import { MDXOption } from './mdx-option';
86
type Props = {
97
content: string;
108
};
@@ -14,13 +12,7 @@ export default function MDXRenderer(props: Props) {
1412
<article className={`${style['cgoing-markdown']} mb-40`}>
1513
<MDXRemote
1614
source={props.content}
17-
options={{
18-
parseFrontmatter: true,
19-
mdxOptions: {
20-
remarkPlugins: [remarkGfm, remarkBreaks],
21-
rehypePlugins: [rehypePrettyCode, rehypeSlug],
22-
},
23-
}}
15+
options={MDXOption}
2416
components={MDXInjectComponents}
2517
/>
2618
</article>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Icon from '@components/icon';
2+
import LoadRemoteUrl from './load-remote-url';
23

34
export const MDXInjectComponents = {
45
Icon,
6+
LoadRemoteUrl,
57
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { compileMDX } from 'next-mdx-remote/rsc';
2+
import { MDXOption } from '../mdx-option';
3+
export default async function LoadRemoteUrl({ url }: { url: string }) {
4+
const source = await fetch(url).then((res) => res.text());
5+
6+
const { content } = await compileMDX<{ title: string }>({
7+
source,
8+
options: MDXOption,
9+
});
10+
return content;
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import rehypePrettyCode from 'rehype-pretty-code';
2+
import rehypeSlug from 'rehype-slug';
3+
import remarkBreaks from 'remark-breaks';
4+
import remarkGfm from 'remark-gfm';
5+
export const MDXOption = {
6+
parseFrontmatter: true,
7+
mdxOptions: {
8+
remarkPlugins: [remarkGfm, remarkBreaks],
9+
rehypePlugins: [rehypePrettyCode, rehypeSlug],
10+
},
11+
};

0 commit comments

Comments
 (0)