add embed for leaderboard
All checks were successful
deploy / deploy (push) Successful in 54s

This commit is contained in:
Lee 2023-10-28 18:08:01 +01:00
parent b9fd569196
commit fb6658eec5
2 changed files with 39 additions and 1 deletions

@ -1,4 +1,6 @@
import Leaderboard from "@/components/leaderboard/Leaderboard";
import { ScoreSaberAPI } from "@/utils/scoresaber/api";
import { formatTime } from "@/utils/timeUtils";
import { Metadata } from "next";
type Props = {
@ -8,8 +10,29 @@ type Props = {
export async function generateMetadata({
params: { id },
}: Props): Promise<Metadata> {
const leaderboard = await ScoreSaberAPI.fetchLeaderboardInfo(id);
if (!leaderboard) {
return {
title: "Leaderboard not found",
};
}
return {
title: `Leaderboard - name`,
title: `${leaderboard.songName}`,
description: `View the leaderboard for ${leaderboard.songName}.`,
openGraph: {
siteName: "ScoreSaber",
title: `${leaderboard.songName}`,
description: `View the leaderboard for ${leaderboard.songName}.
Song: ${leaderboard.songName} (${leaderboard.songSubName})
Mapper: ${leaderboard.levelAuthorName}
Total plays: ${leaderboard.plays}
Created: ${formatTime(new Date(leaderboard.createdDate))}
`,
},
twitter: {
card: "summary",
},
};
}

@ -59,3 +59,18 @@ export function formatMsToTime(ms: number) {
return hoursStr + minutesStr + secondsStr;
}
/**
* Formats a date to a human readable format
* eg: January 1, 2021
*
* @param date the date to format
* @returns the formatted date
*/
export function formatTime(date: Date) {
return date.toLocaleTimeString("en-US", {
day: "numeric",
month: "long",
year: "numeric",
});
}