mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-06-30 05:06:53 +00:00
Update page.tsx
This commit is contained in:
parent
56dc21fc77
commit
d82df8795f
@ -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,19 +38,35 @@ export async function generateStaticParams() {
|
||||
}
|
||||
}
|
||||
|
||||
function wrapCodeBlocksWithCopyable(content: string) {
|
||||
function processContent(content: string) {
|
||||
const codeBlockRegex = /<pre><code>([\s\S]*?)<\/code><\/pre>/g
|
||||
return content.replace(codeBlockRegex, (match, code) => {
|
||||
return `<CopyableCode code={\`${code.replace(/`/g, "\\`")}\`} />`
|
||||
return `<CopyableCodePlaceholder code="${encodeURIComponent(code)}" />`
|
||||
})
|
||||
}
|
||||
|
||||
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<string>("")
|
||||
|
||||
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 = <CopyableCode key={index} code={code} /> // Added key prop
|
||||
placeholder.replaceWith(codeElement)
|
||||
})
|
||||
}, []) // Removed guideContent from dependencies
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-white">
|
||||
<div className="max-w-3xl mx-auto px-4 sm:px-6 lg:px-8 py-8 text-gray-900">
|
||||
<div
|
||||
className="prose prose-gray max-w-none
|
||||
@ -65,7 +82,6 @@ export default async function GuidePage({ params }: { params: { slug: string } }
|
||||
dangerouslySetInnerHTML={{ __html: guideContent }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user