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

@ -33,7 +33,7 @@
visible even if the renderer hasn't caught up with it.
═══════════════════════════════════════════════════════════════ */
import { blockMedia } from '../lib/media.ts'
import { mediaUrl } from '../lib/media.ts'
import type { ContentBlock } from '../lib/useContent.ts'
import { Anchor, Inline, Paragraphs } from './InlineText.tsx'
import VideoPlayer from './VideoPlayer.tsx'
@ -170,7 +170,7 @@ function Block({ block, accent }: { block: ContentBlock; accent: string }) {
)
case 'image': {
const src = blockMedia(block.media)
const src = mediaUrl(block.media)
if (!src) return null
const img = (
<img
@ -196,7 +196,7 @@ function Block({ block, accent }: { block: ContentBlock; accent: string }) {
return (
<figure>
<div className="overflow-hidden rounded-lg">
<VideoPlayer url={block.href} still={blockMedia(block.media)} title={text || null} />
<VideoPlayer url={block.href} still={mediaUrl(block.media)} title={text || null} />
</div>
<Caption text={text} />
</figure>

View file

@ -23,7 +23,7 @@ import { useState } from 'react'
import HomeLink from '../pages/sections/home/HomeLink.tsx'
import VideoPlayer from './VideoPlayer.tsx'
import { refHref } from '../lib/hrefs.ts'
import { logoForKind } from '../lib/media.ts'
import { mediaUrl } from '../lib/media.ts'
import type { FeaturedCard } from '../lib/useFrontPage.ts'
/* Image kinds that are photographs, drawn edge to edge. Anything
@ -39,7 +39,7 @@ function hrefFor(card: FeaturedCard): string | null {
function Picture({ card }: { card: FeaturedCard }) {
const [failed, setFailed] = useState(false)
const src = card.image ? logoForKind(card.image.kind, card.image.file) : null
const src = card.image ? mediaUrl(card.image.file) : null
const photo = card.image ? PHOTO_KINDS.has(card.image.kind) : false
if (!src || failed) {
@ -68,7 +68,7 @@ function Picture({ card }: { card: FeaturedCard }) {
}
function VideoPicture({ card }: { card: FeaturedCard }) {
const own = card.image ? logoForKind(card.image.kind, card.image.file) : null
const own = card.image ? mediaUrl(card.image.file) : null
return <VideoPlayer url={card.url} still={own} title={card.title} />
}

View file

@ -6,6 +6,7 @@ import nguLogo from "../assets/logos/NGU_Logo.svg";
import Footer from "./Footer.tsx";
import PrivacyNotice from "./PrivacyNotice.tsx";
import ThemeToggle from "./ThemeToggle.tsx";
import { scrollBehavior } from "../lib/motion.ts";
/* ── Right-side nav actions ──────────────────────────────── */
@ -117,7 +118,7 @@ export default function Layout() {
if (location.hash) {
const el = document.querySelector(location.hash);
if (el) {
el.scrollIntoView({ behavior: "smooth" });
el.scrollIntoView({ behavior: scrollBehavior() });
return;
}
}

27
src/components/Logo.tsx Normal file
View file

@ -0,0 +1,27 @@
/* ═══════════════════════════════════════════════════════════════
LOGO
An <img> for a logo or mark that may not exist: no src, or a file
that 404s, and it draws `fallback` instead (initials, a colour dot,
or nothing). `src` is already resolved (mediaUrl in media.ts).
Decorative by default (alt ""), since a logo sits next to the
name it stands for.
═══════════════════════════════════════════════════════════════ */
import { useState, type ReactNode } from 'react'
export default function Logo({
src,
alt = '',
className,
fallback = null,
}: {
src?: string | null
alt?: string
className?: string
fallback?: ReactNode
}) {
const [failed, setFailed] = useState(false)
if (!src || failed) return <>{fallback}</>
return <img src={src} alt={alt} loading="lazy" className={className} onError={() => setFailed(true)} />
}

View file

@ -12,7 +12,7 @@ import { Link } from "react-router-dom";
import { get } from "../lib/api.ts";
import { isBadId, personHref } from "../lib/hrefs.ts";
import { initials, personPhoto } from "../lib/media.ts";
import { mediaUrl, initials } from "../lib/media.ts";
import "./PeopleTiles.css";
/**
@ -548,7 +548,7 @@ function Tile({
const content = (
<span className="pl__frame">
<span className="pl__photo">
<Photo src={personPhoto(person.photo)} name={person.name} />
<Photo src={mediaUrl(person.photo)} name={person.name} />
</span>
<span className="pl__caption">
<span className="pl__name">{person.name}</span>

View file

@ -24,7 +24,7 @@ import { useId, useState, type KeyboardEvent } from 'react'
import { Link } from 'react-router-dom'
import { personHref } from '../lib/hrefs.ts'
import { blockMedia, initials, personPhoto } from '../lib/media.ts'
import { mediaUrl, initials } from '../lib/media.ts'
import type { ContentBlockItem } from '../lib/useContent.ts'
import { Anchor, Paragraphs } from './InlineText.tsx'
import { withAlpha, accentText, readableOn } from '../lib/color.ts'
@ -66,7 +66,7 @@ const mapLink = (place: string) =>
function Avatar({ person, size }: { person: NonNullable<ContentBlockItem['person']>; size: string }) {
const [failed, setFailed] = useState(false)
const src = personPhoto(person.photo)
const src = mediaUrl(person.photo)
return src && !failed ? (
<img src={src} alt="" onError={() => setFailed(true)} className={`${size} shrink-0 rounded-full object-cover`} />
) : (
@ -84,7 +84,7 @@ function Entry({ entry, accent }: { entry: ContentBlockItem; accent: string }) {
// Google's map loads only when asked for (Privacy page).
const [showMap, setShowMap] = useState(false)
const panelId = useId()
const graphic = blockMedia(entry.media)
const graphic = mediaUrl(entry.media)
const place = entry.map?.trim()
const more = Boolean(entry.description || graphic || place || entry.person)

View file

@ -16,6 +16,7 @@
═══════════════════════════════════════════════════════════════ */
import { useEffect, useState } from "react";
import { scrollBehavior } from "../../lib/motion.ts";
export type EditorSection = {
id: string;
@ -63,7 +64,7 @@ function useActiveSection(sections: EditorSection[]) {
}
function jump(id: string) {
document.getElementById(id)?.scrollIntoView({ behavior: "smooth", block: "start" });
document.getElementById(id)?.scrollIntoView({ behavior: scrollBehavior(), block: "start" });
}
function Label({ section }: { section: EditorSection }) {