import '@catppuccin/highlightjs/sass/catppuccin-variables.rgb.scss'; import clsx from 'clsx'; import components from 'components/mdx/components'; import data from 'content/mdx-data'; import { allPostsPath, readSinglePost } from 'lib/posts'; import { SingleToc, generateToc } from 'lib/utils'; import { compileMDX } from 'next-mdx-remote/rsc'; import dynamic from 'next/dynamic'; import { notFound } from 'next/navigation'; import rehypeHighlight from 'rehype-highlight'; import rehypeSlug from 'rehype-slug'; import remarkGfm from 'remark-gfm'; import { Post } from 'types'; const PostToc = dynamic(() => import('components/post/post-toc')); const PostCommnetLine = dynamic( () => import('components/post/post-commnet-line'), ); export async function generateStaticParams() { return await allPostsPath(); } const Page = async ({ params, }: { params: Promise<{ slug: string; }>; }) => { const { slug } = await params; if (!slug) notFound(); const post = await readSinglePost(slug); const toc = generateToc(post); const calcLength = (prev: number, cur: SingleToc) => { const childLen = cur.children.length; return childLen ? prev + childLen + 1 : prev + 1; }; const tocLength = toc.reduce(calcLength, 0); const mdxSource = await compileMDX({ source: post, options: { parseFrontmatter: true, mdxOptions: { remarkPlugins: [remarkGfm], rehypePlugins: [ [rehypeHighlight, { alias: { vue: 'xml' } }], rehypeSlug, ], }, scope: data, }, components: { ...(components as {}) }, }); return ( <>

{mdxSource.frontmatter?.title}

{mdxSource.content} {/*
*/} {/* */} {/*
*/}
); }; export default Page;