|
1 | 1 | import { getMusicList } from "../music"; |
2 | 2 | import { notFound } from "next/navigation"; |
3 | 3 | import { Player } from "./components/player"; |
4 | | - |
| 4 | +import { Metadata } from "next"; |
5 | 5 | export function generateStaticParams() { |
6 | 6 | const musicList = getMusicList(); |
7 | 7 | return musicList.map((music) => ({ |
8 | 8 | music_id: music.id, |
9 | 9 | })); |
10 | 10 | } |
| 11 | +export async function generateMetadata({ |
| 12 | + params, |
| 13 | +}: { |
| 14 | + params: Promise<{ music_id: string; }>; |
| 15 | +}): Promise<Metadata> { |
| 16 | + const resolvedParams = await params; |
| 17 | + const musicList = getMusicList(); |
| 18 | + const music = musicList.find((m) => m.id === resolvedParams.music_id); |
| 19 | + if (!music) { |
| 20 | + notFound(); |
| 21 | + } |
| 22 | + // 1. paramsからslugを再構築 |
| 23 | + const slug = `music/${resolvedParams.music_id}`; |
| 24 | + const title = music.title; |
| 25 | + const artist = music.artist; |
| 26 | + const fullTitle = `${title} | by ${artist}`; // 例: "Next.jsでメタデータを生成する | あなたのサイト名" |
| 27 | + const description = "Music: ${title}"; |
| 28 | + const og_image_url = `${slug}/${music.jacketUrl?.split("/").slice(-1)[0]}`; |
| 29 | + const metadata: Metadata = { |
| 30 | + metadataBase: new URL(process.env.BASE_URL || "https://the-infinitys.f5.si"), |
| 31 | + title: fullTitle, // ページのタイトルを設定 |
| 32 | + description: description, // ページのディスクリプションを設定 |
| 33 | + alternates: { |
| 34 | + canonical: `/${slug}`, // |
| 35 | + }, |
| 36 | + // Open Graph メタデータ (SNS共有時に表示される情報) |
| 37 | + openGraph: { |
| 38 | + title: fullTitle, |
| 39 | + description: description, |
| 40 | + url: `/${slug}`, // 絶対URLが推奨 |
| 41 | + type: 'music.song', // コンテンツタイプを記事に設定 |
| 42 | + // 記事に画像がある場合は、imagesプロパティを追加 |
| 43 | + images: [og_image_url || ""], |
| 44 | + } |
| 45 | + }; |
| 46 | + return metadata; |
| 47 | +} |
11 | 48 |
|
12 | 49 | export default async function MusicPage({ |
13 | 50 | params, |
|
0 commit comments