/** @jsxRuntime automatic */
/** @jsxImportSource remix/component */
import type { Action } from 'remix/router'
import { findGallery } from '../../src/domain/content.ts'
import { canonicalUrl, loadSite } from '../data/site.ts'
import { routes } from '../routes.ts'
import { icon } from '../ui/icons.tsx'
import { notFound } from '../ui/not-found.tsx'
import { ogImage } from '../ui/og-image.ts'
import { cameraDetails } from '../ui/photo-details.ts'
import { picture } from '../ui/picture.tsx'
import { render } from '../ui/render.tsx'
/** One photo on its own page: the shareable URL the lightbox shows, and the no-JavaScript view. */
export default {
async handler(context) {
const site = await loadSite(context)
const gallery = findGallery(site.content, context.params.slug ?? '')
const index =
gallery?.photos.findIndex((p) => p.id === context.params.photoId) ?? -1
if (!gallery || index < 0) return notFound(site, 'That photo')
const photo = gallery.photos[index]!
const previous = gallery.photos[index - 1]
const next = gallery.photos[index + 1]
const details = cameraDetails(site.content.config, photo)
return render(
site,
{
title:
photo.caption ??
`${gallery.title} (${index + 1} of ${gallery.photos.length})`,
description: photo.alt,
canonical: canonicalUrl(
site,
routes.photo.href({ slug: gallery.slug, photoId: photo.id }),
),
nav: 'galleries',
...ogImage(site, photo),
},
{icon('back')} {gallery.title}
{picture(site, photo, {
sizes: '(max-width: 1400px) 100vw, 1400px',
priority: true,
})}
{photo.caption ? (
{photo.caption}
) : null}
{details ? {details} : null}
{index + 1} / {gallery.photos.length}
,
)
},
} satisfies Action