fix: fix titles for non-existent documentation pages
Some checks failed
Deploy Next.js application / deploy (push) Failing after 5s

This commit is contained in:
Dorian Niemiec 2024-11-08 18:54:33 +01:00
parent cb9a35cb2b
commit 54cff67b7e

View file

@ -28,6 +28,28 @@ export async function generateMetadata({ params }) {
docLink.href == docLink.href ==
`/docs${obtainedParams.slug ? "/" + obtainedParams.slug.join("/") : ""}` `/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 { return {
title: `${foundDocLink ? foundDocLink.label : obtainedParams.slug && obtainedParams.slug.length > 0 ? obtainedParams.slug[obtainedParams.slug.length - 1] : "Documentation"} - MERNMail`, title: `${foundDocLink ? foundDocLink.label : obtainedParams.slug && obtainedParams.slug.length > 0 ? obtainedParams.slug[obtainedParams.slug.length - 1] : "Documentation"} - MERNMail`,
description: description: