|
1 | | -import { STATIONS } from '@/lib/stations'; |
| 1 | +import type { Metadata } from 'next'; |
| 2 | +import { STATIONS, getStation } from '@/lib/stations'; |
| 3 | +import { BreadcrumbJsonLd } from 'next-seo'; |
2 | 4 | import StationDetailClient from './StationDetailClient'; |
3 | 5 |
|
| 6 | +const LINE_NAMES: Record<string, string> = { |
| 7 | + '1': '1호선', '2': '2호선', '3': '3호선', '4': '4호선', |
| 8 | + '5': '5호선', '6': '6호선', '7': '7호선', '8': '8호선', '9': '9호선', |
| 9 | + S: '우이신설선', |
| 10 | +}; |
| 11 | + |
| 12 | +function stationLabel(name: string): string { |
| 13 | + return name.endsWith('역') ? name : `${name}역`; |
| 14 | +} |
| 15 | + |
4 | 16 | export function generateStaticParams() { |
5 | 17 | return STATIONS.map((s) => ({ code: s.code })); |
6 | 18 | } |
7 | 19 |
|
| 20 | +export async function generateMetadata({ |
| 21 | + params, |
| 22 | +}: { |
| 23 | + params: Promise<{ code: string }>; |
| 24 | +}): Promise<Metadata> { |
| 25 | + const { code } = await params; |
| 26 | + const station = getStation(code); |
| 27 | + |
| 28 | + if (!station) { |
| 29 | + return { title: '존재하지 않는 역' }; |
| 30 | + } |
| 31 | + |
| 32 | + const lineText = station.lines.map((l) => LINE_NAMES[l] ?? `${l}호선`).join(' · '); |
| 33 | + const title = `${stationLabel(station.name)} 편의시설 현황`; |
| 34 | + const description = `${stationLabel(station.name)}(${lineText}) 엘리베이터, 에스컬레이터 등 교통약자 편의시설의 실시간 운행 상태를 확인하세요.`; |
| 35 | + |
| 36 | + return { |
| 37 | + title, |
| 38 | + description, |
| 39 | + alternates: { |
| 40 | + canonical: `/station/${code}/`, |
| 41 | + }, |
| 42 | + openGraph: { |
| 43 | + title: `${stationLabel(station.name)} 편의시설 현황 | 나들이`, |
| 44 | + description, |
| 45 | + url: `/station/${code}/`, |
| 46 | + }, |
| 47 | + }; |
| 48 | +} |
| 49 | + |
8 | 50 | export default async function StationPage({ params }: { params: Promise<{ code: string }> }) { |
9 | 51 | const { code } = await params; |
10 | | - return <StationDetailClient code={code} />; |
| 52 | + const station = getStation(code); |
| 53 | + const stationName = station?.name ?? code; |
| 54 | + |
| 55 | + return ( |
| 56 | + <> |
| 57 | + <BreadcrumbJsonLd |
| 58 | + items={[ |
| 59 | + { name: '홈', item: 'https://nadeuri.today/' }, |
| 60 | + { |
| 61 | + name: `${stationLabel(stationName)}`, |
| 62 | + item: `https://nadeuri.today/station/${code}/`, |
| 63 | + }, |
| 64 | + ]} |
| 65 | + /> |
| 66 | + <StationDetailClient code={code} /> |
| 67 | + </> |
| 68 | + ); |
11 | 69 | } |
0 commit comments