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

View file

@ -27,6 +27,7 @@ import { timeline } from "./adminSchema/timeline.ts";
import { frontPage } from "./adminSchema/frontPage.ts";
import { blogPosts } from "./adminSchema/blog.ts";
import { siteSettings } from "./adminSchema/siteSettings.ts";
import { siteNav } from "./adminSchema/siteNav.ts";
import { personTagTypes } from "./adminSchema/personTags.ts";
import { tags } from "./adminSchema/tags.ts";
import { contactTypes } from "./adminSchema/contactTypes.ts";
@ -37,6 +38,7 @@ import {
resourcesPage,
organizationPage,
historyPage,
shopPage,
} from "./adminSchema/sitePages.ts";
export const ADMIN_ENTITIES: Record<string, any> = {
@ -57,6 +59,8 @@ export const ADMIN_ENTITIES: Record<string, any> = {
resources_page: resourcesPage,
organization_page: organizationPage,
history_page: historyPage,
shop_page: shopPage,
navigation: siteNav,
site_settings: siteSettings,
};

View file

@ -0,0 +1,104 @@
import siteConfiguration from "../../../site.json";
/* ── Navigation (075_site_nav.sql) ───────────────────────────────
Pages → Navigation: the header's and footer's links, and each
static page's title, intro and whether it's hidden. Admins and up
save it, since hiding takes a page off the site. Server side:
server/src/admin-schema/siteNav.js; the site reads it through
server/src/siteNav.js and src/lib/useSiteNav.ts. */
const SITE_PAGES: [string, string][] = Object.entries(siteConfiguration.pages).map(
([path, page]) => [path, `${page.title} (${path})`],
);
const PLACES: [string, string][] = [
["main", "Header: pages"],
["action", "Header: buttons"],
["footer", "Footer: Get in Touch"],
["legal", "Footer: bottom row"],
];
const placeLabel = (place) => PLACES.find(([key]) => key === place)?.[1];
export const siteNav = {
key: "navigation",
label: "Navigation",
singular: "navigation",
idLabel: "Navigation",
singleton: "site",
writeRole: "admin",
list: { columns: [], filters: [] },
groups: [],
children: [
{
key: "links",
label: "Links",
note: "Top to bottom, in the order each place shows them. A link to a hidden page is only shown to signed-in admin accounts. A header page lists its sections under it by itself (Pages → the page).",
addLabel: "Add link",
title: (row) => (row.label ? `${row.label} · ${placeLabel(row.place) ?? "No place"}` : "New link"),
blank: { place: "", label: "", path: "", parent_path: "", style: "", new_tab: 0 },
fields: [
{ path: "place", label: "Shows in", widget: "select", options: PLACES, required: true },
{ path: "label", label: "Label", required: true, help: "eg. Shop" },
{
path: "path",
label: "Link",
required: true,
full: true,
help: "A page on the site, a section of one, or an address elsewhere, eg. /shop, /organization#contact or https://www.bonfire.com/store/…",
},
{
path: "parent_path",
label: "Under page",
widget: "select",
options: [["/", "Home (/)"], ...SITE_PAGES],
blankLabel: "Default: its own place in the header",
help: "Lists it in that page's menu, after its sections, instead of in the header's row",
when: { path: "place", value: "main" },
},
{
path: "style",
label: "Style",
widget: "select",
options: [["filled", "Filled, like Give (also beside the footer's logo)"]],
blankLabel: "Default: outlined",
when: { path: "place", value: "action" },
},
{ path: "new_tab", label: "Opens in a new tab", widget: "checkbox" },
],
},
{
key: "pages",
label: "Pages",
note: "A page's heading and intro (also its search title and description), and whether it's hidden. A hidden page is out of the menus and the sitemap and says Not found to everyone but signed-in admin accounts, who see it with a bar saying it's hidden. Blank fields keep site.json's. A page not listed here shows as site.json has it.",
addLabel: "Add page",
title: (row) =>
`${SITE_PAGES.find(([path]) => path === row.path)?.[1] ?? "New page"}${row.is_hidden ? " · Hidden" : ""}`,
blank: { path: "", title: "", description: "", is_hidden: 0 },
fields: [
{ path: "path", label: "Page", widget: "select", options: SITE_PAGES, required: true },
{
path: "is_hidden",
label: "Hidden",
widget: "checkbox",
help: "Not found to everyone but signed-in admin accounts, eg. a page that isn't done",
},
{
path: "title",
label: "Title",
help: (row) => (row?.path ? `Default: ${siteConfiguration.pages[row.path]?.title ?? ""}` : undefined),
},
{
path: "description",
label: "Intro",
widget: "textarea",
full: true,
help: (row) => (row?.path ? `Default: ${siteConfiguration.pages[row.path]?.description ?? ""}` : undefined),
},
],
},
],
};

View file

@ -1,5 +1,6 @@
/* ── The site's own pages (056_site_pages.sql) ───────────────────
Pages → Community, Retreats, Resources, Organization, History:
Pages → Community, Retreats, Resources, Organization, History,
Shop (075):
each page is its sections, in order, and each section is its
heading and its own content blocks, then a preset if it has one
(a prebuilt part of the site, drawn under the blocks). Server
@ -254,3 +255,4 @@ export const retreatsPage = sitePage("retreats", "Retreats page", ["events"]);
export const resourcesPage = sitePage("resources", "Resources page", ["people_directory"]);
export const organizationPage = sitePage("organization", "Organization page", ["people_directory"]);
export const historyPage = sitePage("history", "History page", ["timeline"]);
export const shopPage = sitePage("shop", "Shop page", []);

View file

@ -4,10 +4,8 @@ import { THEME_DEFAULTS } from "../../../server/src/themeDefaults.js";
/* ── Site settings (035_site_settings.sql) ───────────────────────
Overrides for site.json, superadmins only: every blank falls back
to what site.json says, which is shown as the default. */
const SITE_PAGES: [string, string][] = Object.entries(siteConfiguration.pages).map(
([path, page]) => [path, `${page.title} (${path})`],
);
to what site.json says, which is shown as the default. Page titles
and intros are Pages → Navigation's (siteNav.ts). */
/* The palette an admin can change, in the order the dropdown lists
it: token and label. The defaults come from the server's list
@ -218,28 +216,5 @@ export const siteSettings = {
},
],
},
{
key: "pages",
label: "Page titles and intros",
note: "Change a static page's heading and intro, which are also its search title and description. Blank fields keep site.json's.",
addLabel: "Change a page",
title: (row) => SITE_PAGES.find(([path]) => path === row.path)?.[1] ?? "New page",
blank: { path: "", title: "", description: "" },
fields: [
{ path: "path", label: "Page", widget: "select", options: SITE_PAGES, required: true },
{
path: "title",
label: "Title",
help: (row) => (row?.path ? `Default: ${siteConfiguration.pages[row.path]?.title ?? ""}` : undefined),
},
{
path: "description",
label: "Intro",
widget: "textarea",
full: true,
help: (row) => (row?.path ? `Default: ${siteConfiguration.pages[row.path]?.description ?? ""}` : undefined),
},
],
},
],
};

View file

@ -13,7 +13,7 @@
table, so there is one answer to "where does an event live" and
changing it is changing EVENT_BASE below.
navConfig.ts stays the source of truth for the *nav*: these are
The nav is Pages → Navigation's (useSiteNav.ts): these are
record routes, which never appear in it.
── On missing ids ──

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])
}