import Link from 'next/link'; import type { Post } from 'contentlayer/generated'; import { siteConfig } from '@/lib/config'; interface Props { current: Post; newer?: Post; older?: Post; } interface StationConfig { key: 'older' | 'current' | 'newer'; label: string; post?: Post; hint: string; rel?: 'prev' | 'next'; } export function PostStorylineNav({ current, newer, older }: Props) { const stations: StationConfig[] = [ { key: 'older', label: '上一站', post: older, hint: older ? `發表於 ${formatDate(older.published_at)}` : '沒有更早的文章', rel: 'prev' }, { key: 'current', label: '你在這裡', post: current, hint: current.published_at ? formatDate(current.published_at) : '草稿' }, { key: 'newer', label: '下一站', post: newer, hint: newer ? `發表於 ${formatDate(newer.published_at)}` : '還沒有新文章', rel: 'next' } ]; return ( ); } function Station({ station }: { station: StationConfig }) { const { post, label, hint, key, rel } = station; const isCurrent = key === 'current'; const base = `group flex flex-col gap-3 rounded-3xl px-4 py-5 transition duration-300 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-400/60 dark:focus-visible:ring-blue-300/70 ${ isCurrent ? 'bg-white/80 shadow-md ring-1 ring-blue-200/60 dark:bg-slate-900/80 dark:ring-blue-500/20' : 'bg-white/60 shadow-sm hover:-translate-y-0.5 hover:shadow-lg dark:bg-slate-900/70' }`; const circle = ( {label === '下一站' ? 'NEXT' : label === '上一站' ? 'PREV' : 'NOW'} ); if (!post) { return (
{circle}

{hint}

); } return (
{circle}
{label}

{post.title}

{hint} {label === '下一站' ? '→ 前往' : label === '上一站' ? '回顧 ←' : '正在閱讀'}
); } function formatDate(input?: string | Date) { if (!input) return ''; const date = input instanceof Date ? input : new Date(input); return date.toLocaleDateString(siteConfig.defaultLocale ?? 'zh-TW', { year: 'numeric', month: '2-digit', day: '2-digit' }); }