Finish the audit leftovers

- One mediaUrl in media.ts instead of 12 identical aliases and a
  kind map; orgPath builds on hrefs.ts's orgHref
- One Logo component (hides itself or shows a fallback when the file
  is missing) for event cards, org lists and chapter marks
- useHistory is a thin wrapper over useRecord
- adminSchema.ts split into adminSchema/, one file per entity plus
  shared.ts; the registry is unchanged (checked by loading both)
- JS smooth scrolls respect reduced motion (lib/motion.ts)
- Content-Security-Policy in Report-Only, with /api/csp-report logging
  what it would block

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-28 22:49:07 -05:00
parent c74ad746f5
commit e4a9c96f7e
42 changed files with 1968 additions and 2043 deletions

View file

@ -22,7 +22,7 @@ import PageShell from '../components/PageShell.tsx'
import PageState from '../components/PageState.tsx'
import { useAward, type Recipient } from '../lib/useContent.ts'
import { eventHref, orgHref, personHref } from '../lib/hrefs.ts'
import { awardLogo, initials, personPhoto } from '../lib/media.ts'
import { mediaUrl, initials } from '../lib/media.ts'
import { accentText } from '../lib/color.ts'
const TEAL = '#0f7183'
@ -47,7 +47,7 @@ export default function AwardDetail() {
}
const accent = TEAL
const logo = awardLogo(award.logo)
const logo = mediaUrl(award.logo)
return (
<PageShell
@ -105,7 +105,7 @@ export default function AwardDetail() {
}
function RecipientRow({ recipient, accent }: { recipient: Recipient; accent: string }) {
const photo = personPhoto(recipient.photo)
const photo = mediaUrl(recipient.photo)
return (
<div className="flex gap-5">

View file

@ -16,7 +16,7 @@ import PageShell, { type ShellSection } from '../components/PageShell.tsx'
import PageState from '../components/PageState.tsx'
import ContentBlocks from '../components/ContentBlocks.tsx'
import PeopleTiles from '../components/PeopleTiles.tsx'
import { blogImage, personPhoto } from '../lib/media.ts'
import { mediaUrl } from '../lib/media.ts'
import { postDate, useBlogPost } from '../lib/useBlog.ts'
import { accentText } from '../lib/color.ts'
@ -45,7 +45,7 @@ export default function BlogPost() {
}
const date = postDate(post.published_on)
const cover = blogImage(post.cover_image)
const cover = mediaUrl(post.cover_image)
const byline = [
...post.authors.map((author) => author.name),
...(post.guest ? [post.guest.name] : []),
@ -57,9 +57,9 @@ export default function BlogPost() {
name: author.name,
tagline: author.tagline,
pronouns: author.pronouns,
photo: personPhoto(author.photo),
photo: mediaUrl(author.photo),
})),
...(post.guest ? [{ name: post.guest.name, title: 'Guest author', photo: blogImage(post.guest.photo) }] : []),
...(post.guest ? [{ name: post.guest.name, title: 'Guest author', photo: mediaUrl(post.guest.photo) }] : []),
]
const sections: ShellSection[] = [

View file

@ -30,7 +30,7 @@ import {
type EventRecord,
} from '../lib/useContent.ts'
import { awardHref, personHref, refHref } from '../lib/hrefs.ts'
import { personPhoto } from '../lib/media.ts'
import { mediaUrl } from '../lib/media.ts'
import { eventTypeLabel } from '../lib/eventTypes.ts'
import { occurrenceLabel, seriesLabel, seriesTimes, upcomingOccurrences } from '../lib/eventSeries.ts'
import { capitalize } from '../lib/text.ts'
@ -395,7 +395,7 @@ function peopleGroups(people: EventPerson[], accent: string): PeopleGroupInput[]
pronouns: person.pronouns,
// PeopleTiles resolves a bare filename itself; this is here
// so a hand-written entry elsewhere can't diverge.
photo: personPhoto(person.photo),
photo: mediaUrl(person.photo),
})),
}))
}

View file

@ -30,8 +30,9 @@ import {
type OrganizationRecord,
} from '../lib/useContent.ts'
import { orgHref, orgListHref, teamHref } from '../lib/hrefs.ts'
import { orgLogo, personPhoto } from '../lib/media.ts'
import { withAlpha, accentText } from '../lib/color.ts'
import { initials, mediaUrl } from '../lib/media.ts'
import Logo from '../components/Logo.tsx'
import { withAlpha, accentText, readableOn } from '../lib/color.ts'
const TEAL = '#0f7183'
const BODY = 'var(--color-muted)'
@ -147,7 +148,7 @@ export default function OrganizationDetail() {
title: leader.title,
pronouns: leader.pronouns,
public_email: leader.public_email,
photo: personPhoto(leader.photo),
photo: mediaUrl(leader.photo),
is_owner: leader.is_owner,
}))}
/>
@ -179,7 +180,7 @@ export default function OrganizationDetail() {
className="flex items-center gap-4 rounded-lg border p-4 transition-colors hover:bg-tint"
style={{ borderColor: `${withAlpha(accent, 25)}` }}
>
<Logo file={chapter.logo} name={chapter.name} accent={accent} />
<ChapterMark file={chapter.logo} name={chapter.name} accent={accent} />
<span>
<span className="block font-semibold" style={{ color: accentText(accent) }}>
{chapter.name}
@ -359,28 +360,22 @@ function Contact({ org, accent }: { org: OrganizationRecord; accent: string }) {
)
}
function Logo({
file,
name,
accent,
}: {
file?: string | null
name: string
accent: string
}) {
const src = orgLogo(file)
if (!src) {
return (
<span
aria-hidden="true"
className="flex h-10 w-10 shrink-0 items-center justify-center rounded-full text-xs font-bold text-white"
style={{ background: accent }}
>
{name.slice(0, 2).toUpperCase()}
</span>
)
}
return <img src={src} alt="" loading="lazy" className="h-10 w-10 shrink-0 object-contain" />
function ChapterMark({ file, name, accent }: { file?: string | null; name: string; accent: string }) {
return (
<Logo
src={mediaUrl(file)}
className="h-10 w-10 shrink-0 object-contain"
fallback={
<span
aria-hidden="true"
className="flex h-10 w-10 shrink-0 items-center justify-center rounded-full text-xs font-bold"
style={{ background: accent, color: readableOn(accent) }}
>
{initials(name)}
</span>
}
/>
)
}
/* ── Leadership → team blocks ────────────────────────────────── */

View file

@ -31,7 +31,7 @@ import {
type PersonRole,
} from '../lib/useContent.ts'
import { awardHref, eventHref, orgHref, teamHref } from '../lib/hrefs.ts'
import { initials, personPhoto } from '../lib/media.ts'
import { mediaUrl, initials } from '../lib/media.ts'
import { eventTypeLabel } from '../lib/eventTypes.ts'
import { capitalize } from '../lib/text.ts'
import { accentText } from '../lib/color.ts'
@ -199,7 +199,7 @@ export default function PersonDetail() {
/* ── The strip of facts under the heading ────────────────────── */
function Facts({ person, accent }: { person: PersonRecord; accent: string }) {
const photo = personPhoto(person.photo)
const photo = mediaUrl(person.photo)
return (
<div className="flex flex-wrap items-center gap-x-6 gap-y-3 text-sm">

View file

@ -20,7 +20,7 @@ import { Link } from 'react-router-dom'
import FeaturedCards from '../../components/FeaturedCards.tsx'
import PlatformIcon from '../../components/PlatformIcon.tsx'
import { blogHref } from '../../lib/hrefs.ts'
import { blogImage } from '../../lib/media.ts'
import { mediaUrl } from '../../lib/media.ts'
import { preview } from '../../lib/text.ts'
import { postDate, useCommunityBlog, type BlogPostSummary } from '../../lib/useBlog.ts'
import HomeLink from './home/HomeLink.tsx'
@ -36,7 +36,7 @@ const DEFAULTS = {
const EXCERPT_CHARS = 180
function PostCard({ post, accent }: { post: BlogPostSummary; accent: string }) {
const cover = blogImage(post.cover_image)
const cover = mediaUrl(post.cover_image)
const date = postDate(post.published_on)
const authors = post.authors.map((author) => author.name).join(', ')

View file

@ -5,7 +5,8 @@ import { eventHref } from "../../lib/hrefs.ts";
import { EVENT_TYPES, eventTypeLabel } from "../../lib/eventTypes.ts";
import { seriesLabel } from "../../lib/eventSeries.ts";
import PlatformIcon from "../../components/PlatformIcon.tsx";
import { eventBackground, eventLogo as eventLogoSrc, orgLogo as orgLogoSrc } from "../../lib/media.ts";
import { mediaUrl } from "../../lib/media.ts";
import Logo from "../../components/Logo.tsx";
import { accentText, withAlpha, readableOn } from '../../lib/color.ts'
/* ═══════════════════════════════════════════════════════════════
@ -34,22 +35,6 @@ import { accentText, withAlpha, readableOn } from '../../lib/color.ts'
fires only for an event with no host at all. */
const DEFAULT_ORG_LOGO = null;
/* An <img> that removes itself if the file 404s. `src` is already
resolved by media.ts: a bare filename from the uploads directory,
anything with a path or URL as it is. */
function Logo({ src, alt = "", className }) {
const [failed, setFailed] = useState(false);
if (!src || failed) return null;
return (
<img
src={src}
alt={alt}
className={className}
onError={() => setFailed(true)}
/>
);
}
const TEAL = "#0f7183"; // last-resort card color
const INK = "var(--color-ink)"; // button text: the card colour is only a border
const CARD_BG = "var(--color-surface)"; // sits under every card, photo or not
@ -64,7 +49,7 @@ const CARD_IMAGE_VEIL =
has one, then the plain surface. */
function cardBackground(ev) {
const layers: string[] = [];
const image = eventBackground(ev.card_image);
const image = mediaUrl(ev.card_image);
if (image) {
layers.push(CARD_IMAGE_VEIL, `url(${JSON.stringify(image)}) center / cover no-repeat`);
}
@ -155,8 +140,8 @@ export function Card({
}) {
const past = ev.status === "past";
const color = ev.color || defaultColor;
const orgLogo = orgLogoSrc(ev.org_logo) || DEFAULT_ORG_LOGO;
const eventLogo = eventLogoSrc(ev.event_logo);
const orgLogo = mediaUrl(ev.org_logo) || DEFAULT_ORG_LOGO;
const eventLogo = mediaUrl(ev.event_logo);
const schedule = seriesLabel(ev.series, ev.starts_on);
const links = ev.links ?? [];
const igHandle = ev.instagram || null;

View file

@ -1,6 +1,6 @@
import { useState } from "react";
import ArrowLink from "../../components/ArrowLink.tsx";
import { orgLogo } from "../../lib/media.ts";
import { mediaUrl } from "../../lib/media.ts";
import Logo from "../../components/Logo.tsx";
import {
initialsFor,
orgPath,
@ -35,27 +35,20 @@ const CARD_MIN = "20rem";
const GRID_MAX = "88rem";
function OrgMark({ org, color }) {
const [failed, setFailed] = useState(false);
if (org.logo && !failed) {
return (
<img
src={orgLogo(org.logo) ?? undefined}
alt=""
onError={() => setFailed(true)}
className="h-14 w-14 object-contain rounded-xl shrink-0"
/>
);
}
return (
<span
className="h-14 w-14 rounded-xl shrink-0 flex items-center justify-center font-extrabold"
style={{ border: `1px solid ${color}`, color }}
aria-hidden="true"
>
{initialsFor(org.name)}
</span>
<Logo
src={mediaUrl(org.logo)}
className="h-14 w-14 object-contain rounded-xl shrink-0"
fallback={
<span
className="h-14 w-14 rounded-xl shrink-0 flex items-center justify-center font-extrabold"
style={{ border: `1px solid ${color}`, color: accentText(color) }}
aria-hidden="true"
>
{initialsFor(org.name)}
</span>
}
/>
);
}

View file

@ -2,10 +2,11 @@ import { useEffect, useRef, useState } from "react";
import { useCommunity } from "../../lib/chapters.ts";
import { Link } from "react-router-dom";
import ArrowLink from "../../components/ArrowLink.tsx";
import { orgLogo } from "../../lib/media.ts";
import { mediaUrl } from "../../lib/media.ts";
import { initialsFor, orgPath } from "../../lib/organizations.ts";
import { AREAS, AREA_NAMES } from "../../data/mapGrid.ts";
import { withAlpha, accentText, readableOn } from '../../lib/color.ts'
import { scrollBehavior } from "../../lib/motion.ts";
/* ═══════════════════════════════════════════════════════════════
ORGANIZATION LIST: MAP
@ -472,7 +473,7 @@ function OrgLogo({ org, color, size = "h-14 w-14" }) {
if (org.logo && !failed) {
return (
<img
src={orgLogo(org.logo) ?? undefined}
src={mediaUrl(org.logo) ?? undefined}
alt={org.name}
onError={() => setFailed(true)}
className={`${size} object-contain rounded-xl shrink-0`}
@ -798,7 +799,7 @@ export default function OrgListMap({ view = "map", accent = FALLBACK_COLOR }) {
// that it's stacked under the map and scrolling it would fight
// the page.
if (box.scrollHeight <= box.clientHeight) return;
box.scrollTo({ top: el.offsetTop - 8, behavior: "smooth" });
box.scrollTo({ top: el.offsetTop - 8, behavior: scrollBehavior() });
};
// Hovering or selecting a region on the map or legend brings its

View file

@ -1,6 +1,7 @@
import { useId, useState } from "react";
import ArrowLink from "../../components/ArrowLink.tsx";
import { orgLogo } from "../../lib/media.ts";
import { mediaUrl } from "../../lib/media.ts";
import Logo from "../../components/Logo.tsx";
import PlatformIcon from "../../components/PlatformIcon.tsx";
import {
areasSentence,
@ -62,38 +63,18 @@ function RowButton({ as: As = "button", color, children, ...rest }: any) {
}
function OrgMark({ org, color }) {
const [failed, setFailed] = useState(false);
if (org.logo && !failed) {
return (
<img
src={orgLogo(org.logo) ?? undefined}
alt=""
onError={() => setFailed(true)}
className="h-8 w-8 object-contain shrink-0"
/>
);
}
if (org.color) {
return (
<span
className="h-3 w-3 rounded-full shrink-0"
style={{ background: color }}
aria-hidden="true"
/>
);
}
return (
const fallback = org.color ? (
<span className="h-3 w-3 rounded-full shrink-0" style={{ background: color }} aria-hidden="true" />
) : (
<span
className="h-8 w-8 rounded-lg shrink-0 flex items-center justify-center text-xs font-extrabold"
style={{ border: `1px solid ${color}`, color }}
style={{ border: `1px solid ${color}`, color: accentText(color) }}
aria-hidden="true"
>
{initialsFor(org.name)}
</span>
);
return <Logo src={mediaUrl(org.logo)} className="h-8 w-8 object-contain shrink-0" fallback={fallback} />;
}
function OrgRow({ org, pageLabel, siteLabel }) {

View file

@ -1,7 +1,7 @@
import { Link } from 'react-router-dom'
import { MONTH_LABELS, type PersonRef, type TimelineItem } from '../../../lib/timeline.ts'
import { hrefFor, logoSrc, photoSrc } from '../../../lib/timelineRefs.ts'
import { initials } from '../../../lib/media.ts'
import { hrefFor, logoSrc } from '../../../lib/timelineRefs.ts'
import { initials, mediaUrl } from '../../../lib/media.ts'
const KIND_NAMES: Record<TimelineItem['kind'], string> = {
milestone: 'Milestone',
@ -28,7 +28,7 @@ function fullMarker(item: TimelineItem): string {
}
function PersonChip({ person }: { person: PersonRef }) {
const src = photoSrc(person.photo)
const src = mediaUrl(person.photo)
return (
<li className="ngu-tl__person">
{src ? (

View file

@ -27,6 +27,7 @@ import { useHistory } from '../../../lib/useHistory.ts'
import { hrefFor, logoSrc } from '../../../lib/timelineRefs.ts'
import { MONTH_LABELS, type TimelineItem } from '../../../lib/timeline.ts'
import { accentText } from '../../../lib/color.ts'
import { scrollBehavior } from '../../../lib/motion.ts';
const TEAL = '#0f7183'
const DRAG_SLOP = 6
@ -49,7 +50,7 @@ export default function FeaturedTimelineRail({ id, title, blurb }: RailProps) {
const rail = railRef.current
const card = rail?.querySelector('li')
if (!rail || !card) return
rail.scrollBy({ left: direction * (card.clientWidth + 24), behavior: 'smooth' })
rail.scrollBy({ left: direction * (card.clientWidth + 24), behavior: scrollBehavior() })
}
const onPointerDown = (e: ReactPointerEvent<HTMLOListElement>) => {

View file

@ -44,7 +44,7 @@ import VideoPlayer from '../../../components/VideoPlayer.tsx'
import DoveMark from '../../../components/DoveMark.tsx'
import PlatformIcon from '../../../components/PlatformIcon.tsx'
import { livestreamEmbedUrl, videoSource, type VideoSource } from '../../../lib/embeds.ts'
import { eventBackground, heroPhoto } from '../../../lib/media.ts'
import { mediaUrl } from '../../../lib/media.ts'
import { eventHref } from '../../../lib/hrefs.ts'
import { seriesLabel } from '../../../lib/eventSeries.ts'
import type { Hero, HeroBackdrop, HeroEvent, HeroFeature, HeroSlide } from '../../../lib/useFrontPage.ts'
@ -53,7 +53,7 @@ import { withAlpha } from '../../../lib/color.ts'
const DEEP = '#04262e'
export default function HeroStage({ hero }: { hero: Hero | null }) {
const slides = (hero?.slides ?? []).filter((slide) => heroPhoto(slide.media))
const slides = (hero?.slides ?? []).filter((slide) => mediaUrl(slide.media))
const embed = livestreamEmbedUrl(hero?.livestream?.url)
const video = videoSource(hero?.video?.url)
@ -290,7 +290,7 @@ function PhotoBackdrop({ slides, seconds }: { slides: HeroSlide[]; seconds: numb
className={`hp-slide ${i === index ? 'hp-slide--on' : ''}`}
aria-hidden={i !== index}
>
<img src={heroPhoto(slide.media) ?? ''} alt={slide.alt ?? ''} loading={i === 0 ? 'eager' : 'lazy'} />
<img src={mediaUrl(slide.media) ?? ''} alt={slide.alt ?? ''} loading={i === 0 ? 'eager' : 'lazy'} />
</div>
))}
<div
@ -455,7 +455,7 @@ function VideoFrame({
it's usually Register. */
function EventPanel({ event }: { event: HeroEvent }) {
const color = event.color || '#0f7183'
const photo = eventBackground(event.card_image)
const photo = mediaUrl(event.card_image)
const when = seriesLabel(event.series, event.starts_on) ?? event.date_label
const where = event.is_online && !event.location_label ? 'Online' : event.location_label