Reading mode: every page and section reads as text

The reader (ReaderView.tsx) now reads an icon-only link's label, puts
a card's link on its first line or picture when it has no heading,
gives each item of a row of facts or links its own line, keeps line
breaks, skips what CSS hides, turns a form into one line saying it
can't be used there, shows empty table cells as "-", keeps section and
heading ids so #links land, and opens file links as files.

What it can't read draws its own text version (useReadingMode()):
the hero, pathfinder, front page history, event lists (every event,
past ones too), org lists and groups map (every region and group,
linked), history timeline (every year open), schedules (every day,
fold-outs included), people tiles (everyone, with details) and videos.

Also: org names are linked headings, heading levels fixed where cards
repeated their section's, Team pages lose the doubled "Members",
Giving links the treasurer's email and names Church Center.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-10-03 17:12:27 -05:00
parent c79910ef8d
commit 27e5fbd690
24 changed files with 788 additions and 180 deletions

View file

@ -35,6 +35,10 @@
"Formatted" is InlineText.tsx: **bold**, *italic*, [text](url),
line breaks, and a blank line for a new paragraph.
Reading mode (readingMode.ts): a linked image with no alt text
is a line linking with its caption, and a video's caption is its
link (VideoPlayer), not said twice.
An unknown `type` renders its text as a paragraph rather than
disappearing. A block somebody typed into the admin should be
visible even if the renderer hasn't caught up with it.
@ -50,6 +54,7 @@ import { accentText, BRAND } from '../lib/color.ts'
import { headingAnchors } from '../lib/contents.ts'
import { SITE_NAME } from '../lib/site.ts'
import { useSmallImage } from '../lib/useSmallImage.ts'
import { useReadingMode } from '../lib/readingMode.ts'
const BODY = 'var(--color-muted)'
@ -66,11 +71,20 @@ export default function ContentBlocks({
// Headings get ids so a post's contents (PostContents) and a shared
// link (#getting-there) can point at them.
const { idAt } = headingAnchors(blocks)
// The heading level a block's own headings take: under the last
// heading (h3) or subheading (h4) before it, else the section's h2.
let under = 2
const levels = blocks.map((block) => {
const level = (under + 1) as 3 | 4 | 5
if (block.type === 'heading') under = 3
if (block.type === 'subheading') under = 4
return level
})
return (
<div className={`space-y-6 ${className}`}>
{blocks.map((block, index) => (
<Block key={block.id ?? index} block={block} accent={accent} anchor={idAt.get(index)} />
<Block key={block.id ?? index} block={block} accent={accent} anchor={idAt.get(index)} level={levels[index]} />
))}
</div>
)
@ -135,8 +149,19 @@ function Caption({ text }: { text?: string | null }) {
)
}
function Block({ block, accent, anchor }: { block: ContentBlock; accent: string; anchor?: string }) {
function Block({
block,
accent,
anchor,
level,
}: {
block: ContentBlock
accent: string
anchor?: string
level: 3 | 4 | 5
}) {
const text = block.text ?? ''
const reading = useReadingMode()
switch (block.type) {
case 'heading':
@ -294,6 +319,14 @@ function Block({ block, accent, anchor }: { block: ContentBlock; accent: string;
case 'image': {
const src = mediaUrl(block.media)
if (!src) return null
// The reader leaves out a picture with no alt, and its link with it.
if (reading && block.href && !block.alt) {
return (
<p>
<Anchor href={block.href}>{text || 'Open link'}</Anchor>
</p>
)
}
const img = (
<img
src={src}
@ -320,7 +353,7 @@ function Block({ block, accent, anchor }: { block: ContentBlock; accent: string;
<div className="overflow-hidden">
<VideoPlayer url={block.href} still={mediaUrl(block.media)} title={text || null} />
</div>
<Caption text={text} />
{!reading && <Caption text={text} />}
</figure>
)
@ -335,8 +368,8 @@ function Block({ block, accent, anchor }: { block: ContentBlock; accent: string;
if (!block.team_id && picked.length === 0) return null
return (
<div className="space-y-6">
{block.team_id && <PeopleTiles size="lg" teams={block.team_id} accent={accent} />}
{picked.length > 0 && <PeopleTiles size="lg" people={picked} accent={accent} />}
{block.team_id && <PeopleTiles size="lg" teams={block.team_id} accent={accent} headingLevel={level} />}
{picked.length > 0 && <PeopleTiles size="lg" people={picked} accent={accent} headingLevel={level} />}
</div>
)
}

View file

@ -25,7 +25,8 @@
longer stretches its neighbor.
Reading mode (readingMode.ts) gets each card as a linked heading
and its words, a video card linking to its video.
and its words, a video card linking to its video. `level` is that
heading's level, one under the heading above the cards.
═══════════════════════════════════════════════════════════════ */
@ -84,8 +85,9 @@ function VideoPicture({ card }: { card: FeaturedCard }) {
const RULE = 'border-brand'
function Card({ card, large }: { card: FeaturedCard; large: boolean }) {
function Card({ card, large, level }: { card: FeaturedCard; large: boolean; level: 3 | 4 }) {
const href = hrefFor(card)
const Title = level === 4 ? 'h4' : 'h3'
const text = (
<div className={`flex flex-1 flex-col ${large ? 'p-8 md:p-10' : 'p-7'}`}>
@ -93,7 +95,7 @@ function Card({ card, large }: { card: FeaturedCard; large: boolean }) {
<p className="text-sm font-semibold text-link">{card.eyebrow}</p>
)}
{card.title && (
<h3 className={`mt-2 font-display font-bold leading-snug text-ink ${large ? 'text-2xl md:text-3xl' : 'text-lg'}`}>
<Title className={`mt-2 font-display font-bold leading-snug text-ink ${large ? 'text-2xl md:text-3xl' : 'text-lg'}`}>
{href ? (
// Stretched over the whole card, so the picture and the
// blurb are part of the click without nesting links.
@ -106,7 +108,7 @@ function Card({ card, large }: { card: FeaturedCard; large: boolean }) {
) : (
card.title
)}
</h3>
</Title>
)}
{card.blurb && (
<p className={`mt-2 leading-relaxed text-muted ${large ? '' : 'line-clamp-3 text-sm'}`}>{card.blurb}</p>
@ -135,7 +137,10 @@ function Card({ card, large }: { card: FeaturedCard; large: boolean }) {
)
}
function ReadingCards({ cards }: { cards: FeaturedCard[] }) {
type FeaturedCardsProps = { cards: FeaturedCard[]; level?: 3 | 4 }
function ReadingCards({ cards, level = 3 }: FeaturedCardsProps) {
const Title = level === 4 ? 'h4' : 'h3'
return (
<>
{cards.map((card, index) => {
@ -143,7 +148,7 @@ function ReadingCards({ cards }: { cards: FeaturedCard[] }) {
return (
<div key={`${card.kind}-${card.ref?.id ?? card.url}-${index}`}>
{card.eyebrow && <p>{card.eyebrow}</p>}
{card.title && <h3>{href ? <HomeLink url={href}>{card.title}</HomeLink> : card.title}</h3>}
{card.title && <Title>{href ? <HomeLink url={href}>{card.title}</HomeLink> : card.title}</Title>}
{card.blurb && <p>{card.blurb}</p>}
</div>
)
@ -152,9 +157,9 @@ function ReadingCards({ cards }: { cards: FeaturedCard[] }) {
)
}
export default function FeaturedCards({ cards }: { cards: FeaturedCard[] }) {
export default function FeaturedCards({ cards, level = 3 }: FeaturedCardsProps) {
const reading = useReadingMode()
if (reading) return <ReadingCards cards={cards} />
if (reading) return <ReadingCards cards={cards} level={level} />
const leadLarge = cards.length >= 3
return (
<div className="overflow-hidden shadow-md">
@ -164,6 +169,7 @@ export default function FeaturedCards({ cards }: { cards: FeaturedCard[] }) {
key={`${card.kind}-${card.ref?.id ?? card.url}-${index}`}
card={card}
large={leadLarge && index === 0}
level={level}
/>
))}
</ul>

View file

@ -5,11 +5,20 @@
filled in its accent, then its website, email and socials
outlined. Nothing at all when it has none. Used on an
organization's page and on the Organization page (NGU's own).
A platform's icon has its name beside it for screen readers and
reading mode, unless the label already says it (PlatformName).
═══════════════════════════════════════════════════════════════ */
import PlatformIcon from './PlatformIcon.tsx'
import type { OrganizationRecord } from '../lib/useContent.ts'
import { accentText } from '../lib/color.ts'
import { PLATFORMS } from '../lib/platforms.ts'
function PlatformName({ platform, label }: { platform?: string | null; label?: string | null }) {
const name = PLATFORMS.find((p) => p.id === platform)?.label
if (!name || label?.toLowerCase().includes(name.toLowerCase())) return null
return <span className="sr-only">{label ? `${name}: ` : name}</span>
}
export default function OrgContact({ org, accent }: { org: OrganizationRecord; accent: string }) {
const hasAny =
@ -29,6 +38,7 @@ export default function OrgContact({ org, accent }: { org: OrganizationRecord; a
style={{ background: accent }}
>
<PlatformIcon platform={link.platform} />
<PlatformName platform={link.platform} label={link.label} />
{link.label}
</a>
))}
@ -51,6 +61,7 @@ export default function OrgContact({ org, accent }: { org: OrganizationRecord; a
style={{ borderColor: accent, color: accentText(accent) }}
>
<PlatformIcon platform={link.platform} />
<PlatformName platform={link.platform} label={link.label} />
{link.label}
</a>
))}

View file

@ -18,6 +18,7 @@ import { isBadId, personHref } from "../lib/hrefs.ts";
import { mediaUrl, initials } from "../lib/media.ts";
import { useSmallImage } from "../lib/useSmallImage.ts";
import { paletteFill } from "../lib/color.ts";
import { useReadingMode } from "../lib/readingMode.ts";
import "./PeopleTiles.css";
/**
@ -71,6 +72,10 @@ import "./PeopleTiles.css";
* with no photo gets their initials on a palette color
* (paletteFill in color.ts).
*
* Reading mode (readingMode.ts) gets everyone, no "Show all", each
* a heading (linked to their profile) and their title, facts and bio
* as lines (ReadingPeople).
*
* Field names follow the API (is_owner, location_label), so a row
* from /api/teams/:id/people drops in unchanged.
*
@ -122,7 +127,8 @@ export interface PeopleGroupInput extends Omit<PeopleGroup, "people"> {
export interface TeamSpec {
id: string;
/** Heading for the members group. Defaults to the team's name. */
/** Heading for the members group beside a lead group, or among
* several teams. Defaults to the team's name. */
label?: string;
/** Heading for the lead group. Defaults to the lead's own title. */
leadLabel?: string;
@ -146,6 +152,9 @@ export interface PeopleTilesProps
align?: "start" | "center";
accent?: string;
tilt?: boolean;
/** The group labels' heading level, by what they sit under (3 under
* a section's h2). In reading mode the names are one level under. */
headingLevel?: 3 | 4 | 5;
/** How long a fetched team or person is reused, in ms. */
ttl?: number;
emptyMessage?: string;
@ -372,8 +381,10 @@ function buildTeamGroups(
return [
{
id: data.team.id,
// One unlabeled team needs no heading; several always do.
label: teamCount > 1 || spec.label ? name : undefined,
// One team alone needs no heading (its page or section names
// it); several always do. `label` names the members beside a
// lead group.
label: teamCount > 1 ? name : undefined,
accent,
people: data.people,
},
@ -408,6 +419,7 @@ export function PeopleTilesView({
accent,
tilt = false,
emptyMessage = "No one listed yet.",
headingLevel = 3,
onExpand,
className = "",
style,
@ -426,6 +438,7 @@ export function PeopleTilesView({
const [clipped, setClipped] = useState<ReadonlySet<string>>(() => new Set());
const rootRef = useRef<HTMLDivElement>(null);
const probeRef = useRef<HTMLSpanElement>(null);
const reading = useReadingMode();
const resolvedSize: PeopleTilesSize = SIZE_FEATURES[size] ? size : "md";
const features = SIZE_FEATURES[resolvedSize];
@ -532,6 +545,8 @@ export function PeopleTilesView({
if (!resolvedGroups.length) {
return emptyMessage ? <p className="pl__empty">{emptyMessage}</p> : null;
}
if (reading) return <ReadingPeople groups={resolvedGroups} level={headingLevel} />;
const Label = `h${headingLevel}` as "h3";
const open = openKey ? findByKey(resolvedGroups, openKey) : null;
const oneRow =
@ -598,7 +613,7 @@ export function PeopleTilesView({
>
{(group.label || group.note) && (
<header className="pl__group-head">
{group.label && <h3 className="pl__group-label">{group.label}</h3>}
{group.label && <Label className="pl__group-label">{group.label}</Label>}
{group.note && <p className="pl__group-note">{group.note}</p>}
</header>
)}
@ -883,6 +898,52 @@ function DetailPanel({
);
}
/* Reading mode: every person and what their details panel says. */
function ReadingPeople({ groups, level }: { groups: PeopleGroup[]; level: 3 | 4 | 5 }) {
const Label = `h${level}` as "h3";
return (
<div>
{groups.map((group) => {
// Names sit under the group's label, or take its place.
const Name = `h${group.label ? level + 1 : level}` as "h4";
return (
<section key={group.id}>
{group.label && <Label>{group.label}</Label>}
{group.note && <p>{group.note}</p>}
{group.people.map((person, index) => {
const href = profileHref(person);
const title = titleOf(person);
const org = resolveOrg(person.org);
const bio = Array.isArray(person.bio) ? person.bio : [person.bio];
return (
<div key={keyFor(group, person, index)}>
<Name>{href ? <Link to={href}>{person.name}</Link> : person.name}</Name>
{title && <p>{title}</p>}
{person.pronouns && <p>Pronouns: {person.pronouns}</p>}
{org && (
<p>
Home organization: {org.href ? <a href={org.href}>{org.name}</a> : org.name}
</p>
)}
{person.location_label && <p>Based in: {person.location_label}</p>}
{person.public_email && (
<p>
Email: <a href={`mailto:${person.public_email}`}>{person.public_email}</a>
</p>
)}
{bio.filter(Boolean).map((paragraph, i) => (
<p key={i}>{paragraph}</p>
))}
</div>
);
})}
</section>
);
})}
</div>
);
}
function Chevron() {
return (
<CaretDown size={12} weight="bold" aria-hidden="true" />

View file

@ -14,26 +14,46 @@
h1 to h6 headings, at their level
p, li, td, quote... paragraphs, with their links
a links (a card that is one link gives its
heading the link)
heading the link, or with none its first
line or picture); an icon-only link reads
its aria-label
br a line break
a part drawn on its a line of its own: a row of facts or link
own line buttons reads one per line
form one line saying it can't be used here
img with alt text pictures; one with empty alt is decoration
(a card's faded background) and is left out
a button that opens its words, as a line: a person's tile, a
something schedule row (aria-expanded)
What's dropped: other buttons, form fields, navigation lists, video and
map frames, drawings, and anything hidden from screen readers
(aria-hidden, the copies a carousel draws for its turns).
map frames, drawings, anything hidden from screen readers
(aria-hidden, the copies a carousel draws for its turns) and
anything CSS hides (display: none, eg. a print-only footer).
Ids on sections and headings are kept, so #links still land.
What this can't do well (a carousel showing one card, tabs,
details opened by a click, a count waiting to be scrolled to) the
component draws as text itself when useReadingMode() is on.
═══════════════════════════════════════════════════════════════ */
import { useEffect, useState, type ReactNode, type RefObject } from 'react'
import { Fragment, useEffect, useState, type ReactNode, type RefObject } from 'react'
import { Link } from 'react-router-dom'
import { PAGE_LINKS } from '../navConfig.ts'
type Inline = string | { href: string; children: Inline[] }
type Block =
/* A <br> in the page, kept as a line break (an address, a poem). */
const BREAK = '
'
/* `ids` are the page's own ids on a section or heading (a section
and its heading can both have one), kept so a #link (the side
nav, a "Jump to" button) still lands. */
type Block = { ids?: string[] } & (
| { kind: 'heading'; level: number; content: Inline[] }
| { kind: 'text'; content: Inline[] }
| { kind: 'image'; src: string; alt: string }
| { kind: 'image'; src: string; alt: string; href?: string }
)
const SKIP = new Set(['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEMPLATE', 'BUTTON', 'INPUT', 'SELECT', 'TEXTAREA', 'NAV', 'IFRAME', 'VIDEO', 'AUDIO', 'CANVAS', 'DIALOG', 'svg'])
const HEADINGS = new Set(['H1', 'H2', 'H3', 'H4', 'H5', 'H6'])
@ -48,7 +68,16 @@ const skipped = (el: Element) =>
(SKIP.has(el.tagName) && !opens(el)) ||
el.getAttribute('aria-hidden') === 'true' ||
el.hasAttribute('hidden') ||
['button', 'switch', 'tab', 'slider', 'presentation', 'none'].includes(el.getAttribute('role') ?? '')
['button', 'switch', 'tab', 'slider', 'presentation', 'none'].includes(el.getAttribute('role') ?? '') ||
// Hidden by CSS: a print-only footer, a phone-only copy.
getComputedStyle(el).display === 'none'
/* Drawn on a line of its own (a flex row's items, a block link): a
row of facts or link buttons reads one per line, not run together. */
const ownLine = (el: Element) => {
const display = getComputedStyle(el).display
return !display.startsWith('inline') && display !== 'contents'
}
/* A link's address as the app routes it: a path for this site, so
it opens without reloading; the full address for anywhere else. */
@ -66,9 +95,12 @@ function hrefOf(a: HTMLAnchorElement): string | null {
function inline(node: Node): Inline[] {
if (node.nodeType === Node.TEXT_NODE) return [node.textContent ?? '']
if (!(node instanceof Element) || skipped(node) || node.tagName === 'IMG') return []
if (node.tagName === 'BR') return [' ']
const children = [...node.childNodes].flatMap(inline)
if (node.tagName === 'BR') return [BREAK]
let children = [...node.childNodes].flatMap(inline)
const href = node instanceof HTMLAnchorElement ? hrefOf(node) : null
// An icon-only link (an arrow) names itself in aria-label.
const label = node.getAttribute('aria-label')
if (href && label && !textOf(children)) children = [label]
const parts: Inline[] = href ? [{ href, children }] : children
// A part the page draws on its own line (a span set to block, a
// flex row's items) has no space in its text: give it one.
@ -82,13 +114,20 @@ const isBlock = (el: Element) => opens(el) || el.matches(BLOCK_SELECTOR) || el.q
function extract(root: Element): Block[] {
const blocks: Block[] = []
// Ids waiting for the next block written, which takes them.
let pendingIds: string[] = []
const push = (block: Block) => {
blocks.push(pendingIds.length ? { ...block, ids: pendingIds } : block)
pendingIds = []
}
const text = (content: Inline[]) => {
if (textOf(content)) blocks.push({ kind: 'text', content })
if (textOf(content)) push({ kind: 'text', content })
}
function walk(el: Element, link: string | null) {
// The root is the hidden copy of the page itself: read inside it.
if (el !== root && skipped(el)) return
if (el.id && el !== root) pendingIds.push(el.id)
if (opens(el)) {
// Each part on its own line in the page (a name, a title) joins
// with a comma.
@ -98,10 +137,14 @@ function extract(root: Element): Block[] {
text([parts.join(', ')])
return
}
if (el.tagName === 'FORM') {
text(['This form can’t be filled in while reading mode is on. Turn it off (the accessibility button) to use it.'])
return
}
if (HEADINGS.has(el.tagName)) {
const content = [...el.childNodes].flatMap(inline)
if (textOf(content)) {
blocks.push({ kind: 'heading', level: Number(el.tagName[1]), content: link ? [{ href: link, children: content }] : content })
push({ kind: 'heading', level: Number(el.tagName[1]), content: link ? [{ href: link, children: content }] : content })
}
return
}
@ -109,7 +152,7 @@ function extract(root: Element): Block[] {
const img = el as HTMLImageElement
const alt = img.getAttribute('alt')?.trim()
const src = img.currentSrc || img.getAttribute('src')
if (alt && src) blocks.push({ kind: 'image', src, alt })
if (alt && src) push({ kind: 'image', src, alt, ...(link ? { href: link } : {}) })
return
}
if (TEXT_BLOCKS.has(el.tagName) && !el.querySelector('p,li,h1,h2,h3,h4,h5,h6,img')) {
@ -117,19 +160,26 @@ function extract(root: Element): Block[] {
return
}
if (el.tagName === 'TR') {
const cells = [...el.children].map((cell) => [...cell.childNodes].flatMap(inline)).filter((c) => textOf(c))
const cells = [...el.children].map((cell) => [...cell.childNodes].flatMap(inline)).map((c) => (textOf(c) ? c : ['-']))
text(cells.flatMap((cell, i) => (i ? [' · ', ...cell] : cell)))
return
}
// A link around a whole card: its parts, with the link on the first
// heading (or, with none, kept as a line of its own).
// heading; with none, on its aria-label as a line of its own, or
// else on its first line of text.
const href = el instanceof HTMLAnchorElement ? hrefOf(el) : null
if (href && isBlock(el)) {
const before = blocks.length
for (const child of el.children) walk(child, href)
if (!blocks.slice(before).some((b) => b.kind === 'heading')) {
const own = blocks.slice(before)
if (!own.some((b) => b.kind === 'heading')) {
const label = el.getAttribute('aria-label')
const first = own.findIndex((b) => b.kind === 'text')
if (label) blocks.splice(before, 0, { kind: 'text', content: [{ href, children: [label] }] })
else if (first >= 0) {
const block = blocks[before + first] as Extract<Block, { kind: 'text' }>
blocks[before + first] = { ...block, content: [{ href, children: block.content }] }
}
}
return
}
@ -142,6 +192,10 @@ function extract(root: Element): Block[] {
text(run)
run = []
walk(child, link)
} else if (child instanceof Element && !skipped(child) && ownLine(child)) {
text(run)
run = []
text(inline(child))
} else {
run.push(...inline(child))
}
@ -159,20 +213,31 @@ function extract(root: Element): Block[] {
function render(parts: Inline[]): ReactNode[] {
return parts.map((part, i) => {
if (typeof part === 'string') return part
const children = render(part.children)
return part.href.startsWith('/') ? (
<Link key={i} to={part.href}>
{children}
</Link>
) : (
<a key={i} href={part.href}>
{children}
</a>
if (typeof part === 'string') {
if (!part.includes(BREAK)) return part
return part.split(BREAK).map((line, j) => (
<Fragment key={`${i}-${j}`}>
{j > 0 && <br />}
{line}
</Fragment>
))
}
return (
<Anchor key={i} href={part.href}>
{render(part.children)}
</Anchor>
)
})
}
/* A page on this site opens without reloading; a file (an upload,
the API) or anywhere else is a plain link. */
const isFile = (href: string) => /^\/(uploads|api)\//.test(href)
function Anchor({ href, children }: { href: string; children: ReactNode }) {
return href.startsWith('/') && !isFile(href) ? <Link to={href}>{children}</Link> : <a href={href}>{children}</a>
}
export default function ReaderView({ source }: { source: RefObject<HTMLElement | null> }) {
const [blocks, setBlocks] = useState<Block[]>([])
@ -207,10 +272,37 @@ export default function ReaderView({ source }: { source: RefObject<HTMLElement |
))}
</p>
{blocks.map((block, i) => {
if (block.kind === 'image') return <img key={i} src={block.src} alt={block.alt} loading="lazy" />
if (block.kind === 'text') return <p key={i}>{render(block.content)}</p>
const [id, ...more] = block.ids ?? []
const anchors = more.map((other) => <span key={other} id={other} />)
if (block.kind === 'image') {
return (
<Fragment key={i}>
{anchors}
{block.href ? (
<Anchor href={block.href}>
<img id={id} src={block.src} alt={block.alt} loading="lazy" />
</Anchor>
) : (
<img id={id} src={block.src} alt={block.alt} loading="lazy" />
)}
</Fragment>
)
}
if (block.kind === 'text') {
return (
<p key={i} id={id}>
{anchors}
{render(block.content)}
</p>
)
}
const Heading = `h${block.level}` as 'h1'
return <Heading key={i}>{render(block.content)}</Heading>
return (
<Heading key={i} id={id}>
{anchors}
{render(block.content)}
</Heading>
)
})}
</article>
)

View file

@ -18,10 +18,14 @@
the place typed in, with a link out to the full map.
Tabs follow the ARIA tab pattern: arrow keys move between them.
Reading mode (readingMode.ts) gets every day as a heading, each
entry a line (time, title, place, person) with its fold-out after
it, no map frame (ReadingSchedule).
═══════════════════════════════════════════════════════════════ */
import { CaretDown } from '@phosphor-icons/react'
import { useId, useState, type KeyboardEvent } from 'react'
import { Fragment, useId, useState, type KeyboardEvent, type ReactNode } from 'react'
import { Link } from 'react-router-dom'
import { personHref } from '../lib/hrefs.ts'
@ -31,6 +35,7 @@ import { Anchor, Paragraphs } from './InlineText.tsx'
import { withAlpha, accentText, readableOn } from '../lib/color.ts'
import { useSmallImage } from '../lib/useSmallImage.ts'
import { focusOnMount } from '../lib/focus.ts'
import { useReadingMode } from '../lib/readingMode.ts'
const BODY = 'var(--color-muted)'
const WEEKDAYS = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday']
@ -215,6 +220,54 @@ function Entry({ entry, accent }: { entry: ContentBlockItem; accent: string }) {
)
}
/* Reading mode: every day, every entry and its fold-out, as text. A
day is an h4, under the page's h3 block headings (ContentBlocks). */
function ReadingSchedule({ days, intro, accent }: { days: Day[]; intro?: string | null; accent: string }) {
return (
<div>
{intro && <Paragraphs text={intro} accent={accent} />}
{days.map((day, index) => (
<div key={day.name || index}>
{days.length > 1 && <h4>{day.name || 'Schedule'}</h4>}
<ul>
{day.entries.map((entry, i) => {
const graphic = mediaUrl(entry.media)
const place = entry.map?.trim()
const parts: ReactNode[] = [
entry.time,
entry.url ? <Anchor href={entry.url}>{entry.text}</Anchor> : entry.text,
entry.location,
entry.person && <Link to={personHref(entry.person.id)}>{entry.person.name}</Link>,
].filter(Boolean)
return (
<li key={i}>
<p>
{parts.map((part, j) => (
<Fragment key={j}>
{j > 0 && ' · '}
{part}
</Fragment>
))}
</p>
{entry.detail && <p>{entry.detail}</p>}
{entry.person?.tagline && <p>{entry.person.tagline}</p>}
{entry.description && <Paragraphs text={entry.description} accent={accent} />}
{graphic && <img src={graphic} alt={entry.media_alt ?? ''} />}
{place && (
<p>
<a href={mapLink(place)}>Open {place} in Google Maps</a>
</p>
)}
</li>
)
})}
</ul>
</div>
))}
</div>
)
}
export default function ScheduleBlock({
items,
intro,
@ -227,8 +280,10 @@ export default function ScheduleBlock({
const days = groupByDay(items)
const [active, setActive] = useState(() => todayIndex(days))
const baseId = useId()
const reading = useReadingMode()
if (days.length === 0) return null
if (reading) return <ReadingSchedule days={days} intro={intro} accent={accent} />
const current = days[Math.min(active, days.length - 1)]
// Arrows move one tab and wrap; Home and End jump to the ends.

View file

@ -14,6 +14,9 @@
corners, as the only rounded thing besides buttons and dots. A link that embeds.ts can't turn into a
player (not https, or not a host it knows how to frame) still
goes somewhere: the still becomes a link to it.
Reading mode (readingMode.ts) gets a link to the video (an
uploaded file's own address), named by its title.
═══════════════════════════════════════════════════════════════ */
import { Play } from '@phosphor-icons/react'
@ -23,6 +26,7 @@ import HomeLink from '../pages/sections/home/HomeLink.tsx'
import { playingSource, videoSource, videoThumbnails } from '../lib/embeds.ts'
import { BRAND } from '../lib/color.ts'
import { focusOnMount } from '../lib/focus.ts'
import { useReadingMode } from '../lib/readingMode.ts'
export default function VideoPlayer({
@ -40,6 +44,16 @@ export default function VideoPlayer({
const [playing, setPlaying] = useState(false)
const [skipped, setSkipped] = useState(0)
const source = videoSource(url)
const reading = useReadingMode()
if (reading) {
const href = source?.kind === 'file' ? source.src : url
return href ? (
<p>
<a href={href}>{title || 'Watch the video'}</a>
</p>
) : null
}
if (playing && source) {
const live = playingSource(source)