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:
parent
c79910ef8d
commit
27e5fbd690
24 changed files with 788 additions and 180 deletions
|
|
@ -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>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue