feat(website): photos upright, without metadata, in responsive sizes
Every upload is turned upright, stripped of its metadata (EXIF, GPS), kept at most 2400 px wide and saved at 480/960/1600 px in WebP and JPEG; the pages pick the size with <picture> and srcset. Every file counts towards storage; a photo that can't be read is refused. sharp 0.35 (prebuilt, no build step on the servers). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,7 @@ import { TEMPLATE_FONT_PAIRINGS, type Church, type CrosscodeEvent, type WebsiteT
|
||||
import type { Ctx } from '../context.js';
|
||||
import { churchProfile } from '../church/profile.js';
|
||||
import { buildPalette, type Palette } from './palette.js';
|
||||
import { buildSnapshot, mediaUrl, publishedSnapshot, type Image, type Snapshot } from './snapshot.js';
|
||||
import { buildSnapshot, imageOf, publishedSnapshot, type Image, type Snapshot } from './snapshot.js';
|
||||
import { headerIsTransparent, TEMPLATE_STYLE, type Variant } from './variants.js';
|
||||
|
||||
export type SiteEvent = {
|
||||
@@ -112,7 +112,7 @@ async function liveEvents(ctx: Ctx): Promise<SiteEvent[]> {
|
||||
]);
|
||||
const image = (id: string | null) => {
|
||||
const m = id ? media.find((x) => x.id === id) : null;
|
||||
return m ? { url: mediaUrl(m.filename), alt: m.alt, width: m.width, height: m.height } : null;
|
||||
return m ? imageOf(m) : null;
|
||||
};
|
||||
const own: SiteEvent[] = simple.map((e) => ({
|
||||
title: e.title, summary: e.description ? e.description.slice(0, 200) : null, startsAt: e.startsAt.toISOString(), endsAt: e.endsAt?.toISOString() ?? null,
|
||||
|
||||
@@ -15,7 +15,10 @@ import { defaultDesign, isVariant, SECTION_TYPES, type SectionType, type SiteDes
|
||||
|
||||
export const SNAPSHOT_VERSION = 1;
|
||||
|
||||
export type Image = { url: string; alt: string; width: number | null; height: number | null };
|
||||
/** An image to show: the photo, and its responsive sizes as `srcset`s when it has them (§3). */
|
||||
export type Image = { url: string; alt: string; width: number | null; height: number | null; srcset?: { webp: string; jpg: string } };
|
||||
|
||||
type MediaRow = { id: string; filename: string; alt: string; width: number | null; height: number | null; sizes?: unknown };
|
||||
|
||||
export type SnapshotSection = { type: string; variant: string | null; data: Record<string, unknown> };
|
||||
|
||||
@@ -47,6 +50,18 @@ export type Snapshot = {
|
||||
|
||||
export const mediaUrl = (filename: string) => `/api/uploads/${filename.split('/').map(encodeURIComponent).join('/')}`;
|
||||
|
||||
/** A media row as an Image, with `srcset`s from its sizes and the photo itself as the widest. */
|
||||
export function imageOf(m: MediaRow): Image {
|
||||
const img: Image = { url: mediaUrl(m.filename), alt: m.alt, width: m.width, height: m.height };
|
||||
const sizes = Array.isArray(m.sizes) ? (m.sizes as { w: number; webp: string; jpg: string }[]) : [];
|
||||
if (sizes.length && m.width) {
|
||||
const dir = m.filename.includes('/') ? m.filename.slice(0, m.filename.lastIndexOf('/') + 1) : '';
|
||||
const set = (key: 'webp' | 'jpg') => [...sizes.map((x) => `${mediaUrl(dir + x[key])} ${x.w}w`), `${img.url} ${m.width}w`].join(', ');
|
||||
img.srcset = { webp: set('webp'), jpg: set('jpg') };
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
/** The design as saved, made safe: an unknown template, variant or section falls back to the default. */
|
||||
export function cleanDesign(saved: { template: string; variants: unknown; home: unknown; style: unknown } | null): SiteDesign {
|
||||
const template: WebsiteTemplate = saved && (WEBSITE_TEMPLATES as readonly string[]).includes(saved.template) ? (saved.template as WebsiteTemplate) : 'heritage';
|
||||
@@ -107,8 +122,8 @@ export async function buildSnapshot(ctx: Ctx): Promise<Snapshot> {
|
||||
return snapshotFrom(toSource(w), media);
|
||||
}
|
||||
|
||||
export function snapshotFrom(source: Source, media: { id: string; filename: string; alt: string; width: number | null; height: number | null }[]): Snapshot {
|
||||
const images = new Map(media.map((m) => [m.id, { url: mediaUrl(m.filename), alt: m.alt, width: m.width, height: m.height } satisfies Image]));
|
||||
export function snapshotFrom(source: Source, media: MediaRow[]): Snapshot {
|
||||
const images = new Map(media.map((m) => [m.id, imageOf(m)]));
|
||||
const image = (id: string | null | undefined) => (id ? images.get(id) ?? null : null);
|
||||
const used: Record<string, Image> = {};
|
||||
const collect = (data: unknown) => {
|
||||
|
||||
Reference in New Issue
Block a user