mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-06-28 04:06:54 +00:00
Update page.tsx
This commit is contained in:
parent
51b3ef6b5a
commit
39a4b7b0e2
@ -3,29 +3,43 @@ import path from "path"
|
||||
import { remark } from "remark"
|
||||
import html from "remark-html"
|
||||
|
||||
const guidesDirectory =
|
||||
process.env.NODE_ENV === "production"
|
||||
? path.join(process.cwd(), "..", "..", "guides")
|
||||
: path.join(process.cwd(), "..", "guides")
|
||||
|
||||
async function getGuideContent(slug: string) {
|
||||
const guidePath = path.join(process.cwd(), "..", "..", "guides", `${slug}.md`)
|
||||
const fileContents = fs.readFileSync(guidePath, "utf8")
|
||||
const fullPath = path.join(guidesDirectory, `${slug}.md`)
|
||||
const fileContents = fs.readFileSync(fullPath, "utf8")
|
||||
|
||||
const result = await remark().use(html).process(fileContents)
|
||||
return result.toString()
|
||||
}
|
||||
|
||||
export async function generateStaticParams() {
|
||||
const guidesPath = path.join(process.cwd(), "..", "..", "guides")
|
||||
const guideFiles = fs.readdirSync(guidesPath)
|
||||
return guideFiles.map((file) => ({
|
||||
slug: file.replace(/\.md$/, ""),
|
||||
}))
|
||||
try {
|
||||
const guideFiles = fs.readdirSync(guidesDirectory)
|
||||
return guideFiles.map((file) => ({
|
||||
slug: file.replace(/\.md$/, ""),
|
||||
}))
|
||||
} catch (error) {
|
||||
console.error("Error reading guides directory:", error)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
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" dangerouslySetInnerHTML={{ __html: guideContent }} />
|
||||
</div>
|
||||
)
|
||||
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>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user