Skip to content

Commit 206bb83

Browse files
committed
Fetch song information and return metadata for song page embeds
1 parent aa7ae8d commit 206bb83

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

web/src/app/(content)/song/[id]/page.tsx

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
1+
import { SongViewDtoType } from '@shared/validation/song/dto/types';
2+
import type { Metadata } from 'next';
3+
4+
import axios from '@web/src/lib/axios';
15
import { SongPage } from '@web/src/modules/song/components/SongPage';
26

3-
function Page({ params }: { params: { id: string } }) {
7+
interface SongPage {
8+
params: {
9+
id: string;
10+
};
11+
}
12+
13+
export async function generateMetadata({
14+
params,
15+
}: SongPage): Promise<Metadata> {
16+
let song;
17+
18+
try {
19+
const response = await axios.get<SongViewDtoType>(`/song/${params.id}`);
20+
song = response.data;
21+
} catch {
22+
return {
23+
title: 'Unknown song!',
24+
};
25+
}
26+
27+
return {
28+
title: song.title,
29+
description: song.description,
30+
openGraph: {
31+
images: [song.thumbnailUrl],
32+
},
33+
};
34+
}
35+
36+
function Page({ params }: SongPage) {
437
const { id } = params;
538

639
return <SongPage id={id} />;

0 commit comments

Comments
 (0)