2025-02-13 17:28:49 +01:00
|
|
|
import fs from "fs"
|
|
|
|
import path from "path"
|
|
|
|
import { remark } from "remark"
|
|
|
|
import html from "remark-html"
|
2025-02-15 12:40:28 +01:00
|
|
|
import dynamic from "next/dynamic"
|
|
|
|
|
|
|
|
const CopyableCode = dynamic(() => import("@/components/CopyableCode"), { ssr: false })
|
2025-02-13 17:28:49 +01:00
|
|
|
|
2025-02-14 11:20:10 +01:00
|
|
|
const guidesDirectory = path.join(process.cwd(), "..", "guides")
|
2025-02-14 10:46:02 +01:00
|
|
|
|
2025-02-13 17:28:49 +01:00
|
|
|
async function getGuideContent(slug: string) {
|
2025-02-14 10:46:02 +01:00
|
|
|
const fullPath = path.join(guidesDirectory, `${slug}.md`)
|
2025-02-14 11:05:58 +01:00
|
|
|
try {
|
|
|
|
const fileContents = fs.readFileSync(fullPath, "utf8")
|
|
|
|
const result = await remark().use(html).process(fileContents)
|
|
|
|
return result.toString()
|
|
|
|
} catch (error) {
|
|
|
|
console.error(`Error reading guide file: ${fullPath}`, error)
|
|
|
|
return "<p>Guide content not found.</p>"
|
|
|
|
}
|
2025-02-13 17:28:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function generateStaticParams() {
|
2025-02-14 10:46:02 +01:00
|
|
|
try {
|
2025-02-14 11:05:58 +01:00
|
|
|
if (fs.existsSync(guidesDirectory)) {
|
|
|
|
const guideFiles = fs.readdirSync(guidesDirectory)
|
|
|
|
return guideFiles.map((file) => ({
|
|
|
|
slug: file.replace(/\.md$/, ""),
|
|
|
|
}))
|
|
|
|
} else {
|
|
|
|
console.warn("Guides directory not found. No static params generated.")
|
|
|
|
return []
|
|
|
|
}
|
2025-02-14 10:46:02 +01:00
|
|
|
} catch (error) {
|
2025-02-14 11:05:58 +01:00
|
|
|
console.error("Error generating static params for guides:", error)
|
2025-02-14 10:46:02 +01:00
|
|
|
return []
|
|
|
|
}
|
2025-02-13 17:28:49 +01:00
|
|
|
}
|
|
|
|
|
2025-02-15 12:40:28 +01:00
|
|
|
function wrapCodeBlocksWithCopyable(content: string) {
|
|
|
|
const codeBlockRegex = /<pre><code>([\s\S]*?)<\/code><\/pre>/g
|
|
|
|
return content.replace(codeBlockRegex, (match, code) => {
|
|
|
|
return `<CopyableCode code={\`${code.replace(/`/g, "\\`")}\`} />`
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2025-02-15 11:54:33 +01:00
|
|
|
export default async function GuidePage({ params }: { params: { slug: string } }) {
|
2025-02-15 12:40:28 +01:00
|
|
|
let guideContent = await getGuideContent(params.slug)
|
|
|
|
guideContent = wrapCodeBlocksWithCopyable(guideContent)
|
2025-02-13 23:04:40 +01:00
|
|
|
|
2025-02-14 11:05:58 +01:00
|
|
|
return (
|
2025-02-15 12:06:36 +01:00
|
|
|
<div className="min-h-screen bg-white">
|
2025-02-15 12:40:28 +01:00
|
|
|
<div className="container mx-auto px-4 py-16 max-w-3xl">
|
|
|
|
<div
|
|
|
|
className="prose prose-gray max-w-none
|
|
|
|
[&>h1]:text-3xl [&>h1]:font-bold [&>h1]:text-gray-900 [&>h1]:mb-6
|
|
|
|
[&>h2]:text-2xl [&>h2]:font-semibold [&>h2]:text-gray-900 [&>h2]:mt-8 [&>h2]:mb-4
|
|
|
|
[&>h3]:text-xl [&>h3]:font-semibold [&>h3]:text-gray-900 [&>h3]:mt-6 [&>h3]:mb-3
|
|
|
|
[&>p]:text-gray-700 [&>p]:mb-4
|
|
|
|
[&>ul]:list-disc [&>ul]:pl-5 [&>ul]:mb-4
|
|
|
|
[&>ul>li]:text-gray-700 [&>ul>li]:mb-2
|
|
|
|
[&>ol]:list-decimal [&>ol]:pl-5 [&>ol]:mb-4
|
|
|
|
[&>ol>li]:text-gray-700 [&>ol>li]:mb-2
|
|
|
|
[&>a]:text-blue-600 [&>a:hover]:underline
|
|
|
|
[&>strong]:font-bold [&>strong]:text-gray-900"
|
|
|
|
dangerouslySetInnerHTML={{ __html: guideContent }}
|
|
|
|
/>
|
|
|
|
</div>
|
2025-02-14 11:05:58 +01:00
|
|
|
</div>
|
|
|
|
)
|
2025-02-15 12:22:29 +01:00
|
|
|
}
|
|
|
|
|