diff --git a/web/app/guides/[slug]/page.tsx b/web/app/guides/[slug]/page.tsx index 8ca1f6a..151b033 100644 --- a/web/app/guides/[slug]/page.tsx +++ b/web/app/guides/[slug]/page.tsx @@ -2,7 +2,9 @@ import fs from "fs" import path from "path" import { remark } from "remark" import html from "remark-html" -import GuideContent from "./GuideContent" +import dynamic from "next/dynamic" + +const CopyableCode = dynamic(() => import("@/components/CopyableCode"), { ssr: false }) const guidesDirectory = path.join(process.cwd(), "..", "guides") @@ -35,12 +37,35 @@ export async function generateStaticParams() { } } +function wrapCodeBlocksWithCopyable(content: string) { + const codeBlockRegex = /
([\s\S]*?)<\/code><\/pre>/g
+ return content.replace(codeBlockRegex, (match, code) => {
+ return ` `
+ })
+}
+
export default async function GuidePage({ params }: { params: { slug: string } }) {
- const guideContent = await getGuideContent(params.slug)
+ let guideContent = await getGuideContent(params.slug)
+ guideContent = wrapCodeBlocksWithCopyable(guideContent)
return (
-
+
+
+
)
}