From 6fa905ec01fcb23a3726822b72d53828ecce38d7 Mon Sep 17 00:00:00 2001 From: MacRimi <123239993+MacRimi@users.noreply.github.com> Date: Fri, 14 Feb 2025 11:05:58 +0100 Subject: [PATCH] Update page.tsx --- web/app/guides/[slug]/page.tsx | 51 +++++++++++++++++----------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/web/app/guides/[slug]/page.tsx b/web/app/guides/[slug]/page.tsx index 34f96ae..b448677 100644 --- a/web/app/guides/[slug]/page.tsx +++ b/web/app/guides/[slug]/page.tsx @@ -3,43 +3,44 @@ 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") +const guidesDirectory = path.join(process.cwd(), "guides") async function getGuideContent(slug: string) { const fullPath = path.join(guidesDirectory, `${slug}.md`) - const fileContents = fs.readFileSync(fullPath, "utf8") - - const result = await remark().use(html).process(fileContents) - return result.toString() + try { + const fileContents = fs.readFileSync(fullPath, "utf8") + const result = await remark().use(html).process(fileContents) + return result.toString() + } catch (error) { + console.error(`Error reading guide file: ${fullPath}`, error) + return "
Guide content not found.
" + } } export async function generateStaticParams() { try { - const guideFiles = fs.readdirSync(guidesDirectory) - return guideFiles.map((file) => ({ - slug: file.replace(/\.md$/, ""), - })) + if (fs.existsSync(guidesDirectory)) { + const guideFiles = fs.readdirSync(guidesDirectory) + return guideFiles.map((file) => ({ + slug: file.replace(/\.md$/, ""), + })) + } else { + console.warn("Guides directory not found. No static params generated.") + return [] + } } catch (error) { - console.error("Error reading guides directory:", error) + console.error("Error generating static params for guides:", error) return [] } } export default async function GuidePage({ params }: { params: { slug: string } }) { - try { - const guideContent = await getGuideContent(params.slug) - return ( -