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-14 10:46:02 +01:00
|
|
|
const guidesDirectory =
|
|
|
|
process.env.NODE_ENV === "production"
|
|
|
|
? path.join(process.cwd(), "..", "..", "guides")
|
|
|
|
: path.join(process.cwd(), "..", "guides")
|
|
|
|
|
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`)
|
|
|
|
const fileContents = fs.readFileSync(fullPath, "utf8")
|
2025-02-13 17:28:49 +01:00
|
|
|
|
|
|
|
const result = await remark().use(html).process(fileContents)
|
|
|
|
return result.toString()
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function generateStaticParams() {
|
2025-02-14 10:46:02 +01:00
|
|
|
try {
|
|
|
|
const guideFiles = fs.readdirSync(guidesDirectory)
|
|
|
|
return guideFiles.map((file) => ({
|
|
|
|
slug: file.replace(/\.md$/, ""),
|
|
|
|
}))
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error reading guides directory:", error)
|
|
|
|
return []
|
|
|
|
}
|
2025-02-13 17:28:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default async function GuidePage({ params }: { params: { slug: string } }) {
|
2025-02-14 10:46:02 +01:00
|
|
|
try {
|
|
|
|
const guideContent = await getGuideContent(params.slug)
|
|
|
|
return (
|
|
|
|
<div className="container mx-auto px-4 py-16 max-w-3xl">
|
|
|
|
<div className="prose prose-lg" dangerouslySetInnerHTML={{ __html: guideContent }} />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error rendering guide:", error)
|
|
|
|
return <div>Error: Unable to load guide content.</div>
|
|
|
|
}
|
2025-02-13 17:28:49 +01:00
|
|
|
}
|
2025-02-13 23:04:40 +01:00
|
|
|
|
2025-02-14 10:46:02 +01:00
|
|
|
|