From 09c84d4a3ef5d6195c038036613b53971d69ffd2 Mon Sep 17 00:00:00 2001 From: MacRimi <123239993+MacRimi@users.noreply.github.com> Date: Sat, 15 Feb 2025 12:40:28 +0100 Subject: [PATCH] Update page.tsx --- web/app/guides/[slug]/page.tsx | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) 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 (
     
- +
+
+
) }