diff --git a/src/app/blog/[slug]/page.tsx b/src/app/blog/[slug]/page.tsx index 13943d8..cd969cd 100644 --- a/src/app/blog/[slug]/page.tsx +++ b/src/app/blog/[slug]/page.tsx @@ -1,8 +1,8 @@ import { FC } from "react"; import { allBlogs } from "contentlayer/generated"; import { notFound } from "next/navigation"; -import { Mdx } from "@/components/Common/Mdx"; import Container from "@/components/Common/Container/Container"; +import { Mdx } from "@/components/Common/Mdx/Mdx"; const getBlogFromParams = async (slug: string) => { const blogDetail = allBlogs.find((blog) => blog.slugAsParams === slug); diff --git a/src/app/profile/[slug]/page.tsx b/src/app/profile/[slug]/page.tsx index 6e4d26b..4add1c7 100644 --- a/src/app/profile/[slug]/page.tsx +++ b/src/app/profile/[slug]/page.tsx @@ -1,5 +1,5 @@ import Container from "@/components/Common/Container/Container"; -import { Mdx } from "@/components/Common/Mdx"; +import { Mdx } from "@/components/Common/Mdx/Mdx"; import { allProfiles } from "contentlayer/generated"; import { notFound } from "next/navigation"; import { FC } from "react"; diff --git a/src/components/Common/Mdx/Mdx.tsx b/src/components/Common/Mdx/Mdx.tsx new file mode 100644 index 0000000..777ec42 --- /dev/null +++ b/src/components/Common/Mdx/Mdx.tsx @@ -0,0 +1,168 @@ +import { cn } from "@/utils"; +import { useMDXComponent } from "next-contentlayer/hooks"; +import React from "react"; + +const components = { + h1: ({ className, ...rest }: React.HTMLAttributes) => ( +

+ ), + h2: ({ className, ...rest }: React.HTMLAttributes) => ( +

+ ), + h3: ({ className, ...rest }: React.HTMLAttributes) => ( +

+ ), + h4: ({ className, ...rest }: React.HTMLAttributes) => ( +

+ ), + h5: ({ className, ...rest }: React.HTMLAttributes) => ( +
+ ), + h6: ({ className, ...rest }: React.HTMLAttributes) => ( +
+ ), + a: ({ className, ...rest }: React.HTMLAttributes) => ( + + ), + p: ({ className, ...rest }: React.HTMLAttributes) => ( +

+ ), + ul: ({ className, ...rest }: React.HTMLAttributes) => ( +

    + ), + ol: ({ className, ...rest }: React.HTMLAttributes) => ( +
      + ), + li: ({ className, ...rest }: React.HTMLAttributes) => ( +
    1. + ), + blockquote: ({ + className, + ...rest + }: React.HTMLAttributes) => ( +
      *]:text-muted-foreground", + className + )} + {...rest} + /> + ), + img: ({ + className, + alt, + ...rest + }: React.ImgHTMLAttributes) => ( + // eslint-disable-next-line @next/next/no-img-element + {alt} + ), + hr: ({ className, ...rest }: React.HTMLAttributes) => ( +
      + ), + table: ({ className, ...rest }: React.HTMLAttributes) => ( +
      + + + ), + tr: ({ className, ...rest }: React.HTMLAttributes) => ( + + ), + th: ({ + className, + ...rest + }: React.HTMLAttributes) => ( +
      + ), + td: ({ + className, + ...rest + }: React.HTMLAttributes) => ( + + ), + pre: ({ className, ...rest }: React.HTMLAttributes) => ( +
      +  ),
      +  code: ({ className, ...rest }: React.HTMLAttributes) => (
      +    
      +  ),
      +};
      +
      +interface MdxProps {
      +  code: string;
      +}
      +
      +export function Mdx({ code }: MdxProps) {
      +  const Component = useMDXComponent(code);
      +
      +  return (
      +    
      + +
      + ); +}