diff --git a/components/icons/CopyIcon.tsx b/components/icons/CopyIcon.tsx
new file mode 100644
index 0000000..6b08196
--- /dev/null
+++ b/components/icons/CopyIcon.tsx
@@ -0,0 +1,11 @@
+import {Props} from '@/types'
+
+export function CopyIcon(props: Props) {
+ return (
+
+ )
+}
\ No newline at end of file
diff --git a/components/layouts/ArticleLayout.tsx b/components/layouts/ArticleLayout.tsx
index 00f9d96..5009755 100644
--- a/components/layouts/ArticleLayout.tsx
+++ b/components/layouts/ArticleLayout.tsx
@@ -5,13 +5,11 @@ import {Prose} from '@/components/ui/Prose'
import {Views} from '@/components/ui/Views'
import {ArrowDownIcon} from '@/components/icons/ArrowDownIcon'
import ArticleNav from '@/components/ui/ArticleNav'
-import Comments from '@/components/ui/Comments'
+import {Comments} from '@/components/ui/Comments'
import {getAllArticles} from '@/lib/getAllArticles'
import {getComments} from '@/lib/getComments'
import {format} from 'date-fns'
-import type {Comment} from '@/types'
-
type ArticleLayout = {
title: string
date: string
diff --git a/components/ui/Code.tsx b/components/ui/Code.tsx
new file mode 100644
index 0000000..1e71606
--- /dev/null
+++ b/components/ui/Code.tsx
@@ -0,0 +1,22 @@
+'use client'
+
+import React, {ReactNode, useRef} from 'react'
+import {CopyIcon} from '@/components/icons/CopyIcon'
+
+export function Code({children}: { children: ReactNode }) {
+ const preRef = useRef(null)
+
+ const handleCopy = async (e: React.MouseEvent) => {
+ e.preventDefault()
+ await navigator.clipboard.writeText(preRef.current?.innerText ?? '')
+ }
+
+ return (
+
+
+ {children}
+
+ )
+}
\ No newline at end of file
diff --git a/components/ui/Comments.tsx b/components/ui/Comments.tsx
index f90df4f..d52e060 100644
--- a/components/ui/Comments.tsx
+++ b/components/ui/Comments.tsx
@@ -205,7 +205,7 @@ type CommentsProps = {
comments?: any
}
-export default function Comments({slug, comments}: CommentsProps) {
+export function Comments({slug, comments}: CommentsProps) {
return (
diff --git a/mdx-components.tsx b/mdx-components.tsx
index 4c2e529..f6bcbbf 100644
--- a/mdx-components.tsx
+++ b/mdx-components.tsx
@@ -1,4 +1,6 @@
import type {MDXComponents} from 'mdx/types'
+import React from 'react'
+import {Code} from '@/components/ui/Code'
import {Heading} from './components/ui/Heading'
// This file allows you to provide custom React components
@@ -11,6 +13,7 @@ export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
h2: ({children}) => {children},
h3: ({children}) => {children},
+ pre: ({children}) => {children}
,
// Allows customizing built-in components, e.g. to add styling.
// h1: ({ children }) => {children}
,
...components