Navigation in the admin: header and footer links, page titles, hidden pages, Shop

Pages -> Navigation (migration 075) edits the header's pages and buttons
and the footer's links; navConfig.ts is now only the defaults. Page titles
and intros move there from Site settings. A hidden page answers Not found
below viewer (server and app) and is out of the menus and sitemap; signed
in, it shows with a bar. Adds a /shop page of sections, hidden, with its
header button.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aidan Dona 2026-10-16 18:01:02 -05:00
parent b49497cc59
commit 0cc2a3f721
30 changed files with 716 additions and 216 deletions

56
src/lib/useSiteNav.ts Normal file
View file

@ -0,0 +1,56 @@
/* ═══════════════════════════════════════════════════════════════
SITE NAV: 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.
═══════════════════════════════════════════════════════════════ */
import { useMemo } from 'react'
import { NAV_DEFAULTS, type NavLink } from '../navConfig.ts'
import { useRecord } from './useRecord.ts'
export type SiteNav = {
links: NavLink[]
/** Paths of hidden pages, eg. '/shop'. */
hidden: string[]
/** This visitor sees hidden pages (signed in, viewer and up). */
seesHidden: boolean
}
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 }
/** A path's page: no #section or ?query, no trailing slash. */
export const pageOf = (path: string): string => path.split(/[?#]/)[0].replace(/(.)\/+$/, '$1') || '/'
export function useSiteNav() {
const { data } = useRecord<SiteNav>('/nav', 'nav')
const nav = data ?? fromPage ?? DEFAULTS
return useMemo(() => {
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)))
return {
...nav,
/** 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)),
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)),
}
}, [nav])
}