2024-04-16 17:14:15 +00:00
|
|
|
import { Metadata } from "next";
|
|
|
|
|
|
|
|
type Embed = {
|
2024-04-18 06:28:59 +00:00
|
|
|
/**
|
|
|
|
* The title of the embed.
|
|
|
|
*/
|
2024-04-16 17:14:15 +00:00
|
|
|
title: string;
|
2024-04-18 06:28:59 +00:00
|
|
|
|
2024-04-19 23:34:42 +00:00
|
|
|
/**
|
|
|
|
* The title of the embed.
|
|
|
|
*/
|
|
|
|
embedTitle?: string;
|
|
|
|
|
2024-04-18 06:28:59 +00:00
|
|
|
/**
|
|
|
|
* The description of the embed.
|
|
|
|
*/
|
2024-04-16 17:14:15 +00:00
|
|
|
description: string;
|
2024-04-18 06:28:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The image to show as the thumbmail.
|
|
|
|
*/
|
|
|
|
image?: string;
|
2024-04-16 17:14:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates metadata for a embed.
|
|
|
|
*
|
|
|
|
* @param title the title of the embed
|
2024-04-19 23:34:42 +00:00
|
|
|
* @param embedTitle the title of the embed
|
2024-04-16 17:14:15 +00:00
|
|
|
* @param description the description of the embed
|
2024-04-19 23:34:42 +00:00
|
|
|
* @param image the image to show as the thumbmail
|
2024-04-16 17:14:15 +00:00
|
|
|
* @returns the metadata for the embed
|
|
|
|
*/
|
2024-04-19 23:34:42 +00:00
|
|
|
export function generateEmbed({ title, embedTitle, description, image }: Embed): Metadata {
|
|
|
|
// Fall back to the title
|
|
|
|
if (!embedTitle) {
|
|
|
|
embedTitle = title;
|
|
|
|
}
|
|
|
|
|
2024-04-16 17:14:15 +00:00
|
|
|
const metadata: Metadata = {
|
|
|
|
title: `${title}`,
|
|
|
|
openGraph: {
|
|
|
|
title: `${title}`,
|
|
|
|
description: description,
|
|
|
|
},
|
|
|
|
twitter: {
|
|
|
|
card: "summary",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (image) {
|
|
|
|
metadata.openGraph!.images = [
|
|
|
|
{
|
|
|
|
url: image || "",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return metadata;
|
|
|
|
}
|