diff --git a/app/p/[slug]/page.tsx b/app/p/[slug]/page.tsx new file mode 100644 index 0000000..6031b13 --- /dev/null +++ b/app/p/[slug]/page.tsx @@ -0,0 +1,74 @@ +import rehypePrism from '@mapbox/rehype-prism'; +import components from 'components/mdx/components'; +import PostCommnetLine from 'components/post/post-commnet-line'; +import PostToc from 'components/post/post-toc'; +import data from 'content/mdx-data'; +import { readSinglePost } from 'lib/posts'; +import { SingleToc, generateToc } from 'lib/utils'; +import { MDXRemote, compileMDX } from 'next-mdx-remote/rsc'; +import { serialize } from 'next-mdx-remote/serialize'; +import { notFound } from 'next/navigation'; +import { Suspense, lazy } from 'react'; +import rehypeSlug from 'rehype-slug'; +import remarkGfm from 'remark-gfm'; + +const PostComment = lazy(() => import('components/post/post-comment')); + +const Page = async ({ + params, +}: { + params: { + slug: string; + }; +}) => { + const slug = params.slug; + if (!slug) notFound(); + + const post = await readSinglePost(slug); + const toc = generateToc(post); + // const { ref, inView } = useInView(); + + 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: [ + [rehypePrism, { alias: { vue: 'xml' }, ignoreMissing: true }], + rehypeSlug, + ], + }, + scope: data, + }, + // components: components as {}, + }); + + return ( + <> +
+ {/* @ts-expect-error Async Server Component */} +

{mdxSource.frontmatter?.title}

+ {/* @ts-expect-error Async Server Component */} + + + +
+ {mdxSource.content} + + +
+ +
+
+
+ + ); +}; + +export default Page; \ No newline at end of file diff --git a/components/mdx/pre.tsx b/components/mdx/pre.tsx index 69a134b..cd41098 100644 --- a/components/mdx/pre.tsx +++ b/components/mdx/pre.tsx @@ -1,3 +1,5 @@ +'use client'; + import clsx from 'clsx'; import CopyButton from 'components/post/copy-button'; import useCopyToClipboard from 'lib/hooks/use-copy-to-clipboard'; @@ -42,4 +44,4 @@ const Pre = ({ ...rest }: Props) => { ); }; -export default memo(Pre); +export default memo(Pre); \ No newline at end of file diff --git a/components/post/post-comment.tsx b/components/post/post-comment.tsx index 68a9602..6419e03 100644 --- a/components/post/post-comment.tsx +++ b/components/post/post-comment.tsx @@ -1,3 +1,5 @@ +'use client'; + import Giscus from '@giscus/react'; import { useTheme } from 'next-themes'; import { memo } from 'react'; @@ -24,4 +26,4 @@ const PostComment = () => { ); }; -export default memo(PostComment); +export default memo(PostComment); \ No newline at end of file diff --git a/components/post/post-commnet-line.tsx b/components/post/post-commnet-line.tsx index f9d0599..ec007a9 100644 --- a/components/post/post-commnet-line.tsx +++ b/components/post/post-commnet-line.tsx @@ -1,3 +1,5 @@ +'use client'; + import { useTheme } from 'next-themes'; import Image from 'next/image'; import { memo } from 'react'; @@ -29,4 +31,4 @@ const PostCommnetLine = () => { ); }; -export default memo(PostCommnetLine); +export default memo(PostCommnetLine); \ No newline at end of file diff --git a/components/post/post-toc.tsx b/components/post/post-toc.tsx index 394b66c..e418fed 100644 --- a/components/post/post-toc.tsx +++ b/components/post/post-toc.tsx @@ -1,3 +1,5 @@ +'use client'; + import clsx from 'clsx'; import Anchor from 'components/mdx/anchor'; import { SingleToc } from 'lib/utils'; @@ -77,4 +79,4 @@ const PostToc = ({ toc, tocLength }: Props) => { ); }; -export default memo(PostToc); +export default memo(PostToc); \ No newline at end of file diff --git a/components/rua/rua-code-sandbox.tsx b/components/rua/rua-code-sandbox.tsx index 818f644..389659f 100644 --- a/components/rua/rua-code-sandbox.tsx +++ b/components/rua/rua-code-sandbox.tsx @@ -1,3 +1,5 @@ +'use client'; + import clsx from 'clsx'; import useInView from 'lib/hooks/use-in-view'; import { useTheme } from 'next-themes'; @@ -64,4 +66,4 @@ const RUACodeSandbox = ({ url }: Props) => { ); }; -export default memo(RUACodeSandbox); +export default memo(RUACodeSandbox); \ No newline at end of file diff --git a/components/rua/rua-codepen.tsx b/components/rua/rua-codepen.tsx index 9ee4e01..82096ed 100644 --- a/components/rua/rua-codepen.tsx +++ b/components/rua/rua-codepen.tsx @@ -1,3 +1,5 @@ +'use client'; + import clsx from 'clsx'; import useInView from 'lib/hooks/use-in-view'; import { useTheme } from 'next-themes'; @@ -80,4 +82,4 @@ const RUACodepen = ({ defaultTab, url }: Props) => { ); }; -export default memo(RUACodepen); +export default memo(RUACodepen); \ No newline at end of file diff --git a/components/rua/rua-sandpack.tsx b/components/rua/rua-sandpack.tsx index ea0e0ba..67f767c 100644 --- a/components/rua/rua-sandpack.tsx +++ b/components/rua/rua-sandpack.tsx @@ -1,3 +1,5 @@ +'use client'; + import { Sandpack, SandpackProps } from '@codesandbox/sandpack-react'; import { useTheme } from 'next-themes'; import { memo } from 'react'; @@ -20,4 +22,4 @@ const RUASandpack = ({ ...rest }: Props) => { ); }; -export default memo(RUASandpack); +export default memo(RUASandpack); \ No newline at end of file diff --git a/components/rua/tab/index.tsx b/components/rua/tab/index.tsx index a85cc82..f8a5057 100644 --- a/components/rua/tab/index.tsx +++ b/components/rua/tab/index.tsx @@ -1,3 +1,5 @@ +'use client'; + import clsx from 'clsx'; import React, { memo, useState } from 'react'; import { ItemProps } from './tab-item'; @@ -56,4 +58,4 @@ const Tab = ({ defaultValue, children }: Props) => { ); }; -export default memo(Tab); +export default memo(Tab); \ No newline at end of file