From 9b0e5bfcf799618b7ae2121e80607ea267a65a41 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 20 Apr 2024 03:22:10 +0100 Subject: [PATCH] use title components in docs --- .../documentation/[[...slug]]/page.tsx | 35 +++++++++++-------- src/app/common/documentation.ts | 2 +- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/app/(pages)/documentation/[[...slug]]/page.tsx b/src/app/(pages)/documentation/[[...slug]]/page.tsx index 4f7ac55..594e4be 100644 --- a/src/app/(pages)/documentation/[[...slug]]/page.tsx +++ b/src/app/(pages)/documentation/[[...slug]]/page.tsx @@ -2,6 +2,7 @@ import { getDocumentation } from "@/app/common/documentation"; import { CustomMDX } from "@/app/components/mdx-components"; import { Metadata } from "next"; import { generateEmbed } from "@/app/common/embed"; +import { Title } from "@/app/components/title"; type DocumentationPageParams = { params: { @@ -17,16 +18,30 @@ export async function generateStaticParams() { })); } -export async function generateMetadata({ params: { slug } }: DocumentationPageParams): Promise { - const pageSlug = slug?.join("/"); +/** + * Gets a documentation page by its slug. + * + * @param slug The slug of the documentation page. + */ +function getPage(slug?: string) { const documentationPages = getDocumentation(); - let page = documentationPages.find(page => page.slug === pageSlug); + let page = documentationPages.find(page => page.slug === slug); - // Use the landing page on "/documentation" + // Fallback to the landing page if (!page && !slug) { page = documentationPages.find(page => page.slug === "landing"); } + // We still can't find the page, return undefined + if (!page) { + return undefined; + } + return page; +} + +export async function generateMetadata({ params: { slug } }: DocumentationPageParams): Promise { + const page = getPage(slug?.join("/")); + // Fallback to page not found if (!page) { return generateEmbed({ @@ -42,14 +57,7 @@ export async function generateMetadata({ params: { slug } }: DocumentationPagePa } export default function Page({ params: { slug } }: DocumentationPageParams) { - const pageSlug = slug?.join("/"); - const documentationPages = getDocumentation(); - let page = documentationPages.find(page => page.slug === pageSlug); - - // Use the landing page on "/documentation" - if (!page && !slug) { - page = documentationPages.find(page => page.slug === "landing"); - } + const page = getPage(slug?.join("/")); // Page was not found, show an error page if (!page) { @@ -65,8 +73,7 @@ export default function Page({ params: { slug } }: DocumentationPageParams) {
{/* The documentation page title and description */}
- {page.metadata.title &&

{page.metadata.title}

} - {page.metadata.description &&

{page.metadata.description}

} + </div> {/* The content of the documentation page */} diff --git a/src/app/common/documentation.ts b/src/app/common/documentation.ts index 83969ba..7f40195 100644 --- a/src/app/common/documentation.ts +++ b/src/app/common/documentation.ts @@ -14,7 +14,7 @@ type Metadata = { /** * The description of the documentation page. */ - description?: string; + description: string; }; /**