/* ═══════════════════════════════════════════════════════════════ NOT FOUND: any address no route matches Rather than a dead end, the closest pages to the address that failed: the site's pages (Page management'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 { useSiteNav, type SitePageInfo } from '../lib/useSiteNav.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 = { national: 'Organization', region: 'Region', group: 'Group', partner: 'Partner', } /* Everything an address could have meant: the static pages (not the hidden ones), then each kind of record, with the words to match it by. */ function candidates(directory: Directory | null, sitePages: SitePageInfo[]): Candidate[] { const pages: Candidate[] = sitePages.filter((page) => !page.hidden && page.path !== '/').map((page) => ({ href: page.path, label: page.title, detail: 'Page', keys: [page.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 { main: pages, pages: sitePages } = useSiteNav() const matches = useMemo( () => suggest(pathname, candidates(directory ?? null, sitePages)), [pathname, directory, sitePages], ) const reading = useReadingMode() return ( {loading && !directory ? (
) : matches.length ? (
    {matches.map((match) => (
  • {match.label} {match.detail} · {match.href}
  • ))}
) : (

{reading ? 'Try one of the main pages at the top.' : 'Try one of the main pages below, or the menu at the top.'}

)}
), }, ...(reading ? [] : [{ id: 'start', title: 'Start from', accent: ACCENTS.green, content: (
{pages.map((page) => ( {page.label} ))}
), }]), ]} /> ) }