use the server preview from the api in the server route for embeds
All checks were successful
Deploy App / docker (ubuntu-latest) (push) Successful in 3m25s

This commit is contained in:
Lee 2024-04-22 20:15:56 +01:00
parent 4ffd10e9c3
commit 52fea3da68
4 changed files with 17 additions and 12 deletions

@ -33,7 +33,7 @@
"cmdk": "^1.0.0", "cmdk": "^1.0.0",
"fuse.js": "^7.0.0", "fuse.js": "^7.0.0",
"lucide-react": "^0.372.0", "lucide-react": "^0.372.0",
"mcutils-library": "^1.2.6", "mcutils-library": "^1.3.1",
"moment": "^2.30.1", "moment": "^2.30.1",
"next": "14.2.2", "next": "14.2.2",
"next-build-id": "^3.0.0", "next-build-id": "^3.0.0",

@ -81,7 +81,7 @@ dependencies:
specifier: ^0.372.0 specifier: ^0.372.0
version: 0.372.0(react@18.2.0) version: 0.372.0(react@18.2.0)
mcutils-library: mcutils-library:
specifier: ^1.2.6 specifier: ^1.3.1
version: 1.3.1(@babel/core@7.24.4)(@types/node@20.12.7) version: 1.3.1(@babel/core@7.24.4)(@types/node@20.12.7)
moment: moment:
specifier: ^2.30.1 specifier: ^2.30.1

@ -82,18 +82,14 @@ export async function generateMetadata({ params: { platform, hostname } }: Param
try { try {
const server = await getServer(platform, hostname); const server = await getServer(platform, hostname);
const { hostname: serverHostname, players } = server; const { hostname: serverHostname } = server;
const favicon = getFavicon(platform, server);
let description = `There is ${formatNumber(players.online)}/${formatNumber(players.max)} players connected!\n\n`;
description += "Click to view more information about the server.";
return generateEmbed({ return generateEmbed({
title: `${serverHostname} ${capitalizeFirstLetter(platform)} Server`, title: `${serverHostname} ${capitalizeFirstLetter(platform)} Server`,
embedTitle: `${capitalizeFirstLetter(platform)} Server: ${serverHostname}`, embedTitle: `${capitalizeFirstLetter(platform)} Server: ${serverHostname}`,
description: description, description: "Click to view more information about the server.",
image: favicon, image: `${config.apiEndpoint}/server/${platform}/preview/${serverHostname}`,
cardType: "summary_large_image",
}); });
} catch (err) { } catch (err) {
// An error occurred // An error occurred

@ -20,6 +20,11 @@ type Embed = {
* The image to show as the thumbmail. * The image to show as the thumbmail.
*/ */
image?: string; image?: string;
/**
* The type of the card.
*/
cardType?: "summary" | "summary_large_image";
}; };
/** /**
@ -29,13 +34,17 @@ type Embed = {
* @param embedTitle the title of the embed * @param embedTitle the title of the embed
* @param description the description of the embed * @param description the description of the embed
* @param image the image to show as the thumbmail * @param image the image to show as the thumbmail
* @param cardType the type of the card
* @returns the metadata for the embed * @returns the metadata for the embed
*/ */
export function generateEmbed({ title, embedTitle, description, image }: Embed): Metadata { export function generateEmbed({ title, embedTitle, description, image, cardType }: Embed): Metadata {
// Fall back to the title // Fall back to the title
if (!embedTitle) { if (!embedTitle) {
embedTitle = title; embedTitle = title;
} }
if (!cardType) {
cardType = "summary";
}
const metadata: Metadata = { const metadata: Metadata = {
title: `${title}`, title: `${title}`,
@ -44,7 +53,7 @@ export function generateEmbed({ title, embedTitle, description, image }: Embed):
description: description, description: description,
}, },
twitter: { twitter: {
card: "summary", card: cardType,
}, },
}; };