mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-06-30 13:16:53 +00:00
Update page.tsx
This commit is contained in:
parent
bab8929ca4
commit
17c7870106
@ -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 = /<pre><code>([\s\S]*?)<\/code><\/pre>/g
|
||||
return content.replace(codeBlockRegex, (match, code) => {
|
||||
return `<CopyableCodePlaceholder code="${encodeURIComponent(code)}" />`
|
||||
return `<CopyableCode code={\`${code.replace(/`/g, "\\`")}\`} />`
|
||||
})
|
||||
}
|
||||
|
||||
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) => {
|
||||
const code = decodeURIComponent(placeholder.getAttribute("code") || "")
|
||||
const codeElement = <CopyableCode key={index} code={code} />
|
||||
placeholder.replaceWith(codeElement)
|
||||
})
|
||||
}, [])
|
||||
export default async function GuidePage({ params }: { params: { slug: string } }) {
|
||||
let guideContent = await getGuideContent(params.slug)
|
||||
guideContent = wrapCodeBlocksWithCopyable(guideContent)
|
||||
|
||||
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="container mx-auto px-4 py-16 max-w-3xl">
|
||||
<div
|
||||
className="prose prose-gray max-w-none
|
||||
[&>h1]:text-3xl [&>h1]:sm:text-4xl [&>h1]:font-bold [&>h1]:mb-6
|
||||
[&>h2]:text-2xl [&>h2]:font-semibold [&>h2]:mt-8 [&>h2]:mb-4
|
||||
[&>h3]:text-xl [&>h3]:font-medium [&>h3]:mt-6 [&>h3]:mb-3
|
||||
[&>p]:mb-4 [&>p]:text-gray-600
|
||||
[&>ul]:list-disc [&>ul]:pl-5 [&>ul]:mb-4
|
||||
[&>ul>li]:text-gray-600 [&>ul>li]:mb-2
|
||||
[&>ol]:list-decimal [&>ol]:pl-5 [&>ol]:mb-4
|
||||
[&>ol>li]:text-gray-600 [&>ol>li]:mb-2
|
||||
[&>a]:text-blue-600 [&>a:hover]:underline"
|
||||
[&>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 }}
|
||||
/>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user