Frontend/src/common/embed.ts

38 lines
685 B
TypeScript
Raw Normal View History

2024-04-16 17:14:15 +00:00
import { Metadata } from "next";
type Embed = {
title: string;
description: string;
image?: string | null;
};
/**
* Generates metadata for a embed.
*
* @param title the title of the embed
* @param description the description of the embed
* @returns the metadata for the embed
*/
export function generateEmbed({ title, description, image }: Embed): Metadata {
const metadata: Metadata = {
title: `${title}`,
openGraph: {
title: `${title}`,
description: description,
},
twitter: {
card: "summary",
},
};
if (image) {
metadata.openGraph!.images = [
{
url: image || "",
},
];
}
return metadata;
}