import { Metadata } from 'next'; import Image from 'next/image'; import Link from 'next/link'; import { notFound } from 'next/navigation'; import { getArtwork, getArtworks, getAssetUrl, Artwork } from '@/lib/directus'; export const revalidate = 60; type Props = { params: Promise<{ slug: string }>; }; export async function generateMetadata({ params }: Props): Promise { const { slug } = await params; try { const artwork = await getArtwork(slug); if (!artwork) return { title: 'Artwork Not Found' }; return { title: artwork.title, description: artwork.description?.replace(/<[^>]*>/g, '').slice(0, 160) || `${artwork.title} by Katheryn Trenshaw`, openGraph: { images: artwork.image ? [getAssetUrl(artwork.image, { width: 1200, quality: 85 })] : undefined, }, }; } catch { return { title: 'Artwork Not Found' }; } } export async function generateStaticParams() { try { const artworks = await getArtworks({ status: 'published' }); return artworks.map((artwork) => ({ slug: String(artwork.slug || artwork.id), })); } catch { return []; } } export default async function ArtworkPage({ params }: Props) { const { slug } = await params; let artwork: Artwork; try { artwork = await getArtwork(slug); if (!artwork) notFound(); } catch { notFound(); } const imageUrl = getAssetUrl(artwork.image, { width: 1200, quality: 90 }); return (
{/* Breadcrumb */}
{/* Image */}
{artwork.image ? ( {artwork.title} ) : (
No image available
)}
{/* Details */}

{artwork.title}

{artwork.year && (

{artwork.year}

)}
{artwork.medium && (
Medium
{artwork.medium}
)} {artwork.dimensions && (
Dimensions
{artwork.dimensions}
)} {typeof artwork.series === 'object' && artwork.series?.name && (
Series
{artwork.series.name}
)}
{/* Price & Status */}
{artwork.status === 'sold' ? (
Sold

This artwork has found a new home. Contact us for similar works.

) : artwork.price ? (

${artwork.price.toLocaleString()}

) : (

Price on request

)}
{/* Description */} {artwork.description && (

About This Piece

)}
{/* Back to Gallery */}
Back to Gallery
); }