From 17c78701060da177465ff88586bfdad62624dad1 Mon Sep 17 00:00:00 2001 From: MacRimi <123239993+MacRimi@users.noreply.github.com> Date: Sat, 15 Feb 2025 10:53:53 +0100 Subject: [PATCH] Update page.tsx --- web/app/guides/[slug]/page.tsx | 46 ++++++++-------------------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/web/app/guides/[slug]/page.tsx b/web/app/guides/[slug]/page.tsx index 93c7082..8e65e9a 100644 --- a/web/app/guides/[slug]/page.tsx +++ b/web/app/guides/[slug]/page.tsx @@ -1,11 +1,10 @@ -"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 CopyableCode from "@/components/CopyableCode" +import dynamic from "next/dynamic" + +const CopyableCode = dynamic(() => import("@/components/CopyableCode"), { ssr: false }) const guidesDirectory = path.join(process.cwd(), "..", "guides") @@ -38,47 +37,24 @@ export async function generateStaticParams() { } } -function processContent(content: string) { +function wrapCodeBlocksWithCopyable(content: string) { const codeBlockRegex = /
([\s\S]*?)<\/code><\/pre>/g
return content.replace(codeBlockRegex, (match, code) => {
- return ` `
+ return ` `
})
}
-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) => {
- const code = decodeURIComponent(placeholder.getAttribute("code") || "")
- const codeElement =
- placeholder.replaceWith(codeElement)
- })
- }, [])
+export default async function GuidePage({ params }: { params: { slug: string } }) {
+ let guideContent = await getGuideContent(params.slug)
+ guideContent = wrapCodeBlocksWithCopyable(guideContent)
return (
-
+
h1]:text-gray-900 [&>h2]:text-gray-800 [&>h3]:text-gray-700
+ [&>p]:text-gray-600 [&>ul>li]:text-gray-600 [&>ol>li]:text-gray-600"
dangerouslySetInnerHTML={{ __html: guideContent }}
/>