From cf6447e4c413e8ea3cc35cd6aed2940b1b872f0e Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Sun, 6 Oct 2024 18:34:09 -0400 Subject: [PATCH] per-page metadata Took 14 minutes --- docs/intro.md | 67 +----------------------------------- src/app/[[...slug]]/page.tsx | 35 +++++++++++++++++++ src/components/embed.tsx | 50 +++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 66 deletions(-) create mode 100644 src/components/embed.tsx diff --git a/docs/intro.md b/docs/intro.md index 7f4a3dd..1a74f8f 100644 --- a/docs/intro.md +++ b/docs/intro.md @@ -5,69 +5,4 @@ summary: 'petentium usu tota noluisse errem elaboraret auctor.' --- # Get started with Pulse App! -petentium usu tota noluisse errem elaboraret auctor. -petentium usu tota noluisse errem elaboraret auctor. -petentium usu tota noluisse errem elaboraret auctor. -petentium usu tota noluisse errem elaboraret auctor. -petentium usu tota noluisse errem elaboraret auctor. -petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. -## petentium usu tota noluisse errem elaboraret auctor. \ No newline at end of file +petentium usu tota noluisse errem elaboraret auctor. \ No newline at end of file diff --git a/src/app/[[...slug]]/page.tsx b/src/app/[[...slug]]/page.tsx index 8322a0a..1fbcfd0 100644 --- a/src/app/[[...slug]]/page.tsx +++ b/src/app/[[...slug]]/page.tsx @@ -10,6 +10,8 @@ import { BreadcrumbSeparator, } from "@/components/ui/breadcrumb"; import { capitalizeWords } from "@/lib/string"; +import { Metadata } from "next"; +import Embed from "@/components/embed"; /** * The page to render the documentation markdown content. @@ -70,4 +72,37 @@ const DocsPage = async ({ ); }; + +export const generateMetadata = async ({ + params, +}: { + params: Promise<{ slug: string[] }>; +}): Promise => { + const slug: string = (((await params).slug as string[]) || undefined)?.join( + "/" + ); // The slug of the content + let embed: Metadata | undefined; // The content embed, if any + if (slug) { + const content: DocsContentMetadata | undefined = getDocsContent().find( + (metadata: DocsContentMetadata): boolean => metadata.slug === slug + ); // Get the content based on the provided slug + if (content) { + return Embed({ + title: content.title, + description: content.summary, + }); + } + } + + // Return the page embed + return ( + embed || + Embed({ + title: "Documentation", + description: + "Need help with Pulse App? You've come to the right place!", + }) + ); +}; + export default DocsPage; diff --git a/src/components/embed.tsx b/src/components/embed.tsx new file mode 100644 index 0000000..cfdcabc --- /dev/null +++ b/src/components/embed.tsx @@ -0,0 +1,50 @@ +import { Metadata } from "next"; + +/** + * Props for an embed. + */ +type EmbedProps = { + /** + * The title of the embed. + */ + title: string; + + /** + * The description of the embed. + */ + description: string; + + /** + * The optional thumbnail image of the embed. + */ + thumbnail?: string; +}; + +/** + * An embed for a page. + * + * @param props the embed props + * @returns the embed jsx + */ +const Embed = ({ + title, + description, + thumbnail = "", +}: EmbedProps): Metadata => { + return { + title: title, + openGraph: { + title: `${title}`, + description: description, + images: [ + { + url: thumbnail, + }, + ], + }, + twitter: { + card: "summary", + }, + }; +}; +export default Embed;