Files
heidi/lib/media/loader.mjs
CatoandClaude Opus 5.5 df3796b9b6 Photos that follow the theme, better openers, R2-ready media (#365)
* Photos: theme-aware scenes, and served from R2 with no image work on the box

- Scenes follow the theme the way Solon's do: a day photograph for light,
  an evening one of the same kind of place for dark where one is worth it,
  shown by CSS (lazy, neither preloaded when paired). The words stand on a
  veil of the theme's own page colour, ink >= 4.5:1 over any picture.
- New station pair (hall at eye level / against the light), the tram at
  the blue hour, a bakery without a label, a rowing club for the Verein;
  the Stadthaus courtyard with its art installation removed.
- lib/media/: fixed-width AVIF and WebP variants keyed by content hash,
  a manifest, and a next/image loader that is on only with
  NEXT_PUBLIC_MEDIA_BASE. scripts/media/ensure.mjs makes the deploy's build
  upload what the bucket lacks and turn the base on only after a probe;
  it never fails the build. Shaped like Solon's for the sitekit move.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

* Photos: the deploy's build uploads to R2 itself; restaurant and city pairs

- scripts/media/ensure.mjs runs first in `pnpm run build` when SELF_HOST=1:
  with PHOTOS_S3_* and MEDIA_PUBLIC_BASE it uploads only the variants the
  bucket lacks (one image at a time, sharp on one thread), probes one through
  the public base, and only then writes NEXT_PUBLIC_MEDIA_BASE into
  .env.production.local. Anything missing or failing: one line, local
  serving, exit 0. An explicit NEXT_PUBLIC_MEDIA_BASE is the override.
- Same widths, key scheme (photos/<name>.<hash12>/<w>.<fmt>), manifest
  shape and env names as Solon's src/lib/media/, for the sitekit move.
- Restaurant and the situations index: the guild houses on the Limmatquai
  by day and lit at night. The tram is the blue-hour Bahnhofstrasse in both
  themes, wearing the dark theme (scene-night). The old-town lane with a
  restaurant's name is gone; the city default is the Schipfe and the Limmat
  on a winter evening. Apéro and small talk open on the lake.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-26 13:53:47 +01:00

23 lines
1.1 KiB
JavaScript

/**
* next/image's loader while `NEXT_PUBLIC_MEDIA_BASE` is set (`images.loaderFile`
* in next.config.mjs, which switches it on then and only then; unset, Next's
* own optimiser runs as before). A photograph of the manifest is answered with
* its variant in the bucket at the nearest rendered width; any other address
* is used as it is, because with this loader the box has no optimiser.
* The default is WebP, which every browser draws; `avifLoader` is for a
* `<source type="image/avif">`. Shaped like Solon's `src/lib/media/loader.ts`.
*
* Not a client module: getImageProps calls it in server components too.
*/
import manifest from "./manifest.json" with { type: "json" };
import { createPhotoLoader } from "./variants.mjs";
const base = process.env.NEXT_PUBLIC_MEDIA_BASE;
/** The WebP variant: what every browser that draws the `<img>` gets. */
const webpLoader = createPhotoLoader({ manifest, base, format: "webp" });
export default webpLoader;
/** The AVIF variant, for `<source type="image/avif">`. */
export const avifLoader = createPhotoLoader({ manifest, base, format: "avif" });