From 57a45a4c05b8075c365764a9a3441eb2d1ab8741 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 20 Apr 2024 00:50:59 +0100 Subject: [PATCH] generate metadata for the documentation page --- next.config.mjs | 2 +- .../documentation/[[...slug]]/page.tsx | 29 +++++++++++++++---- src/app/components/logo.tsx | 1 - 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/next.config.mjs b/next.config.mjs index dbf009d..274d4bc 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,4 +1,4 @@ -import createMDX from '@next/mdx' +import createMDX from "@next/mdx"; /** @type {import('next').NextConfig} */ const nextConfig = { diff --git a/src/app/(pages)/documentation/[[...slug]]/page.tsx b/src/app/(pages)/documentation/[[...slug]]/page.tsx index 556c92b..98bc37b 100644 --- a/src/app/(pages)/documentation/[[...slug]]/page.tsx +++ b/src/app/(pages)/documentation/[[...slug]]/page.tsx @@ -1,5 +1,13 @@ import { getDocumentation } from "@/common/documentation"; import { CustomMDX } from "@/app/components/mx-components"; +import { Metadata } from "next"; +import { generateEmbed } from "@/common/embed"; + +type DocumentationPageParams = { + params: { + slug?: string; + }; +}; export async function generateStaticParams() { let documentationPages = getDocumentation(); @@ -9,11 +17,22 @@ export async function generateStaticParams() { })); } -type DocumentationPageParams = { - params: { - slug?: string; - }; -}; +export async function generateMetadata({ params: { slug } }: DocumentationPageParams): Promise { + const documentationPages = getDocumentation(); + let page = documentationPages.find(page => page.slug === slug); + + if (!page) { + return generateEmbed({ + title: "Page not found", + description: "The documentation page was not found", + }); + } + + return generateEmbed({ + title: page.metadata.title, + description: "Click to view this page", + }); +} export default function Page({ params: { slug } }: DocumentationPageParams) { const documentationPages = getDocumentation(); diff --git a/src/app/components/logo.tsx b/src/app/components/logo.tsx index a11c164..264dd63 100644 --- a/src/app/components/logo.tsx +++ b/src/app/components/logo.tsx @@ -1,6 +1,5 @@ import Image from "next/image"; import { ReactElement } from "react"; -import config from "@root/config.json"; type LogoProps = { /**