diff --git a/web/app/guides/[slug]/page.tsx b/web/app/guides/[slug]/page.tsx index 0a5a2e6..5ba3862 100644 --- a/web/app/guides/[slug]/page.tsx +++ b/web/app/guides/[slug]/page.tsx @@ -1,10 +1,11 @@ +"use client" + +import { useState, useEffect } from "react" import fs from "fs" import path from "path" import { remark } from "remark" import html from "remark-html" -import dynamic from "next/dynamic" - -const CopyableCode = dynamic(() => import("@/components/CopyableCode"), { ssr: false }) +import CopyableCode from "@/components/CopyableCode" const guidesDirectory = path.join(process.cwd(), "..", "guides") @@ -37,34 +38,49 @@ export async function generateStaticParams() { } } -function wrapCodeBlocksWithCopyable(content: string) { +function processContent(content: string) { const codeBlockRegex = /
([\s\S]*?)<\/code><\/pre>/g
   return content.replace(codeBlockRegex, (match, code) => {
-    return ``
+    return ``
   })
 }
 
-export default async function GuidePage({ params }: { params: { slug: string } }) {
-  let guideContent = await getGuideContent(params.slug)
-  guideContent = wrapCodeBlocksWithCopyable(guideContent)
+export default function GuidePage({ params }: { params: { slug: string } }) {
+  const [guideContent, setGuideContent] = useState("")
+
+  useEffect(() => {
+    async function fetchContent() {
+      const content = await getGuideContent(params.slug)
+      setGuideContent(processContent(content))
+    }
+    fetchContent()
+  }, [params.slug])
+
+  useEffect(() => {
+    const placeholders = document.querySelectorAll("CopyableCodePlaceholder")
+    placeholders.forEach((placeholder, index) => {
+      // Added index for key
+      const code = decodeURIComponent(placeholder.getAttribute("code") || "")
+      const codeElement =  // Added key prop
+      placeholder.replaceWith(codeElement)
+    })
+  }, []) // Removed guideContent from dependencies
 
   return (
-    
-
-
-
+
+
) }