feat: Refactor generateMetadata function to improve performance and readability

This commit is contained in:
mauro-balades
2024-08-27 16:49:22 +02:00
parent 1cd4943053
commit fc96c2c257

View File

@@ -5,37 +5,6 @@ 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<Metadata> {
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();
return themes.map((theme) => ({