39 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-13 21:46:23 +01:00
// Function to retrieve the guide content based on the slug
2025-02-13 17:28:49 +01:00
async function getGuideContent(slug: string) {
2025-02-13 21:46:23 +01:00
const guidePath = path.join(process.cwd(), "guides", slug, "index.md") // Adjusted to look inside a folder
2025-02-13 17:28:49 +01:00
const fileContents = fs.readFileSync(guidePath, "utf8")
const result = await remark().use(html).process(fileContents)
return result.toString()
}
2025-02-13 21:46:23 +01:00
// Function to generate static paths for all available guides
2025-02-13 17:28:49 +01:00
export async function generateStaticParams() {
2025-02-13 21:46:23 +01:00
const guidesPath = path.join(process.cwd(), "guides")
const guideFolders = fs.readdirSync(guidesPath, { withFileTypes: true }) // Read only directories
return guideFolders
.filter((folder) => folder.isDirectory()) // Ensure it's a directory
.map((folder) => ({
slug: folder.name, // Use the folder name as slug
}))
2025-02-13 17:28:49 +01:00
}
2025-02-13 21:46:23 +01:00
// Page component to render a guide based on its slug
2025-02-13 17:28:49 +01:00
export default async function GuidePage({ params }: { params: { slug: string } }) {
const guideContent = await getGuideContent(params.slug)
return (
<div className="container mx-auto px-4 py-16 max-w-3xl">
<div className="prose prose-lg dark:prose-invert" dangerouslySetInnerHTML={{ __html: guideContent }} />
</div>
)
}
2025-02-13 21:46:23 +01:00