Liam
52fea3da68
All checks were successful
Deploy App / docker (ubuntu-latest) (push) Successful in 3m25s
70 lines
1.2 KiB
TypeScript
70 lines
1.2 KiB
TypeScript
import { Metadata } from "next";
|
|
|
|
type Embed = {
|
|
/**
|
|
* The title of the embed.
|
|
*/
|
|
title: string;
|
|
|
|
/**
|
|
* The title of the embed.
|
|
*/
|
|
embedTitle?: string;
|
|
|
|
/**
|
|
* The description of the embed.
|
|
*/
|
|
description: string;
|
|
|
|
/**
|
|
* The image to show as the thumbmail.
|
|
*/
|
|
image?: string;
|
|
|
|
/**
|
|
* The type of the card.
|
|
*/
|
|
cardType?: "summary" | "summary_large_image";
|
|
};
|
|
|
|
/**
|
|
* Generates metadata for a embed.
|
|
*
|
|
* @param title the title of the embed
|
|
* @param embedTitle the title of the embed
|
|
* @param description the description of the embed
|
|
* @param image the image to show as the thumbmail
|
|
* @param cardType the type of the card
|
|
* @returns the metadata for the embed
|
|
*/
|
|
export function generateEmbed({ title, embedTitle, description, image, cardType }: Embed): Metadata {
|
|
// Fall back to the title
|
|
if (!embedTitle) {
|
|
embedTitle = title;
|
|
}
|
|
if (!cardType) {
|
|
cardType = "summary";
|
|
}
|
|
|
|
const metadata: Metadata = {
|
|
title: `${title}`,
|
|
openGraph: {
|
|
title: `${title}`,
|
|
description: description,
|
|
},
|
|
twitter: {
|
|
card: cardType,
|
|
},
|
|
};
|
|
|
|
if (image) {
|
|
metadata.openGraph!.images = [
|
|
{
|
|
url: image || "",
|
|
},
|
|
];
|
|
}
|
|
|
|
return metadata;
|
|
}
|