posts: replace MDXRemote with @next/mdx dynamic import, remove remark/rehype plugin config from page
This commit is contained in:
@@ -1,17 +1,4 @@
|
|||||||
import { notFound } from 'next/navigation'
|
import { notFound } from 'next/navigation'
|
||||||
import { MDXRemote } from 'next-mdx-remote/rsc'
|
|
||||||
import { getMDXComponents } from '@/mdx-components'
|
|
||||||
import remarkMath from 'remark-math'
|
|
||||||
import remarkGfm from 'remark-gfm'
|
|
||||||
import smartypants from 'remark-smartypants'
|
|
||||||
import rehypePrettyCode from 'rehype-pretty-code'
|
|
||||||
import { transformerCopyButton } from '@rehype-pretty/transformers'
|
|
||||||
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
|
|
||||||
import rehypeKatex from 'rehype-katex'
|
|
||||||
import rehypeSlug from 'rehype-slug'
|
|
||||||
import rehypeExternalLinks from 'rehype-external-links'
|
|
||||||
import type { Element } from 'hast'
|
|
||||||
import type { LineElement } from 'rehype-pretty-code'
|
|
||||||
import { getPosts, getPost } from '@/lib/posts'
|
import { getPosts, getPost } from '@/lib/posts'
|
||||||
import { TableOfContents } from '@/components/blog/TableOfContents'
|
import { TableOfContents } from '@/components/blog/TableOfContents'
|
||||||
import { ScrollToTop } from '@/components/ui/ScrollToTop'
|
import { ScrollToTop } from '@/components/ui/ScrollToTop'
|
||||||
@@ -38,6 +25,8 @@ export default async function PostPage({ params }: { params: Promise<{ slug: str
|
|||||||
|
|
||||||
if (!post) notFound()
|
if (!post) notFound()
|
||||||
|
|
||||||
|
const { default: PostContent } = await import(`@/content/posts/${slug}.mdx`)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ScrollToTop />
|
<ScrollToTop />
|
||||||
@@ -73,67 +62,7 @@ export default async function PostPage({ params }: { params: Promise<{ slug: str
|
|||||||
)}
|
)}
|
||||||
</header>
|
</header>
|
||||||
<div className="prose prose-lg max-w-none">
|
<div className="prose prose-lg max-w-none">
|
||||||
<MDXRemote
|
<PostContent />
|
||||||
source={post.source}
|
|
||||||
components={getMDXComponents({})}
|
|
||||||
options={{
|
|
||||||
mdxOptions: {
|
|
||||||
remarkPlugins: [smartypants, remarkMath, remarkGfm],
|
|
||||||
rehypePlugins: [
|
|
||||||
rehypeSlug,
|
|
||||||
[rehypeExternalLinks, {
|
|
||||||
target: '_blank',
|
|
||||||
rel: ['nofollow', 'noopener', 'noreferrer'],
|
|
||||||
}],
|
|
||||||
rehypeAutolinkHeadings,
|
|
||||||
[rehypePrettyCode, {
|
|
||||||
theme: {
|
|
||||||
light: 'github-light',
|
|
||||||
dark: 'github-dark-dimmed',
|
|
||||||
},
|
|
||||||
keepBackground: false,
|
|
||||||
lineNumbers: true,
|
|
||||||
filterMetaString: (metaString: string | undefined) => (metaString || '') + ' showLineNumbers',
|
|
||||||
grid: true,
|
|
||||||
onVisitLine(node: LineElement) {
|
|
||||||
if (node.children.length === 0) {
|
|
||||||
node.children = [{ type: 'text', value: ' ' }];
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onVisitTitle(element: Element) {
|
|
||||||
const existingClassNames = Array.isArray(element.properties.className)
|
|
||||||
? element.properties.className
|
|
||||||
: [];
|
|
||||||
element.properties.className = [
|
|
||||||
...existingClassNames,
|
|
||||||
'vscode-title',
|
|
||||||
];
|
|
||||||
element.children = [
|
|
||||||
{
|
|
||||||
type: 'element',
|
|
||||||
tagName: 'span',
|
|
||||||
properties: { className: ['vscode-dots'] },
|
|
||||||
children: [
|
|
||||||
{ type: 'element', tagName: 'span', properties: { className: ['dot-red'] }, children: [] },
|
|
||||||
{ type: 'element', tagName: 'span', properties: { className: ['dot-yellow'] }, children: [] },
|
|
||||||
{ type: 'element', tagName: 'span', properties: { className: ['dot-green'] }, children: [] },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
element.children[0],
|
|
||||||
];
|
|
||||||
},
|
|
||||||
transformers: [
|
|
||||||
transformerCopyButton({
|
|
||||||
visibility: 'hover',
|
|
||||||
feedbackDuration: 2_500,
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
rehypeKatex,
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
<aside className="hidden lg:block">
|
<aside className="hidden lg:block">
|
||||||
|
|||||||
Reference in New Issue
Block a user