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

@ -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