mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-06-29 12:46:54 +00:00
Update page.tsx
This commit is contained in:
parent
079d462ae9
commit
6fa905ec01
@ -3,43 +3,44 @@ import path from "path"
|
|||||||
import { remark } from "remark"
|
import { remark } from "remark"
|
||||||
import html from "remark-html"
|
import html from "remark-html"
|
||||||
|
|
||||||
const guidesDirectory =
|
const guidesDirectory = path.join(process.cwd(), "guides")
|
||||||
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 fullPath = path.join(guidesDirectory, `${slug}.md`)
|
const fullPath = path.join(guidesDirectory, `${slug}.md`)
|
||||||
const fileContents = fs.readFileSync(fullPath, "utf8")
|
try {
|
||||||
|
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()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error reading guide file: ${fullPath}`, error)
|
||||||
|
return "<p>Guide content not found.</p>"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function generateStaticParams() {
|
export async function generateStaticParams() {
|
||||||
try {
|
try {
|
||||||
const guideFiles = fs.readdirSync(guidesDirectory)
|
if (fs.existsSync(guidesDirectory)) {
|
||||||
return guideFiles.map((file) => ({
|
const guideFiles = fs.readdirSync(guidesDirectory)
|
||||||
slug: file.replace(/\.md$/, ""),
|
return guideFiles.map((file) => ({
|
||||||
}))
|
slug: file.replace(/\.md$/, ""),
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
console.warn("Guides directory not found. No static params generated.")
|
||||||
|
return []
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error reading guides directory:", error)
|
console.error("Error generating static params for guides:", error)
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function GuidePage({ params }: { params: { slug: string } }) {
|
export default async function GuidePage({ params }: { params: { slug: string } }) {
|
||||||
try {
|
const guideContent = await getGuideContent(params.slug)
|
||||||
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