diff --git a/web/app/guides/[slug]/page.tsx b/web/app/guides/[slug]/page.tsx index 3b0affb..d2c2714 100644 --- a/web/app/guides/[slug]/page.tsx +++ b/web/app/guides/[slug]/page.tsx @@ -2,6 +2,11 @@ import fs from "fs" import path from "path" import { remark } from "remark" import html from "remark-html" +import dynamic from "next/dynamic" +import React from "react" + + +const CopyableCode = dynamic(() => import("@/components/CopyableCode"), { ssr: false }) async function getGuideContent(slug: string) { const guidePath = path.join(process.cwd(), "..", "guides", `${slug}.md`) @@ -18,23 +23,26 @@ export async function generateStaticParams() { })) } + +function wrapCodeBlocksWithCopyable(content: string) { + return content.split(/(
[\s\S]*?<\/code><\/pre>)/g).map((segment, index) => {
+    const match = segment.match(/
([\s\S]*?)<\/code><\/pre>/)
+    if (match) {
+      const codeContent = match[1].trim()
+      return React.createElement(CopyableCode, { code: codeContent, key: index })
+    }
+    return segment
+  })
+}
+
 export default async function GuidePage({ params }: { params: { slug: string } }) {
   const guideContent = await getGuideContent(params.slug)
-
-  // Función para envolver los bloques de código con CopyableCode
-  const wrapCodeBlocks = (content: string) => {
-    return content.replace(
-      /
([\s\S]*?)<\/code><\/pre>/g,
-      (match, code) => ``,
-    )
-  }
-
-  const wrappedContent = wrapCodeBlocks(guideContent)
+  const wrappedContent = wrapCodeBlocksWithCopyable(guideContent)
 
   return (
     
-
+
{wrappedContent}
)