diff --git a/web/app/guides/[slug]/page.tsx b/web/app/guides/[slug]/page.tsx index 04e1273..34f96ae 100644 --- a/web/app/guides/[slug]/page.tsx +++ b/web/app/guides/[slug]/page.tsx @@ -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 ( -