Files
heidi/next.config.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

79 lines
3.5 KiB
JavaScript

import { execSync } from "node:child_process";
import { WIDTHS, mediaBase } from "./lib/media/variants.mjs";
/** Short commit SHA baked in at build time so /api/health can say which build is live. */
function commitSha() {
try {
return execSync("git rev-parse --short HEAD", { stdio: ["ignore", "pipe", "ignore"] }).toString().trim();
} catch {
return "unknown";
}
}
/**
* How photographs are served (`lib/media/variants.mjs`). With
* `NEXT_PUBLIC_MEDIA_BASE` set, `next/image` uses the custom loader, which
* spells the bucket's address of a variant rendered at build time
* (`lib/media/manifest.json`): the box does no image work, and its
* `/_next/image` answers 404 — which is why the loader is on ONLY with a
* base, never as a fallback. Unset, it is `next/image`'s own optimiser over
* the files in `public/photos`, as before. A `NEXT_PUBLIC_` variable is read
* when the site is built; on the box `scripts/media/ensure.mjs` sets it
* (in `.env.production.local`) once the bucket is known to serve every variant.
*/
export function imagesConfig(base = process.env.NEXT_PUBLIC_MEDIA_BASE) {
const shared = {
// 75 is the default; 85 is what a scene photograph is asked for at
// (`SCENE_QUALITY` in shared/scene.tsx). Next 16 refuses any quality
// not listed here. AVIF first: about half the bytes of WebP.
qualities: [75, 85],
formats: ["image/avif", "image/webp"],
};
// The widths the variants are rendered at, so each srcset entry names the width its file has.
return mediaBase(base) ? { ...shared, loader: "custom", loaderFile: "./lib/media/loader.mjs", deviceSizes: [...WIDTHS] } : shared;
}
/** @type {import('next').NextConfig} */
/** @type {import('next').NextConfig['redirects']} */
async function redirects() {
return [
{
// `/:locale/check` was a real, indexed page until the checker became
// evidence on the method page. Links to it exist in the wild and in
// Google's index, so it moves permanently rather than 404s — a retired
// URL that answers 404 throws away whatever standing it had.
// The locale is spelled out rather than left as `:locale`. A bare
// wildcard matches ANY first segment — including `api`, so `/api/check`
// 308'd to `/api/method` and the checker silently stopped working while
// the page around it still rendered perfectly. `lib/i18n/routes.test.ts`
// asserts this list equals LOCALES so the two cannot drift.
// Research merged into Method — the evidence is the argument FOR the
// method rather than a peer of it. It was indexed and cited, so it moves
// permanently and lands on the evidence section rather than the top.
source: "/:locale(de|gsw|fr|it|rm|en|ru)/research",
destination: "/:locale/method#facts",
permanent: true,
},
{
source: "/:locale(de|gsw|fr|it|rm|en|ru)/check",
destination: "/:locale/method",
permanent: true,
},
];
}
const nextConfig = {
redirects,
// The box's launch.sh looks for a server.js — see sync-infra.sh.
output: "standalone",
reactStrictMode: true,
// A URL that matches no route at all (a typo, a removed page, `/xx/…`) used
// to get Next's bare English «404 This page could not be found.» with no
// header and no way home, because the root layout lives under `[locale]`.
// See `app/global-not-found.tsx`.
experimental: { globalNotFound: true },
images: imagesConfig(),
env: { COMMIT_SHA: commitSha() },
};
export default nextConfig;