From 7ca8d4fb7c5daff51e9c3f5c315ecb6c57e87679 Mon Sep 17 00:00:00 2001 From: mauro-balades Date: Tue, 27 Aug 2024 16:52:58 +0200 Subject: [PATCH] feat: Refactor generateMetadata function and add support for jsDelivr CDN for images --- src/app/themes/[theme]/page.tsx | 32 ++++++++++++++++++++++++++++++++ src/components/theme-page.tsx | 6 +++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/app/themes/[theme]/page.tsx b/src/app/themes/[theme]/page.tsx index 69d150a..e957cc0 100644 --- a/src/app/themes/[theme]/page.tsx +++ b/src/app/themes/[theme]/page.tsx @@ -5,8 +5,40 @@ import ThemePage from "@/components/theme-page"; import { getAllThemes, getThemeFromId } from "@/lib/themes"; import { Metadata, ResolvingMetadata } from "next"; +export async function generateMetadata( + { params, searchParams }: any, + parent: ResolvingMetadata +): Promise { + const theme = params.theme + const themeData = await getThemeFromId(theme); + if (!themeData) { + return { + title: "Theme not found", + description: "Theme not found", + }; + } + return { + title: themeData.name, + description: themeData.description, + keywords: [themeData.name, themeData.description], + openGraph: { + title: themeData.name, + description: themeData.description, + images: [ + { + url: themeData.image, + width: 500, + height: 500, + alt: themeData.name, + }, + ], + }, + }; +} + export async function generateStaticParams() { const themes = await getAllThemes(); + console.log(themes); return themes.map((theme) => ({ theme: theme.id, })); diff --git a/src/components/theme-page.tsx b/src/components/theme-page.tsx index 7e3d619..4b605a7 100644 --- a/src/components/theme-page.tsx +++ b/src/components/theme-page.tsx @@ -1,4 +1,4 @@ -"use client"; + import Image from "next/image"; import { getThemeAuthorLink, getThemeFromId, getThemeMarkdown, ZenTheme } from "@/lib/themes"; import { Button } from "./ui/button"; @@ -19,10 +19,10 @@ export default async function ThemePage({ themeID }: { themeID: string }) { return (
-
window.history.back()}> +

Go back

-
+ {theme.name}

{theme.name}

{theme.description}