48 lines
1.3 KiB
TypeScript
Raw Normal View History

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 11:54:33 +01:00
import GuideContent from "./GuideContent"
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 11:54:33 +01:00
export default async function GuidePage({ params }: { params: { slug: string } }) {
const guideContent = await getGuideContent(params.slug)
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:22:29 +01:00
<GuideContent content={guideContent} />
2025-02-14 11:05:58 +01:00
</div>
)
2025-02-15 12:22:29 +01:00
}