feat: Refactor generateMetadata function to improve performance and readability
This commit is contained in:
@@ -5,37 +5,6 @@ import ThemePage from "@/components/theme-page";
|
|||||||
import { getAllThemes, getThemeFromId } from "@/lib/themes";
|
import { getAllThemes, getThemeFromId } from "@/lib/themes";
|
||||||
import { Metadata, ResolvingMetadata } from "next";
|
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() {
|
export async function generateStaticParams() {
|
||||||
const themes = await getAllThemes();
|
const themes = await getAllThemes();
|
||||||
return themes.map((theme) => ({
|
return themes.map((theme) => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user