NGU-Web/src/pages/NotFound.tsx
Zaldimmar 27e5fbd690 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>
2026-10-03 17:12:27 -05:00

136 lines
5.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* ═══════════════════════════════════════════════════════════════
NOT FOUND: any address no route matches
Rather than a dead end, the closest pages to the address that
failed: the static pages (site.json's) and every public, listed
record (GET /directory), scored by suggest.ts against the
address. So /organisation offers Organization, /retreat offers
Retreats, and an old /chapters/lynnwood offers the Lynnwood group.
Below them, the main pages to start from, except in reading mode,
whose own line of page links (ReaderView) already gives them.
The server sends this same page with a 404 status for an unknown
address (routes/pages.js), so search engines drop it.
═══════════════════════════════════════════════════════════════ */
import { ArrowRight } from '@phosphor-icons/react'
import { useMemo } from 'react'
import { Link, useLocation } from 'react-router-dom'
import PageShell from '../components/PageShell.tsx'
import { PAGE_LINKS } from '../navConfig.ts'
import { SITE_PAGES } from '../lib/site.ts'
import { useDirectory, type Directory } from '../lib/useContent.ts'
import { blogHref, eventHref, orgHref, personHref, teamHref, awardHref } from '../lib/hrefs.ts'
import { suggest, type Candidate } from '../lib/suggest.ts'
import { ACCENTS, BRAND } from '../lib/color.ts'
import { useReadingMode } from '../lib/readingMode.ts'
const ORG_KIND_LABEL: Record<string, string> = {
national: 'Organization',
region: 'Region',
group: 'Group',
partner: 'Partner',
}
/* Everything an address could have meant: the static pages, then
each kind of record, with the words to match it by. */
function candidates(directory: Directory | null): Candidate[] {
const pages: Candidate[] = Object.entries(SITE_PAGES).map(([path, page]) => ({
href: path,
label: page.title,
detail: 'Page',
keys: [path.slice(1), page.title],
}))
if (!directory) return pages
const record = (href: string, id: string, name: string, detail: string): Candidate => ({
href,
label: name,
detail,
keys: [id, name],
})
return [
...pages,
...directory.events.map((e) => record(eventHref(e.id), e.id, e.name, 'Event')),
...directory.organizations.map((o) => record(orgHref(o.id, o.kind), o.id, o.name, ORG_KIND_LABEL[o.kind] ?? 'Organization')),
...directory.teams.map((t) => record(teamHref(t.id), t.id, t.name, `Team, ${t.org_name}`)),
...directory.awards.map((a) => record(awardHref(a.id), a.id, a.name, 'Award')),
...directory.people.map((p) => record(personHref(p.id), p.id, p.name, 'Person')),
...directory.blog_posts.map((b) => record(blogHref(b.id), b.id, b.name, 'Blog post')),
]
}
export default function NotFound() {
const { pathname } = useLocation()
const { data: directory, loading } = useDirectory()
const matches = useMemo(() => suggest(pathname, candidates(directory ?? null)), [pathname, directory])
const reading = useReadingMode()
return (
<PageShell
title="That page isn’t here"
intro="The link may be out of date, or the address may have a typo."
sections={[
{
id: 'suggestions',
title: matches.length ? 'Were you looking for' : 'Nothing close by that name',
accent: BRAND,
content: (
<div className="mx-auto max-w-6xl px-6">
{loading && !directory ? (
<div className="skeleton !min-h-32" aria-label="Looking for similar pages" />
) : matches.length ? (
<ul className="max-w-2xl divide-y divide-brand/15 bg-raised shadow-sm">
{matches.map((match) => (
<li key={match.href}>
<Link
to={match.href}
className="group flex items-center gap-4 px-5 py-4 transition-colors hover:bg-tint-soft"
>
<span className="min-w-0 flex-1">
<span className="block font-display font-bold text-ink">{match.label}</span>
<span className="block text-sm text-muted">
{match.detail} · {match.href}
</span>
</span>
<ArrowRight
className="shrink-0 text-link transition-transform group-hover:translate-x-1"
weight="bold"
aria-hidden="true"
/>
</Link>
</li>
))}
</ul>
) : (
<p className="notice max-w-xl p-6 text-body">
{reading ? 'Try one of the main pages at the top.' : 'Try one of the main pages below, or the menu at the top.'}
</p>
)}
</div>
),
},
...(reading ? [] : [{
id: 'start',
title: 'Start from',
accent: ACCENTS.green,
content: (
<div className="mx-auto flex max-w-6xl flex-wrap gap-3 px-6">
{PAGE_LINKS.map((page) => (
<Link
key={page.path}
to={page.path}
className="btn border border-brand/50 px-5 py-2 text-link transition-colors hover:bg-tint"
>
{page.label}
</Link>
))}
</div>
),
}]),
]}
/>
)
}