mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-06-28 12:16:53 +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 { remark } from "remark"
|
||||||
import html from "remark-html"
|
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) {
|
async function getGuideContent(slug: string) {
|
||||||
const guidePath = path.join(process.cwd(), "..", "..", "guides", `${slug}.md`)
|
const fullPath = path.join(guidesDirectory, `${slug}.md`)
|
||||||
const fileContents = fs.readFileSync(guidePath, "utf8")
|
const fileContents = fs.readFileSync(fullPath, "utf8")
|
||||||
|
|
||||||
const result = await remark().use(html).process(fileContents)
|
const result = await remark().use(html).process(fileContents)
|
||||||
return result.toString()
|
return result.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function generateStaticParams() {
|
export async function generateStaticParams() {
|
||||||
const guidesPath = path.join(process.cwd(), "..", "..", "guides")
|
try {
|
||||||
const guideFiles = fs.readdirSync(guidesPath)
|
const guideFiles = fs.readdirSync(guidesDirectory)
|
||||||
return guideFiles.map((file) => ({
|
return guideFiles.map((file) => ({
|
||||||
slug: file.replace(/\.md$/, ""),
|
slug: file.replace(/\.md$/, ""),
|
||||||
}))
|
}))
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error reading guides directory:", error)
|
||||||
|
return []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function GuidePage({ params }: { params: { slug: string } }) {
|
export default async function GuidePage({ params }: { params: { slug: string } }) {
|
||||||
const guideContent = await getGuideContent(params.slug)
|
try {
|
||||||
|
const guideContent = await getGuideContent(params.slug)
|
||||||
return (
|
return (
|
||||||
<div className="container mx-auto px-4 py-16 max-w-3xl">
|
<div className="container mx-auto px-4 py-16 max-w-3xl">
|
||||||
<div className="prose prose-lg" dangerouslySetInnerHTML={{ __html: guideContent }} />
|
<div className="prose prose-lg" dangerouslySetInnerHTML={{ __html: guideContent }} />
|
||||||
</div>
|
</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