This commit is contained in:
parent
b9fd569196
commit
fb6658eec5
@ -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 - name`,
|
||||
title: "Leaderboard not found",
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
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",
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user