From 54cff67b7e4bbe3b071945fc385a06dfba0fd44d Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Fri, 8 Nov 2024 18:54:33 +0100 Subject: [PATCH] fix: fix titles for non-existent documentation pages --- app/docs/[[...slug]]/page.jsx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/docs/[[...slug]]/page.jsx b/app/docs/[[...slug]]/page.jsx index 88a3beb..a46f4d2 100644 --- a/app/docs/[[...slug]]/page.jsx +++ b/app/docs/[[...slug]]/page.jsx @@ -28,6 +28,28 @@ export async function generateMetadata({ params }) { docLink.href == `/docs${obtainedParams.slug ? "/" + obtainedParams.slug.join("/") : ""}` ); + try { + await fs.readFile( + `${process.cwd()}/docs/${obtainedParams.slug ? obtainedParams.slug.join("/") : ""}.md` + ); + // eslint-disable-next-line no-unused-vars + } catch (err) { + try { + await fs.readFile( + `${process.cwd()}/docs/${obtainedParams.slug ? obtainedParams.slug.join("/") : ""}/index.md` + ); + } catch (err) { + return { + title: "404 Not Found - MERNMail", + openGraph: { + title: "404 Not Found - MERNMail" + }, + twitter: { + title: "404 Not Found - MERNMail" + } + }; + } + } return { title: `${foundDocLink ? foundDocLink.label : obtainedParams.slug && obtainedParams.slug.length > 0 ? obtainedParams.slug[obtainedParams.slug.length - 1] : "Documentation"} - MERNMail`, description: