Page management, step 1: every page in a registry, new pages, hidden and disabled

Migration 080 makes site_pages the list of every page: address, title,
intro, Hidden, Disabled (out of menus, sitemap and search) and card order.
site.json's pages and Navigation's page list move into it. Pages ->
Page management (one editor in place of six) makes new pages of sections
at any free address; the admin home opens Pages with a banner and a card
per page. A catch-all route draws whatever page is at an address; the
fixed pages take their words from the registry and can't be deleted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aidan Dona 2026-10-16 23:19:54 -05:00
parent 56acedf926
commit 1342691f49
36 changed files with 584 additions and 405 deletions

View file

@ -1,12 +1,15 @@
/* ═══════════════════════════════════════════════════════════════
SITE NAV: the header's and footer's links, and the hidden pages
SITE NAV: the site's pages, the header's and footer's links, and
the hidden pages
Pages → Navigation, for this visitor (server/src/siteNav.js): a
link to a hidden page is only sent to a viewer and up. The page
HTML carries it (window.__SITE__.nav), so the menus draw on the
first paint; GET /api/nav asks again, which is also how the dev
server (no page metadata) and a sign-in in another tab get it.
Until either answers, navConfig.ts's defaults.
Pages → Page management and Pages → Navigation, for this visitor
(server/src/siteNav.js): a hidden page, and links to it, are only
sent to a viewer and up; a disabled page's links to no one. The
page HTML carries it (window.__SITE__.nav), so the menus draw on
the first paint; GET /api/nav asks again, which is also how the
dev server (no page metadata) and a sign-in in another tab get it.
Until either answers, navConfig.ts's links, and no pages yet
(`ready` false).
═══════════════════════════════════════════════════════════════ */
import { useMemo } from 'react'
@ -14,9 +17,20 @@ import { useMemo } from 'react'
import { NAV_DEFAULTS, type NavLink } from '../navConfig.ts'
import { useRecord } from './useRecord.ts'
/** A page of the site (site_pages). */
export type SitePageInfo = {
id: string
path: string
title: string
description: string | null
hidden: boolean
disabled: boolean
}
export type SiteNav = {
links: NavLink[]
/** Paths of hidden pages, eg. '/shop'. */
pages: SitePageInfo[]
/** Paths of hidden pages, eg. '/shop' (sent to a viewer and up only). */
hidden: string[]
/** This visitor sees hidden pages (signed in, viewer and up). */
seesHidden: boolean
@ -25,7 +39,7 @@ export type SiteNav = {
const fromPage: SiteNav | undefined =
typeof window !== 'undefined' ? (window as unknown as { __SITE__?: { nav?: SiteNav } }).__SITE__?.nav : undefined
const DEFAULTS: SiteNav = { links: NAV_DEFAULTS, hidden: [], seesHidden: false }
const DEFAULTS: SiteNav = { links: NAV_DEFAULTS, pages: [], hidden: [], seesHidden: false }
/** A path's page: no #section or ?query, no trailing slash. */
export const pageOf = (path: string): string => path.split(/[?#]/)[0].replace(/(.)\/+$/, '$1') || '/'
@ -38,19 +52,24 @@ export function useSiteNav() {
const main = nav.links.filter((l) => l.place === 'main')
const top = main.filter((l) => !l.parent)
const tops = new Set(top.map((l) => pageOf(l.path)))
const byPath = new Map(nav.pages.map((page) => [page.path, page]))
return {
...nav,
/** Whether the pages have arrived (else a page can't be told from a missing one). */
ready: Boolean(data ?? fromPage),
/** The header's pages, each with the links set under it. */
main: top.map((page) => ({
...page,
children: main.filter((l) => l.parent && l.parent === pageOf(page.path)),
})),
/** Every main link, children included, for lists of the site's pages. */
pages: main.filter((l) => !l.parent || tops.has(l.parent)),
pageLinks: main.filter((l) => !l.parent || tops.has(l.parent)),
actions: nav.links.filter((l) => l.place === 'action'),
footer: nav.links.filter((l) => l.place === 'footer'),
legal: nav.links.filter((l) => l.place === 'legal'),
isHidden: (path: string) => nav.hidden.includes(pageOf(path)),
/** The page at this path, or null. */
pageAt: (path: string): SitePageInfo | null => byPath.get(pageOf(path)) ?? null,
}
}, [nav])
}, [nav, data])
}