From 1342691f498ee15d96f2c0a776837e9bb9864348 Mon Sep 17 00:00:00 2001 From: Aidan Dona Date: Fri, 16 Oct 2026 23:19:54 -0500 Subject: [PATCH] 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 --- CLAUDE.md | 2 +- TODO.md | 21 ++-- docs/seo.md | 2 +- docs/updating-data-in-code.md | 5 +- server/src/admin-crud.js | 4 + server/src/admin-schema.js | 20 +--- server/src/admin-schema/siteNav.js | 14 +-- server/src/admin-schema/sitePages.js | 84 ++++++++++---- server/src/migrations/080_page_registry.sql | 93 ++++++++++++++++ server/src/pageMeta.js | 49 ++++---- server/src/routes/sitePages.js | 24 ++-- server/src/siteNav.js | 84 ++++++++++---- site.json | 50 --------- src/App.tsx | 28 +---- src/lib/adminSchema.ts | 23 +--- src/lib/adminSchema/siteNav.ts | 46 +------- src/lib/adminSchema/sitePages.ts | 117 ++++++++++++++------ src/lib/navSections.ts | 2 +- src/lib/site.ts | 21 +--- src/lib/useSiteNav.ts | 41 +++++-- src/lib/useSitePages.ts | 10 +- src/pages/Feedback.tsx | 9 +- src/pages/Giving.tsx | 9 +- src/pages/NotFound.tsx | 19 ++-- src/pages/PageAtPath.tsx | 31 ++++++ src/pages/Privacy.tsx | 10 +- src/pages/QrCodes.tsx | 9 +- src/pages/Request.tsx | 9 +- src/pages/SitePage.tsx | 12 +- src/pages/Terms.tsx | 9 +- src/pages/admin/AdminHome.tsx | 48 +++++++- src/pages/admin/EntityEdit.tsx | 4 +- src/pages/admin/adminNav.ts | 51 +++------ src/pages/fixedPages.ts | 23 ++++ src/pages/sections/FeedbackForm.tsx | 4 +- src/pages/sections/QrCodeMaker.tsx | 2 +- 36 files changed, 584 insertions(+), 405 deletions(-) create mode 100644 server/src/migrations/080_page_registry.sql create mode 100644 src/pages/PageAtPath.tsx create mode 100644 src/pages/fixedPages.ts diff --git a/CLAUDE.md b/CLAUDE.md index fa0d046..61d2623 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -62,7 +62,7 @@ In dev, Vite proxies `/api` to the target set in `vite.config.ts`, so the API mu - All pages use `PageShell.tsx` as the wrapper unless explicitly noted otherwise. - Pages live in `src/pages/`; section-level components go in `src/pages/sections/`. - `src/data/` holds only hardcoded data shared across multiple section files (e.g. `historyDecades.ts`, map grid). Everything else comes from SQLite, through hooks in `src/lib/`. -- Navigation (header and footer links, page titles and intros, hidden pages) is edited in Pages → Navigation (`site_nav*` tables, `server/src/siteNav.js`, read through `src/lib/useSiteNav.ts`). `navConfig.ts` only holds the defaults the app starts from before that loads. Routes are in `App.tsx`; a static page's default title and intro in `site.json`'s `pages`. A hidden page answers Not found below viewer (server and app both). +- Pages are rows of `site_pages` (migration 080), edited in Pages → Page management: address, title, intro, Hidden (Not found below viewer) and Disabled (out of the menus, sitemap and search). New pages are made there and are pages of sections; `PageAtPath.tsx` (the `*` route) draws whatever page is at an address, and the few still drawn in code are listed in `src/pages/fixedPages.ts` (and `FIXED_PAGES` in `server/src/admin-schema/sitePages.js`, which can't be deleted). Record routes (`/events/:id`...) stay in `App.tsx`, and their first path segments are reserved. Menu links are Pages → Navigation (`site_nav_links`, `server/src/siteNav.js`, read through `src/lib/useSiteNav.ts`); `navConfig.ts` only holds the defaults the app starts from before that loads. - `api.ts` is the shared caching client used by frontend data hooks. - `docs/updating-data-in-code.md`: where content that isn't in the database lives (admin dropdown labels, fixed value lists, nav, banner, decades, map grid) and how to change it. Keep it current when adding a dropdown or code-owned content. - Images: every record image (logos, photos, backgrounds, block images) is an upload, in a folder by use: `/uploads/logos/`, `/uploads/images/`, `/uploads/thumbnails/` (saved previews), `/uploads/captions/` (videos' .vtt files); a logo or icon image field sets `folder: "logos"` (`docs/media-uploads.md`, Folders). A bare filename resolves to `/uploads/` (`src/lib/media.ts`, and `server/src/pageMeta.js` for previews). Only the site's own chosen assets, the NGU logos in the nav, footer and admin, are bundled from `src/assets/logos/`. Logo images hide themselves on load error (`onError`). diff --git a/TODO.md b/TODO.md index 54b9896..1a93bf6 100644 --- a/TODO.md +++ b/TODO.md @@ -43,13 +43,11 @@ ## Sections - [ ] **Hero text that flips**: the headline's word changes (Next, Now, and other words for our generation), or mirrors. - - [ ] Which words, and are they edited in Front page (a list) or fixed? Answer: - - [ ] What motion: a flip like a card, a fade, letters typing, a mirror? Answer: + - [ ] Which words, and are they edited in Front page (a list) or fixed? Answer: Next cycles through words with an animation, allow us to customize this and the list of words, this should be a text content component that can be used places. also direction from where the words slide in, top or bottom. + - [ ] What motion: a flip like a card, a fade, letters typing, a mirror? Answer: make all of these. - [ ] Respect reduced motion by showing one word (the first)? [ ] yes - - [ ] "Next generation of New Thought": is that the line it plays on, or a second line under the headline? Answer: -- [ ] **NGU and partners**: "How does this partner with An Awakened Path and antn" (from the notes; unclear). - - [ ] What is "antn" (an organization's name)? Answer: - - [ ] Is this a section to build (eg. on Organization or Partners), or a question to answer in a blog post? Answer: + - [ ] "Next generation of New Thought": is that the line it plays on, or a second line under the headline? Answer: Unity should also be another one of these animated words that cycles through a list. + - Settled 2026-10-16: words are written inline, {Next|Now|Rising}, in the hero headline, section titles, headings and paragraphs; motion (slide, flip, fade, type, mirror), direction (from top or bottom) and seconds per word have site defaults in Site settings, overridden by the hero or a block. ## Page Features - [ ] **Full profiles**: people get full profile pages. Profile accounts, claiming and visibility are done (Part 2, Accounts); what's left is the page itself. @@ -78,6 +76,10 @@ ## Mobile ## Page Editing +- [ ] **Page management revamp**, in steps (answers from 2026-10-16: disabled means out of the menus, sitemap and search with the address still working; admins can make new pages; the front page, the Community blog's settings, the form and embed pages and Privacy/Terms all become pages of sections; section types like the hero, stats, featured cards, calendar and countdown can go on any page, each with its own content). + - [x] Step 1, the page registry (Done, below). + - [ ] Step 2: Feedback, Request, Give, QR codes become pages of sections (a section type each for the form, the giving embed and the QR maker); Privacy and Terms become editable blocks (their data request form a section type). + - [ ] Step 3: section types with their own settings: the Community blog (its slots, pinned posts and feeds move into the section, so it can go on any page), then the front page's hero, countdown, retreats, calendar, stats, timeline, featured cards and connect, and the front page itself a page of sections. ## Admin @@ -85,10 +87,9 @@ - [ ] **Planning Center sync to People**: Planning Center People into the site's people records. - [ ] One way (Planning Center → site), or both? Answer: to site only - [ ] Who gets synced: everyone, or a Planning Center list or tag (eg. "Website")? Most people in Planning Center shouldn't have a public page. Answer:a specific list - - [ ] Which fields: name, photo, email, phone, birthday? Which win when both sides differ? Answer: + - [ ] Which fields: name, photo, email, phone, birthday? Which win when both sides differ? Answer: planning center. but show the comparasin (reconcile) for each user. Fields (2026-10-16): name, and email and phone into the private fields. Matching: suggested by email or name, an admin confirms, then remembered by Planning Center's id. - [ ] How often: a button in Data, hourly, nightly? Answer: manually only - [ ] Is there a Planning Center API app (personal access token) we can use, and which account owns it? Answer: use the API - - Skipped on 2026-10-16 until the fields (and which side wins) are decided. - [ ] **New Thought young adult directory**: the tabs are built (Part 2, Page features). Content: make the People tags (eg. Authors, Creators), tag people, and set Community's Directories section to them. ## Navigation @@ -122,6 +123,10 @@ # Part 2: Done +## Page management (branch `page-management`, on top of `page-features`, no PR yet; migration 080, back up the database before deploying) +- [x] **Page registry** (migration 080): every page of the site is a row in Pages → Page management (admins and up): its address, title, intro, Hidden (Not found below viewer) and Disabled (out of the menus, the sitemap and search; the address still works), and the order of its admin card. New pages are made there, as pages of sections at the address given (any address but the admin's, the API's, the records' and the account pages'). The admin home's Pages group opens with a Page management banner (New page, Menus), then a card per page. The six page editors (Retreats, Community...) are one editor now; site.json's `pages` and Navigation's page list moved into the registry and are gone. The fixed pages (Feedback, Request, Give, QR codes, Privacy, Terms, the front page) take their words from it too and can't be deleted. + - [ ] Check in a browser: the admin home's banner and page cards, making a page (address, sections) and opening it, hiding and disabling one (menus, the page signed out), renaming Feedback, the Under page select in Navigation. + ## v1.14.0-profiles: page features (branch `page-features`, with `nav-access` under it, no PR yet; migrations 078 and 079, back up the database before deploying) - [x] **Featured event label** (Mobile): the "Featured event" badge left the headline; from lg up it sits above the event's card it names, and on a phone (the card under the words) it's left out. - [x] **Site version names**: the tag's words after the number are the version's name, `v1.13.2-region-cards` → "The Region Cards Update" (`src/lib/version.ts`), shown with the number in the site's footer and beside the version in the admin's footer and home. diff --git a/docs/seo.md b/docs/seo.md index cb2652f..9b9cf26 100644 --- a/docs/seo.md +++ b/docs/seo.md @@ -23,7 +23,7 @@ same build. | --- | --- | | Site name, address, default description | `site.json`: `title`, `url`, `description` (blank uses the front page's subhead) | | Default preview image | `site.json`: `openGraph.image`, eg. `/uploads/` from Admin → Tools → Media. Blank means pages without their own image have none. | -| Static pages (Retreats, Community, History…) | `site.json`: `pages`. The page's heading and intro read the same entry, so they can't drift. A new static page needs an entry. | +| The site's pages (Retreats, Community, History…) | Admin → Pages → Page management (`site_pages`). The page's heading and intro read the same row, so they can't drift. Disabled pages are `noindex` and out of the sitemap; hidden ones are a 404 to search engines. | | Records (events, organizations, teams, awards, people, posts) | The database: the record's name, then its tagline or first paragraph; its own image (an event's card background, else its logo; a post's cover; a person's photo; an organization's logo). SVGs aren't used as previews. | | Whether search may list it | `site.json` `robots.index` for the whole site; per record, published and listed is indexed, published but unlisted is `noindex`, anything else is a 404. `/admin` is always `noindex`. | diff --git a/docs/updating-data-in-code.md b/docs/updating-data-in-code.md index 23a1d96..574987a 100644 --- a/docs/updating-data-in-code.md +++ b/docs/updating-data-in-code.md @@ -36,7 +36,8 @@ what a dropdown in the admin editor says. | The **label** a dropdown shows in the admin | code | [one file](#renaming-what-a-dropdown-shows) | | The **list of allowed values** behind a fixed dropdown | database CHECK + code | [a migration and three files](#adding-removing-or-renaming-a-stored-value) | | Navigation, colors, the site banner, history decades, the map grid | code | [the file named below](#other-content-that-lives-in-code) | -| A static page's title and intro (also its search title and description), the site's name, description, preview image, icons, search indexing, privacy contact email | the database, over `site.json` | Admin → Panel → Site settings (superadmins). Blank uses `site.json`, which also holds the site's address and the pages' defaults. See `docs/seo.md` | +| A page's title and intro (also its search title and description), its address, Hidden and Disabled | the database (`site_pages`, 080) | Admin → Pages → Page management (admins and up), where new pages are made too | +| The site's name, description, preview image, icons, search indexing, privacy contact email | the database, over `site.json` | Admin → Panel → Site settings (superadmins). Blank uses `site.json`, which also holds the site's address. See `docs/seo.md` | | Uploaded images | disk + the `media` table | Admin → Tools → Media, or any image field. See `docs/media-uploads.md` | The rule of thumb from `CLAUDE.md`: data belongs in the database, @@ -278,7 +279,7 @@ The numbers band's "Number Source" dropdown works the same way: | What | File | Notes | | --- | --- | --- | -| Header and footer navigation, each page's sections (the header dropdowns, mobile menu and footer site map) | Admin → Pages → Navigation (the database, `075_site_nav.sql`); `src/navConfig.ts` is only the defaults the app starts from before it loads | Links: where each shows (header pages, header buttons, footer Get in Touch, footer bottom row), order, label, a header page set under another's menu, a filled button, new tab. Pages: title, intro and Hidden (Not found below viewer, out of the menus and the sitemap; `server/src/siteNav.js`). Each page's sections aren't listed there: they follow the page itself, through `src/lib/navSections.ts` (the site pages' sections from Admin → Pages; the front page's bands it shows, with `src/lib/frontPageBands.ts` giving each band's anchor and default heading). A new static page needs a route in `src/App.tsx` and an entry in `site.json`'s `pages` (its default title and intro, and what Navigation's Page select offers); a new page of sections also needs its id in `site_pages`' CHECK and a descriptor in both admin schemas, like Shop (075). | +| Header and footer navigation, each page's sections (the header dropdowns, mobile menu and footer site map) | Admin → Pages → Navigation (the database, `075_site_nav.sql`); `src/navConfig.ts` is only the defaults the app starts from before it loads | Links: where each shows (header pages, header buttons, footer Get in Touch, footer bottom row), order, label, a header page set under another's menu, a filled button, new tab. Each page's sections aren't listed there: they follow the page itself, through `src/lib/navSections.ts` (the site pages' sections from Admin → Pages; the front page's bands it shows, with `src/lib/frontPageBands.ts` giving each band's anchor and default heading). A new page is made in Page management, no code: it's a page of sections at the address given. | | Section titles, blurbs and colors on Feedback, Privacy, Terms | the page file in `src/pages/` | the `SECTIONS` array at the top. | | Site-wide announcement banner | `src/data/bannerConfig.ts` | `enabled: false` hides it. Bump `id` when the message changes, so people who dismissed the old one see the new one. | | History page decade headers | `src/data/historyDecades.ts` | Title, tagline and blurb per decade. | diff --git a/server/src/admin-crud.js b/server/src/admin-crud.js index c1c0461..5a3893b 100644 --- a/server/src/admin-crud.js +++ b/server/src/admin-crud.js @@ -411,6 +411,10 @@ export function deleteRow(db, entity, rawId) { } const id = normalizeId(entity, rawId); + // Records the site can't do without (the pages it draws in code). + if (entity.undeletable?.includes(id)) { + throw new HttpError(405, "The site needs this one: it can be hidden or disabled, not deleted."); + } const result = wrapDbErrors(() => db.prepare(`DELETE FROM ${entity.table} WHERE ${entity.idColumn} = ?`).run(id), ); diff --git a/server/src/admin-schema.js b/server/src/admin-schema.js index 31039af..a9c4689 100644 --- a/server/src/admin-schema.js +++ b/server/src/admin-schema.js @@ -21,6 +21,8 @@ on an extension (an organization's contacts) singleton the one id this entity ever has; the engine refuses create and delete (see front_page) + undeletable ids the engine refuses to delete (the pages the + site draws in code) check (db, id) => void, run after a save has written everything, inside its transaction: throw an HttpError to refuse it (site settings' colors) @@ -59,14 +61,7 @@ import { personTagTypes } from "./admin-schema/personTags.js"; import { tags } from "./admin-schema/tags.js"; import { contactTypes } from "./admin-schema/contactTypes.js"; import { redirects } from "./admin-schema/redirects.js"; -import { - communityPage, - retreatsPage, - resourcesPage, - organizationPage, - historyPage, - shopPage, -} from "./admin-schema/sitePages.js"; +import { pages } from "./admin-schema/sitePages.js"; export const ENTITIES = { organizations, @@ -81,12 +76,7 @@ export const ENTITIES = { timeline, front_page: frontPage, blog_posts: blogPosts, - community_page: communityPage, - retreats_page: retreatsPage, - resources_page: resourcesPage, - organization_page: organizationPage, - history_page: historyPage, - shop_page: shopPage, + pages, navigation: siteNav, site_settings: siteSettings, newsletters, @@ -116,6 +106,8 @@ export const OPTION_QUERIES = { // Link fields with `redirects: true` pick from these (068). redirects: "SELECT id, id || ' (' || target_url || ')' AS label FROM redirects ORDER BY id", blog_posts: "SELECT id, title AS label FROM blog_posts ORDER BY published_on DESC, title", + // Navigation's Under page: a page by its address (080). + site_pages: "SELECT path AS id, title || ' (' || path || ')' AS label FROM site_pages ORDER BY sort_order, title", // org_id rides along so the affiliation row can filter the list // down to teams of the organization it already names. diff --git a/server/src/admin-schema/siteNav.js b/server/src/admin-schema/siteNav.js index 2ac245a..23ed540 100644 --- a/server/src/admin-schema/siteNav.js +++ b/server/src/admin-schema/siteNav.js @@ -1,10 +1,9 @@ import { text, bool, enumeration } from "./columns.js"; /* ── Navigation (075_site_nav.sql) ─────────────────────────────── - Pages → Navigation: the header's and footer's links, in order, - and each static page's title, intro and whether it's hidden - (siteNav.js reads it for the site). Admins and up: it can take a - page off the site. */ + Pages → Navigation: the header's and footer's links, in order + (siteNav.js reads them for the site; the pages themselves are + Page management's, sitePages.js). Admins and up. */ export const siteNav = { key: "navigation", table: "site_nav", @@ -33,12 +32,5 @@ export const siteNav = { bool("new_tab"), ], }, - { - key: "pages", - table: "site_nav_pages", - owner: { column: "nav_id" }, - order: "sort_order", - columns: [text("path", { required: true }), text("title"), text("description"), bool("is_hidden")], - }, ], }; diff --git a/server/src/admin-schema/sitePages.js b/server/src/admin-schema/sitePages.js index 5a28fc1..bd402e3 100644 --- a/server/src/admin-schema/sitePages.js +++ b/server/src/admin-schema/sitePages.js @@ -1,18 +1,19 @@ -import { text, url, int, enumeration, featuredCardsChild, blocksChild } from "./columns.js"; +import { HttpError } from "../admin-crud.js"; +import { text, url, int, bool, enumeration, featuredCardsChild, blocksChild } from "./columns.js"; -/* ── The site's own pages (056_site_pages.sql) ─────────────────── +/* ── The site's pages (056_site_pages.sql, 080_page_registry.sql) ── - Community, Retreats, Resources, Organization, History and Shop - (075): one - site_pages row each, edited as its own singleton, with its - sections nested under it and each section's blocks under that + Pages → Page management: every page of the site, one site_pages + row each (its address, title, intro, Hidden and Disabled), with + its sections nested under it and each section's blocks under that (the blocks' items under them, as on any record). A section is either its blocks or a preset, a prebuilt part of the site - (SitePage.tsx draws both). + (SitePage.tsx draws both). New pages are made here. Community also carries the blog section's settings: the community_page row (same id) as an extension, and its pinned - posts, cards and feeds, all owned by that id. */ + posts, cards and feeds, all owned by that id; only for the page + whose id is community. */ const sectionsChild = { key: "sections", @@ -60,27 +61,62 @@ const sectionsChild = { ], }; -const sitePage = (id, more = {}) => ({ - key: `${id}_page`, + +/* Pages the site draws in code (src/pages/fixedPages.ts): they can be + renamed, moved, hidden or disabled, never deleted. */ +export const FIXED_PAGES = ["home", "give", "feedback", "request", "qr", "privacy", "terms"]; + +/* Addresses a page can't take: the admin, the API, the uploads, the + records' own pages and the account pages. */ +const RESERVED = [ + "admin", "api", "uploads", "assets", "pa", "go", + "events", "regions", "groups", "partners", "organizations", "teams", "awards", "people", "blog", "directory", + "sign-in", "account", "sitemap.xml", "robots.txt", +]; + +/* After a save: the address is one a page may have. */ +function checkPage(db, id) { + const page = db.prepare(`SELECT path FROM site_pages WHERE id = ?`).get(id); + const first = page?.path.split("/")[1]; + if (first && RESERVED.includes(first)) { + throw new HttpError(422, "Validation failed", { path: `/${first} belongs to another part of the site. Pick another address.` }); + } + if (id === "home" && page.path !== "/") throw new HttpError(422, "Validation failed", { path: "The front page stays at /." }); + if (id !== "home" && page.path === "/") throw new HttpError(422, "Validation failed", { path: "/ is the front page." }); +} + +const isCommunity = { column: "id", value: "community" }; + +export const pages = { + key: "pages", table: "site_pages", idColumn: "id", idKind: "slug", - singleton: id, concurrency: "updated_at", + undeletable: FIXED_PAGES, - list: { columns: ["id", "updated_at"], filters: [], search: [], order: "id" }, + list: { + columns: ["title", "path", "is_hidden", "is_disabled", "updated_at"], + filters: [], + search: ["title", "path"], + order: "sort_order, title", + }, - columns: [], - ...more, - children: [sectionsChild, ...(more.children ?? [])], -}); + columns: [ + text("path", { required: true }), + text("title", { required: true }), + text("description"), + bool("is_hidden"), + bool("is_disabled"), + int("sort_order"), + ], -export const communityPage = sitePage("community", { extensions: [ { key: "blog", table: "community_page", idColumn: "id", + when: isCommunity, columns: [ text("internal_title"), int("internal_slots"), @@ -91,27 +127,27 @@ export const communityPage = sitePage("community", { ], }, ], + children: [ + sectionsChild, { key: "pinned_posts", table: "community_page_pinned_posts", owner: { column: "page_id" }, order: "sort_order", + when: isCommunity, columns: [text("post_id", { required: true })], }, - featuredCardsChild("community_page"), + { ...featuredCardsChild("community_page"), when: isCommunity }, { key: "feeds", table: "community_page_feeds", owner: { column: "page_id" }, order: "sort_order", + when: isCommunity, columns: [url("url", { required: true }), text("label")], }, ], -}); -export const retreatsPage = sitePage("retreats"); -export const resourcesPage = sitePage("resources"); -export const organizationPage = sitePage("organization"); -export const historyPage = sitePage("history"); -export const shopPage = sitePage("shop"); + check: checkPage, +}; diff --git a/server/src/migrations/080_page_registry.sql b/server/src/migrations/080_page_registry.sql new file mode 100644 index 0000000..d0fd70a --- /dev/null +++ b/server/src/migrations/080_page_registry.sql @@ -0,0 +1,93 @@ +-- ═══════════════════════════════════════════════════════════════ +-- 080 PAGE REGISTRY +-- +-- Every page of the site is a site_pages row: its address, title +-- and intro (the page's heading and its search text), and two +-- switches, all edited in Pages → Page management, where new pages +-- are made too. site.json's "pages" and Navigation's page list +-- (site_nav_pages, 075) both move here and go: this is the one +-- place a page's words live. +-- +-- path '/retreats'; a new page's own, eg. '/library'. +-- Unique; '/' is the front page. +-- is_hidden Not found to everyone below viewer, out of the +-- menus and sitemap (siteNav.js) +-- is_disabled out of the menus, the sitemap and search; the +-- address still works +-- sort_order the order of the admin home's page cards +-- +-- A page is its sections (page_sections), except the few the site +-- still draws in code (src/pages/fixedPages.ts): the front page, +-- Feedback, Request, Give, QR codes, Privacy and Terms. Those take +-- their title and intro from here all the same, and can't be +-- deleted (admin-schema/pages.js). +-- +-- The id stays a slug, as before (page sections, the Community +-- blog's settings and the drafts key on it), so an existing page +-- keeps its id; its address can change. +-- ═══════════════════════════════════════════════════════════════ + +CREATE TABLE site_pages_new ( + id TEXT PRIMARY KEY + CONSTRAINT "A page's URL ID can use only lowercase letters, numbers and hyphens." + CHECK (id <> '' AND id NOT GLOB '*[^a-z0-9-]*'), + path TEXT NOT NULL UNIQUE + CONSTRAINT "A page's address starts with / and uses only lowercase letters, numbers, hyphens and /, eg. /library." + CHECK (path = '/' OR (path GLOB '/[a-z0-9]*' AND path NOT GLOB '*[^a-z0-9/-]*' AND path NOT GLOB '*/')), + title TEXT NOT NULL, + description TEXT, + is_hidden INTEGER NOT NULL DEFAULT 0 CHECK (is_hidden IN (0, 1)), + is_disabled INTEGER NOT NULL DEFAULT 0 CHECK (is_disabled IN (0, 1)), + sort_order INTEGER NOT NULL DEFAULT 0, + updated_at TEXT NOT NULL DEFAULT (datetime('now')) +) STRICT; + +INSERT INTO site_pages_new (id, path, title, description, sort_order) VALUES + ('home', '/', 'Home', NULL, 0), + ('retreats', '/retreats', 'Retreats', 'Retreats hosted by Next Generation of Unity, our regions, and our partners throughout the year.', 1), + ('community', '/community', 'Community', 'Groups, regions and the people who make up Next Generation of Unity.', 2), + ('resources', '/resources', 'Resources', 'Teachings, brand assets, and material for groups and partners.', 3), + ('organization', '/organization', 'Organization', 'Our mission, vision and values, the people who lead Next Generation of Unity, and how to reach us.', 4), + ('history', '/history', 'History', 'A near-complete timeline of Next Generation of Unity (NGU), and other Unity Young Adult programs.', 5), + ('shop', '/shop', 'Shop', 'Shirts, stickers and more from Next Generation of Unity. Every purchase supports our retreats and programs.', 6), + ('give', '/give', 'Giving', 'Support the work of Next Generation of Unity.', 7), + ('feedback', '/feedback', 'Feedback', 'Tell us what''s working, what isn''t, and what you''d like to see next.', 8), + ('request', '/request', 'Request', 'Ask for a blog post, an event, or a new or updated group, region, partner, team, award or person on the site.', 9), + ('qr', '/qr', 'QR Codes', 'Codes for flyers, slides and signs, pointing at any page on the site or any link, in your choice of colors.', 10), + ('privacy', '/privacy', 'Privacy Policy', 'How Next Generation of Unity collects, uses, and protects your information.', 11), + ('terms', '/terms', 'Terms of Service', 'The terms that apply when you use this site and our programs.', 12); + +-- Each page's sections' save time comes along. +UPDATE site_pages_new + SET updated_at = (SELECT updated_at FROM site_pages WHERE site_pages.id = site_pages_new.id) + WHERE id IN (SELECT id FROM site_pages); + +-- What Navigation (or before it Site settings) changed. +UPDATE site_pages_new + SET title = COALESCE((SELECT n.title FROM site_nav_pages n WHERE n.path = site_pages_new.path), title), + description = COALESCE((SELECT n.description FROM site_nav_pages n WHERE n.path = site_pages_new.path), description), + is_hidden = COALESCE((SELECT n.is_hidden FROM site_nav_pages n WHERE n.path = site_pages_new.path), is_hidden); + +DROP TABLE site_nav_pages; + +-- The admin edits every page as one entity now ('pages'), so a +-- page's draft (077) moves under it. +UPDATE drafts + SET entity = 'pages', record_id = substr(entity, 1, length(entity) - 5) + WHERE entity IN ('community_page', 'retreats_page', 'resources_page', 'organization_page', 'history_page', 'shop_page'); + +-- page_sections names site_pages; legacy mode leaves it alone +-- through the rename. +PRAGMA legacy_alter_table = ON; +DROP TABLE site_pages; +ALTER TABLE site_pages_new RENAME TO site_pages; +PRAGMA legacy_alter_table = OFF; + +CREATE INDEX site_pages_order_idx ON site_pages (sort_order); + +CREATE TRIGGER site_pages_touch +AFTER UPDATE ON site_pages +FOR EACH ROW WHEN new.updated_at = old.updated_at +BEGIN + UPDATE site_pages SET updated_at = datetime('now') WHERE id = new.id; +END; diff --git a/server/src/pageMeta.js b/server/src/pageMeta.js index 464cacc..5d8e85a 100644 --- a/server/src/pageMeta.js +++ b/server/src/pageMeta.js @@ -14,10 +14,11 @@ ── Where it comes from ── /site.json (SITE_CONFIG): the site's name, address, default description and image, icons, and each static page's title and - description. Laid over it: Panel → Site settings (the - site_settings table, 035) and Pages → Navigation's page titles - (site_nav_pages, 075), where anything set wins and anything - blank falls back to site.json. siteFor(db) does the merge. The + default description and image, and icons. Laid over it: Panel → + Site settings (the site_settings table, 035), where anything set + wins and anything blank falls back to site.json. siteFor(db) does + the merge. Each page's title and intro are its site_pages row's + (Pages → Page management, 080). The pages read the same merged values (renderPage writes them into the HTML as window.__SITE__, see src/lib/site.ts), so a heading and its search title can't drift. @@ -47,7 +48,7 @@ import { fileURLToPath } from "node:url"; import { loadBlocks, paragraphs } from "./shape.js"; import { themeCss } from "./theme.js"; import { driveReady } from "./googleService.js"; -import { hiddenFrom, hiddenPaths, navFor } from "./siteNav.js"; +import { allPages, hiddenFrom, navFor, pageAt } from "./siteNav.js"; const here = path.dirname(fileURLToPath(import.meta.url)); @@ -75,24 +76,15 @@ const origin = (site) => (site.url ?? "").replace(/\/$/, ""); /* site.json with the admin's Site settings laid over it: a value set there wins, a blank one falls back. indexing 'on' / 'off' overrides - robots.index for this database only. Page overrides (Pages → - Navigation) apply only to pages site.json knows. */ + robots.index for this database only. pages: every page's title + and intro, by path (site_pages). */ export function siteFor(db) { const base = loadSite(); const row = db.prepare(`SELECT * FROM site_settings WHERE id = 'site'`).get() ?? {}; - const pages = { ...(base.pages ?? {}) }; - const overrides = db - .prepare(`SELECT path, title, description FROM site_nav_pages WHERE nav_id = 'site'`) - .all(); - for (const page of overrides) { - const known = pages[page.path]; - if (!known) continue; - pages[page.path] = { - title: page.title || known.title, - description: page.description || known.description, - }; - } + const pages = Object.fromEntries( + allPages(db).map((page) => [page.path, { title: page.title, description: page.description ?? "" }]), + ); return { ...base, @@ -410,10 +402,17 @@ export function metaFor(db, rawPath, user = null) { // in particular, so never indexed or in the sitemap. if (ACCOUNT_PAGES[pathname]) return { ...meta, title: titled(site, ACCOUNT_PAGES[pathname]), noindex: true }; - const page = site.pages?.[pathname]; + // A page of the site (site_pages): hidden is Not found below + // viewer; disabled stays out of search. + const page = pageAt(db, pathname); if (page && hiddenFrom(db, user, pathname)) return notFound(meta); if (page) { - return { ...meta, title: titled(site, page.title), description: plainText(page.description) ?? meta.description }; + return { + ...meta, + title: titled(site, page.title), + description: plainText(page.description) ?? meta.description, + noindex: page.is_disabled === 1, + }; } // An event's schedule presentation (SchedulePresent.tsx): the @@ -558,13 +557,13 @@ export function sitemap(db) { const site = siteFor(db); const base = origin(site); const day = (value) => (value ? String(value).slice(0, 10) : null); - const hidden = hiddenPaths(db); const entries = [ { loc: "/" }, - ...Object.keys(site.pages ?? {}) - .filter((loc) => !hidden.has(loc)) - .map((loc) => ({ loc })), + // Pages that are neither hidden nor disabled. + ...allPages(db) + .filter((page) => page.path !== "/" && page.is_hidden !== 1 && page.is_disabled !== 1) + .map((page) => ({ loc: page.path })), ...db .prepare(`SELECT id, updated_at FROM events WHERE is_published = 1 AND is_listed = 1`) .all() diff --git a/server/src/routes/sitePages.js b/server/src/routes/sitePages.js index bb22705..491ab1d 100644 --- a/server/src/routes/sitePages.js +++ b/server/src/routes/sitePages.js @@ -4,9 +4,11 @@ GET /nav this visitor's header and footer links and the hidden pages (siteNav.js); not cached, since it depends on who's signed in - GET /site-pages every site page's section headings, for - the header's dropdowns and the side nav - GET /site-pages/:id one page's sections, in order: heading, + GET /site-pages every page's section headings, by the + page's path, for the header's dropdowns + and the side nav + GET /site-pages/:id one page's title and intro and its + sections, in order: heading, accent, preset (and an events preset's filter and view), and its blocks; Not found for a hidden page, below viewer @@ -18,7 +20,7 @@ import { Hono } from "hono"; import { currentUser } from "../auth.js"; -import { hiddenPaths, navFor, seesHidden } from "../siteNav.js"; +import { navFor, seesHidden } from "../siteNav.js"; import { NO_STORE, json, loadBlocks } from "../shape.js"; const sitePages = new Hono(); @@ -31,19 +33,23 @@ sitePages.get("/nav", (c) => { sitePages.get("/site-pages", (c) => { const rows = c .get("db") - .prepare(`SELECT page_id, anchor, title FROM page_sections ORDER BY page_id, sort_order, id`) + .prepare( + `SELECT p.path, s.anchor, s.title FROM page_sections s JOIN site_pages p ON p.id = s.page_id + ORDER BY p.path, s.sort_order, s.id`, + ) .all(); const pages = {}; - for (const row of rows) (pages[row.page_id] ??= []).push({ anchor: row.anchor, title: row.title }); + for (const row of rows) (pages[row.path] ??= []).push({ anchor: row.anchor, title: row.title }); return json(c, { pages }); }); sitePages.get("/site-pages/:id", (c) => { const db = c.get("db"); const id = c.req.param("id"); - const hidden = hiddenPaths(db).has(`/${id}`); - if (!db.prepare(`SELECT 1 FROM site_pages WHERE id = ?`).get(id) || (hidden && !seesHidden(currentUser(db, c)))) { + const found = db.prepare(`SELECT title, description, is_hidden FROM site_pages WHERE id = ?`).get(id); + const hidden = found?.is_hidden === 1; + if (!found || (hidden && !seesHidden(currentUser(db, c)))) { return c.json({ error: "No such page." }, 404); } @@ -81,6 +87,8 @@ sitePages.get("/site-pages/:id", (c) => { return send({ page: { id, + title: found.title, + description: found.description, sections: rows.map(({ id: sectionId, ...section }) => ({ ...section, blocks: blocks.get(String(sectionId)) ?? [], diff --git a/server/src/siteNav.js b/server/src/siteNav.js index b06dbf6..b707b7c 100644 --- a/server/src/siteNav.js +++ b/server/src/siteNav.js @@ -1,16 +1,21 @@ /* ═══════════════════════════════════════════════════════════════ - SITE NAVIGATION + SITE NAVIGATION AND PAGES - Pages → Navigation (075_site_nav.sql): the header's and footer's - links, and which static pages are hidden. Read by pageMeta.js - (window.__SITE__, the page's status, the sitemap) and served as - GET /api/nav for the app (routes/sitePages.js). + The site's pages (site_pages, 080_page_registry.sql: Pages → + Page management) and the header's and footer's links (Pages → + Navigation, 075). Read by pageMeta.js (window.__SITE__, each + page's status and title, the sitemap) and served as GET /api/nav + for the app (routes/sitePages.js). - A hidden page answers Not found to anyone below viewer, and its - links are left out of what they're sent; a viewer and up sees - both, and the page says it's hidden (Layout.tsx). Who's asking - is the session cookie, so the same page can be hidden from one - visitor and shown to the next: the HTML is no-cache already. + hidden Not found to anyone below viewer, and left out of + what they're sent, links included; a viewer and up + sees it, and the page says it's hidden (Layout.tsx) + disabled out of the menus, the sitemap and search, for + everyone; its address still works + + Who's asking is the session cookie, so the same page can be + hidden from one visitor and shown to the next: the HTML is + no-cache already. ═══════════════════════════════════════════════════════════════ */ import { hasRole } from "./auth.js"; @@ -20,38 +25,63 @@ export const SEES_HIDDEN = "viewer"; export const seesHidden = (user) => hasRole(user, SEES_HIDDEN); +/* A link's page: its path without the #section or ?query, or null + for an address off the site. */ +export const pageOf = (href) => + /^\//.test(href) ? href.split(/[?#]/)[0].replace(/(.)\/+$/, "$1") || "/" : null; + +/* Every page, in the admin's order. */ +export function allPages(db) { + return db + .prepare( + `SELECT id, path, title, description, is_hidden, is_disabled + FROM site_pages ORDER BY sort_order, title`, + ) + .all(); +} + +/* The page at this path, or null. */ +export function pageAt(db, path) { + return ( + db + .prepare(`SELECT id, path, title, description, is_hidden, is_disabled FROM site_pages WHERE path = ?`) + .get(pageOf(path) ?? path) ?? null + ); +} + /* The paths whose pages are hidden, eg. '/shop'. */ export function hiddenPaths(db) { return new Set( db - .prepare(`SELECT path FROM site_nav_pages WHERE nav_id = 'site' AND is_hidden = 1`) + .prepare(`SELECT path FROM site_pages WHERE is_hidden = 1`) .all() .map((row) => row.path), ); } -/* A link's page: its path without the #section or ?query, or null - for an address off the site. */ -const pageOf = (href) => (/^\//.test(href) ? href.split(/[?#]/)[0].replace(/(.)\/+$/, "$1") : null); - /* Whether this path's page is one the user can't see. */ export function hiddenFrom(db, user, pathname) { return !seesHidden(user) && hiddenPaths(db).has(pageOf(pathname)); } -/* What the app draws its menus from: every link this user may - follow, and the hidden pages' paths (so the app can answer Not - found, or say a page is hidden, without asking again). */ +/* What the app draws its menus and pages from: every page this user + may open, every link they may follow (none to a disabled page), + and which pages are hidden (so the app can say so). */ export function navFor(db, user) { - const hidden = hiddenPaths(db); const sees = seesHidden(user); + const pages = allPages(db).filter((page) => sees || page.is_hidden !== 1); + const hidden = new Set(allPages(db).filter((p) => p.is_hidden === 1).map((p) => p.path)); + const disabled = new Set(pages.filter((p) => p.is_disabled === 1).map((p) => p.path)); const links = db .prepare( `SELECT place, label, path, parent_path, style, new_tab FROM site_nav_links WHERE nav_id = 'site' ORDER BY sort_order, id`, ) .all() - .filter((link) => sees || !hidden.has(pageOf(link.path))) + .filter((link) => { + const page = pageOf(link.path); + return !disabled.has(page) && (sees || !hidden.has(page)); + }) .map((link) => ({ place: link.place, label: link.label, @@ -61,5 +91,17 @@ export function navFor(db, user) { newTab: link.new_tab === 1, })); - return { links, hidden: [...hidden], seesHidden: sees }; + return { + links, + pages: pages.map((page) => ({ + id: page.id, + path: page.path, + title: page.title, + description: page.description, + hidden: page.is_hidden === 1, + disabled: page.is_disabled === 1, + })), + hidden: sees ? [...hidden] : [], + seesHidden: sees, + }; } diff --git a/site.json b/site.json index 8a717b6..4c36c7c 100644 --- a/site.json +++ b/site.json @@ -12,55 +12,5 @@ "accessibility": { "addBypassLinks": false, "ignoreReducedMotion": false - }, - "pages": { - "/retreats": { - "title": "Retreats", - "description": "Retreats hosted by Next Generation of Unity, our regions, and our partners throughout the year." - }, - "/community": { - "title": "Community", - "description": "Groups, regions and the people who make up Next Generation of Unity." - }, - "/organization": { - "title": "Organization", - "description": "Our mission, vision and values, the people who lead Next Generation of Unity, and how to reach us." - }, - "/resources": { - "title": "Resources", - "description": "Teachings, brand assets, and material for groups and partners." - }, - "/history": { - "title": "History", - "description": "A near-complete timeline of Next Generation of Unity (NGU), and other Unity Young Adult programs." - }, - "/feedback": { - "title": "Feedback", - "description": "Tell us what's working, what isn't, and what you'd like to see next." - }, - "/request": { - "title": "Request", - "description": "Ask for a blog post, an event, or a new or updated group, region, partner, team, award or person on the site." - }, - "/qr": { - "title": "QR Codes", - "description": "Codes for flyers, slides and signs, pointing at any page on the site or any link, in your choice of colors." - }, - "/give": { - "title": "Giving", - "description": "Support the work of Next Generation of Unity." - }, - "/privacy": { - "title": "Privacy Policy", - "description": "How Next Generation of Unity collects, uses, and protects your information." - }, - "/shop": { - "title": "Shop", - "description": "Shirts, stickers and more from Next Generation of Unity. Every purchase supports our retreats and programs." - }, - "/terms": { - "title": "Terms of Service", - "description": "The terms that apply when you use this site and our programs." - } } } diff --git a/src/App.tsx b/src/App.tsx index 83bb43b..1f4b15c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -49,16 +49,9 @@ const lazyPage = (load) => throw err }), ) -// Community, Retreats, Resources, Organization, History and Shop: -// each built in the admin from sections. -const SitePage = lazyPage(() => import("./pages/SitePage.tsx")) -const Feedback = lazyPage(() => import("./pages/Feedback.tsx")) -const Request = lazyPage(() => import("./pages/Request.tsx")) -const Giving = lazyPage(() => import("./pages/Giving.tsx")) -const QrCodes = lazyPage(() => import("./pages/QrCodes.tsx")) -const Privacy = lazyPage(() => import("./pages/Privacy.tsx")) -const Terms = lazyPage(() => import("./pages/Terms.tsx")) -const NotFound = lazyPage(() => import("./pages/NotFound.tsx")) +// Every page at its address (Pages → Page management): its sections, +// or one of the few the site draws in code (fixedPages.ts). +const PageAtPath = lazyPage(() => import("./pages/PageAtPath.tsx")) // Profile accounts (076): signing in, an invite's welcome, the profile. const SignIn = lazyPage(() => import("./pages/SignIn.tsx")) const AccountWelcome = lazyPage(() => import("./pages/AccountWelcome.tsx")) @@ -100,9 +93,7 @@ export default function App() { {/* Layout renders the nav once and swaps page content into */} }> } /> - } /> } /> - } /> } /> } /> } /> @@ -112,20 +103,11 @@ export default function App() { } /> } /> } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> } /> } /> } /> - } /> + {/* Every page of the site: Pages → Page management (PageAtPath). */} + } /> {/* A schedule as a slideshow for a screen: full screen, no Layout. */} = { organizations, @@ -55,12 +48,7 @@ export const ADMIN_ENTITIES: Record = { timeline, front_page: frontPage, blog_posts: blogPosts, - community_page: communityPage, - retreats_page: retreatsPage, - resources_page: resourcesPage, - organization_page: organizationPage, - history_page: historyPage, - shop_page: shopPage, + pages, navigation: siteNav, site_settings: siteSettings, }; @@ -79,12 +67,7 @@ export const PREVIEW_PATHS: Record string | null> = { timeline: () => "/history", front_page: () => "/", blog_posts: (row) => blogHref(row.id), - community_page: () => "/community", - retreats_page: () => "/retreats", - resources_page: () => "/resources", - organization_page: () => "/organization", - history_page: () => "/history", - shop_page: () => "/shop", + pages: (row) => row.path || null, // The menus are on every page. navigation: () => "/", site_settings: () => "/", diff --git a/src/lib/adminSchema/siteNav.ts b/src/lib/adminSchema/siteNav.ts index 4bd56ed..84abc9f 100644 --- a/src/lib/adminSchema/siteNav.ts +++ b/src/lib/adminSchema/siteNav.ts @@ -1,16 +1,10 @@ -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: + Pages → Navigation: the header's and footer's links. The pages + themselves (titles, intros, Hidden, Disabled) are Page + management's (sitePages.ts). Admins and up. 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"], @@ -36,7 +30,7 @@ export const siteNav = { { 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).", + 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, and one to a disabled page to no one. 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 }, @@ -54,7 +48,7 @@ export const siteNav = { path: "parent_path", label: "Under page", widget: "select", - options: [["/", "Home (/)"], ...SITE_PAGES], + optionsFrom: "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" }, @@ -70,35 +64,5 @@ export const siteNav = { { 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), - }, - ], - }, ], }; diff --git a/src/lib/adminSchema/sitePages.ts b/src/lib/adminSchema/sitePages.ts index 5d559a5..9200b67 100644 --- a/src/lib/adminSchema/sitePages.ts +++ b/src/lib/adminSchema/sitePages.ts @@ -1,6 +1,6 @@ -/* ── The site's own pages (056_site_pages.sql) ─────────────────── - Pages → Community, Retreats, Resources, Organization, History, - Shop (075): +/* ── The site's pages (056_site_pages.sql, 080_page_registry.sql) ── + Pages → Page management: every page, its address, title, intro, + Hidden and Disabled, and new pages made here. 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 @@ -8,7 +8,8 @@ src/pages/SitePage.tsx. The preset values are the CHECK list on page_sections.preset; - each page offers the ones that belong on it. */ + every page offers them all. The Community blog's settings show on + the Community page only (its id), for now. */ import { FEATURED_KINDS, featuredCardsChild, blocksChild } from "./shared.ts"; @@ -162,26 +163,77 @@ const sectionsChild = (presets: string[]) => ({ ], }); -const sitePage = (id: string, label: string, presets: string[], more: Record = {}) => ({ - key: `${id}_page`, - label, - singular: label.toLowerCase(), - idLabel: "Page", - singleton: id, +const COMMUNITY = { path: "id", value: "community" }; +const ALL_PRESETS = Object.keys(PRESETS); - list: { columns: [], filters: [] }, +/* The pages the site draws in code (src/pages/fixedPages.ts, and the + front page): no sections of their own yet. */ +export const FIXED_PAGE_IDS = ["home", "give", "feedback", "request", "qr", "privacy", "terms"]; +const isFixed = (row) => FIXED_PAGE_IDS.includes(row?.id); - groups: [], - ...more, - children: [sectionsChild(presets), ...(more.children ?? [])], -}); +const communityGroups = (groups) => groups.map((group) => ({ ...group, when: COMMUNITY })); +const communityChildren = (children) => children.map((child) => ({ ...child, when: COMMUNITY })); -export const communityPage = sitePage( - "community", - "Community page", - ["community_blog", "group_map", "region_list", "partner_list", "people_directory"], - { - groups: [ +export const pages = { + key: "pages", + label: "Page management", + singular: "page", + idLabel: "URL ID", + slugFrom: "title", + // Every page's address, title, intro and switches, then its own + // sections. The fixed pages (and the front page, edited in Front + // page) have no sections here. + list: { + columns: [ + { key: "title", label: "Page", primary: true }, + { key: "path", label: "Address" }, + { key: "is_hidden", label: "Hidden", widget: "bool" }, + { key: "is_disabled", label: "Disabled", widget: "bool" }, + ], + filters: [], + }, + + groups: [ + { + legend: "The page", + fields: [ + { path: "title", label: "Title", required: true, help: "The page's heading, and its title in search and the browser tab, eg. Library" }, + { + path: "path", + label: "Address", + required: true, + help: "Where it lives on the site, eg. /library. Lowercase letters, numbers, hyphens and /. Changing it breaks old links: update Navigation's too.", + }, + { path: "description", label: "Intro", widget: "textarea", full: true, help: "The line under the title, and its description in search." }, + { + path: "is_hidden", + label: "Hidden", + widget: "checkbox", + help: "Not found to everyone but signed-in admin accounts, eg. a page that isn't done. Out of the menus and the sitemap.", + }, + { + path: "is_disabled", + label: "Disabled", + widget: "checkbox", + help: "Out of the menus, the sitemap and search; its address still works for anyone with the link.", + }, + { path: "sort_order", label: "Order", widget: "number", help: "Where its card sits on the admin home, lowest first. Default: 0" }, + ], + }, + { + legend: "Its content", + note: "The front page's content is edited in Pages → Front page: its hero, and the bands it shows.", + when: { test: (row) => row?.id === "home" }, + fields: [], + }, + { + legend: "Its content", + note: "This page's content is built into the site (a form, an embed or set text), so it has no sections to edit here yet. Its title, intro, address and switches above are yours.", + when: { test: (row) => isFixed(row) && row?.id !== "home" }, + fields: [], + }, + ...communityGroups( + [ { legend: "Community blog: our posts", note: "For the Community blog preset. Pinned posts first, then the newest published, listed posts, up to the number of slots.", @@ -200,8 +252,14 @@ export const communityPage = sitePage( { path: "blog.external_label", label: "Button text", help: "Default: Read more on Substack" }, ], }, - ], - children: [ + ] + ), + ], + + children: [ + { ...sectionsChild(ALL_PRESETS), when: { test: (row) => !isFixed(row) } }, + ...communityChildren( + [ { key: "pinned_posts", label: "Community blog: pinned posts (ours)", @@ -244,12 +302,7 @@ export const communityPage = sitePage( { path: "label", label: "Source name", help: "Shown on its cards. Default: the feed's own title" }, ], }, - ], - }, -); - -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", []); + ] + ), + ], +}; diff --git a/src/lib/navSections.ts b/src/lib/navSections.ts index 0ffe20c..a099eb4 100644 --- a/src/lib/navSections.ts +++ b/src/lib/navSections.ts @@ -24,7 +24,7 @@ export function useNavSections(): (path: string) => NavSection[] { return useCallback( (path: string) => { if (path !== '/') { - return (sitePages?.[path.slice(1)] ?? []).map((section) => ({ + return (sitePages?.[path] ?? []).map((section) => ({ label: section.title, hash: `#${section.anchor}`, })) diff --git a/src/lib/site.ts b/src/lib/site.ts index 6c223c9..5702360 100644 --- a/src/lib/site.ts +++ b/src/lib/site.ts @@ -10,8 +10,9 @@ serves the plain index.html, it isn't there and site.json alone applies. - A page's visible heading and intro and its search title and - description come from the same values, so they can't drift. + A page's heading and intro are its site_pages row's (Pages → Page + management), which also give its search title and description, so + they can't drift: useSiteNav and the page's own data carry them. SITE_ORIGIN is the public address of the live site. It's used where a URL has to leave the browser and still work: a printed QR @@ -22,9 +23,7 @@ import siteConfiguration from '../../site.json' -type PageText = { title: string; description: string } - -type SiteText = { title?: string; pages?: Record; privacyEmail?: string; requestFiles?: boolean } +type SiteText = { title?: string; privacyEmail?: string; requestFiles?: boolean } /* What the server wrote into the page, if it did. */ const fromServer: SiteText = @@ -46,18 +45,6 @@ export const REQUEST_FILES: boolean = fromServer.requestFiles ?? true /** A site path as a full URL on the live site. */ export const siteUrl = (path: string): string => new URL(path, SITE_ORIGIN).href -const PAGES: Record = { ...siteConfiguration.pages, ...fromServer.pages } - -/* Every static page's path and text, for the not-found page's suggestions. */ -export const SITE_PAGES: Readonly> = PAGES - -/** A static page's title and intro, from site.json's "pages". */ -export function sitePage(path: string): PageText { - const page = PAGES[path] - if (!page) throw new Error(`site.json has no "pages" entry for ${path}`) - return page -} - /** The browser tab's title for a page: "Retreats | Next Generation * of Unity", or the site name alone for the home page. */ export const documentTitle = (title?: string | null): string => diff --git a/src/lib/useSiteNav.ts b/src/lib/useSiteNav.ts index 8d7fa8d..06fe0bc 100644 --- a/src/lib/useSiteNav.ts +++ b/src/lib/useSiteNav.ts @@ -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]) } diff --git a/src/lib/useSitePages.ts b/src/lib/useSitePages.ts index 2b654ce..8c64dbc 100644 --- a/src/lib/useSitePages.ts +++ b/src/lib/useSitePages.ts @@ -1,7 +1,7 @@ -/* The site's own pages (Community, Retreats, Resources, Organization, - History), built in the admin from sections: GET /site-pages/:id - for one page's sections, GET /site-pages for every page's section - headings (the header's dropdowns, the footer, the side nav). */ +/* The site's pages of sections (Pages → Page management): GET + /site-pages/:id for one page's title, intro and sections, GET + /site-pages for every page's section headings by the page's path + (the header's dropdowns, the footer, the side nav). */ import { useRecord, type Resource } from './useRecord.ts' import type { ContentBlock } from './useContent.ts' @@ -24,7 +24,7 @@ export type SitePageSection = { blocks: ContentBlock[] } -export const useSitePage = (id: string): Resource<{ id: string; sections: SitePageSection[] }> => +export const useSitePage = (id: string): Resource<{ id: string; title: string; description: string | null; sections: SitePageSection[] }> => useRecord(`/site-pages/${id}`, 'page') export const useSitePageHeadings = (): Resource>> => diff --git a/src/pages/Feedback.tsx b/src/pages/Feedback.tsx index f082940..55af93e 100644 --- a/src/pages/Feedback.tsx +++ b/src/pages/Feedback.tsx @@ -1,10 +1,8 @@ import PageShell from "../components/PageShell.tsx"; -import { sitePage } from "../lib/site.ts"; +import type { PageText } from "./fixedPages.ts"; import FeedbackForm from "./sections/FeedbackForm.tsx"; import { BRAND } from "../lib/color.ts" -/* Title and intro: site.json, which also gives the search metadata. */ -const PAGE = sitePage("/feedback"); /* ═══════════════════════════════════════════════════════════════ Feedback page. @@ -36,11 +34,12 @@ const SECTIONS = [ }, ]; -export default function Feedback() { +/* Its title and intro: its site_pages row (Pages → Page management). */ +export default function Feedback({ page: PAGE }: { page: PageText }) { return ( ); diff --git a/src/pages/Giving.tsx b/src/pages/Giving.tsx index 5ae0f89..5186a9f 100644 --- a/src/pages/Giving.tsx +++ b/src/pages/Giving.tsx @@ -1,10 +1,8 @@ import { useEffect } from "react"; import PageShell from "../components/PageShell.tsx"; -import { sitePage } from "../lib/site.ts"; +import type { PageText } from "./fixedPages.ts"; import { BRAND } from "../lib/color.ts" -/* Title and intro: site.json, which also gives the search metadata. */ -const PAGE = sitePage("/give"); const GIVING_URL = "https://ngu.churchcenteronline.com/giving?open-in-church-center-modal=true"; @@ -72,7 +70,8 @@ function GivingPanel() { PAGE ═══════════════════════════════════════════════════════════════ */ -export default function GivingPage() { +/* Its title and intro: its site_pages row (Pages → Page management). */ +export default function GivingPage({ page: PAGE }: { page: PageText }) { useChurchCenterModal(); const sections = [ @@ -89,7 +88,7 @@ export default function GivingPage() { return ( ); diff --git a/src/pages/NotFound.tsx b/src/pages/NotFound.tsx index aa061fd..9bd628f 100644 --- a/src/pages/NotFound.tsx +++ b/src/pages/NotFound.tsx @@ -2,7 +2,7 @@ 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 + 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. @@ -18,8 +18,7 @@ import { useMemo } from 'react' import { Link, useLocation } from 'react-router-dom' import PageShell from '../components/PageShell.tsx' -import { useSiteNav } from '../lib/useSiteNav.ts' -import { SITE_PAGES } from '../lib/site.ts' +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' @@ -36,12 +35,12 @@ const ORG_KIND_LABEL: Record = { /* 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, isHidden: (path: string) => boolean): Candidate[] { - const pages: Candidate[] = Object.entries(SITE_PAGES).filter(([path]) => !isHidden(path)).map(([path, page]) => ({ - href: path, +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: [path.slice(1), page.title], + keys: [page.path.slice(1), page.title], })) if (!directory) return pages @@ -66,10 +65,10 @@ function candidates(directory: Directory | null, isHidden: (path: string) => boo export default function NotFound() { const { pathname } = useLocation() const { data: directory, loading } = useDirectory() - const { main: pages, isHidden } = useSiteNav() + const { main: pages, pages: sitePages } = useSiteNav() const matches = useMemo( - () => suggest(pathname, candidates(directory ?? null, isHidden)), - [pathname, directory, isHidden], + () => suggest(pathname, candidates(directory ?? null, sitePages)), + [pathname, directory, sitePages], ) const reading = useReadingMode() diff --git a/src/pages/PageAtPath.tsx b/src/pages/PageAtPath.tsx new file mode 100644 index 0000000..90ba930 --- /dev/null +++ b/src/pages/PageAtPath.tsx @@ -0,0 +1,31 @@ +/* ═══════════════════════════════════════════════════════════════ + PAGE AT PATH: any address the record routes don't take + + Pages → Page management decides what's where: the site_pages row + at this path (useSiteNav) is drawn by its code when it's one of + the fixed pages (fixedPages.ts), or as its sections (SitePage). + No page there (or a hidden one, below viewer, which isn't sent): + Not found. + ═══════════════════════════════════════════════════════════════ */ + +import { useLocation } from 'react-router-dom' + +import { useSiteNav } from '../lib/useSiteNav.ts' +import { FIXED_PAGES } from './fixedPages.ts' +import NotFound from './NotFound.tsx' +import SitePage from './SitePage.tsx' + +export default function PageAtPath() { + const { pathname } = useLocation() + const { ready, pageAt } = useSiteNav() + // Before the pages arrive (the dev server's first moment), nothing + // rather than a Not found that turns into the page. + if (!ready) return null + + const page = pageAt(pathname) + if (!page || page.path === '/') return + + const Fixed = FIXED_PAGES[page.id] + if (Fixed) return + return +} diff --git a/src/pages/Privacy.tsx b/src/pages/Privacy.tsx index b0213a4..ca8c435 100644 --- a/src/pages/Privacy.tsx +++ b/src/pages/Privacy.tsx @@ -3,12 +3,11 @@ import { Link } from "react-router-dom"; import LegalText, { type LegalPart } from "../components/LegalText.tsx"; import PageShell from "../components/PageShell.tsx"; import { DATA_REQUEST } from "../data/feedbackTypes.ts"; -import { PRIVACY_EMAIL, sitePage } from "../lib/site.ts"; +import { PRIVACY_EMAIL } from "../lib/site.ts"; +import type { PageText } from "./fixedPages.ts"; import FeedbackForm from "./sections/FeedbackForm.tsx"; import { BRAND } from "../lib/color.ts" -/* Title and intro: site.json, which also gives the search metadata. */ -const PAGE = sitePage("/privacy"); /* ═══════════════════════════════════════════════════════════════ Privacy policy, cookie notice included. @@ -210,6 +209,7 @@ const SECTIONS = [ }, ]; -export default function PrivacyPage() { - return ; +/* Its title and intro: its site_pages row (Pages → Page management). */ +export default function PrivacyPage({ page: PAGE }: { page: PageText }) { + return ; } diff --git a/src/pages/QrCodes.tsx b/src/pages/QrCodes.tsx index 566c72a..5298a13 100644 --- a/src/pages/QrCodes.tsx +++ b/src/pages/QrCodes.tsx @@ -1,10 +1,8 @@ import PageShell from '../components/PageShell.tsx' -import { sitePage } from '../lib/site.ts' +import type { PageText } from './fixedPages.ts' import QrCodeMaker from './sections/QrCodeMaker.tsx' import { BRAND } from '../lib/color.ts' -/* Title and intro: site.json, which also gives the search metadata. */ -const PAGE = sitePage('/qr') /* ═══════════════════════════════════════════════════════════════ QR CODES PAGE: /qr @@ -30,11 +28,12 @@ const SECTIONS = [ }, ] -export default function QrCodes() { +/* Its title and intro: its site_pages row (Pages → Page management). */ +export default function QrCodes({ page: PAGE }: { page: PageText }) { return ( ) diff --git a/src/pages/Request.tsx b/src/pages/Request.tsx index 451b5b0..981cf72 100644 --- a/src/pages/Request.tsx +++ b/src/pages/Request.tsx @@ -1,10 +1,8 @@ import PageShell from "../components/PageShell.tsx"; -import { sitePage } from "../lib/site.ts"; +import type { PageText } from "./fixedPages.ts"; import RequestForm from "./sections/RequestForm.tsx"; import { BRAND } from "../lib/color.ts"; -/* Title and intro: site.json, which also gives the search metadata. */ -const PAGE = sitePage("/request"); /* ═══════════════════════════════════════════════════════════════ Request page: ask for something to be added to the site or @@ -27,6 +25,7 @@ const SECTIONS = [ }, ]; -export default function Request() { - return ; +/* Its title and intro: its site_pages row (Pages → Page management). */ +export default function Request({ page: PAGE }: { page: PageText }) { + return ; } diff --git a/src/pages/SitePage.tsx b/src/pages/SitePage.tsx index 8b8f140..572e7f4 100644 --- a/src/pages/SitePage.tsx +++ b/src/pages/SitePage.tsx @@ -8,8 +8,8 @@ the site, from PRESETS below. A section with neither says it's coming (ComingSoon) rather than showing a heading over nothing. - The title and intro are site.json's, which also gives the search - metadata. + The title and intro are its site_pages row's (Pages → Page + management), which also give the search metadata. ═══════════════════════════════════════════════════════════════ */ import { useEffect } from 'react' @@ -18,7 +18,7 @@ import { useLocation } from 'react-router-dom' import PageShell from '../components/PageShell.tsx' import ComingSoon from '../components/ComingSoon.tsx' import ContentBlocks from '../components/ContentBlocks.tsx' -import { sitePage } from '../lib/site.ts' +import { useSiteNav } from '../lib/useSiteNav.ts' import { useSectionManifest } from '../lib/sections.tsx' import { useSitePage, type SitePageSection } from '../lib/useSitePages.ts' import { useHistory } from '../lib/useHistory.ts' @@ -97,10 +97,12 @@ const PRESETS: Record Record> } export default function SitePage({ id }: { id: string }) { - const PAGE = sitePage(`/${id}`) const { data: page, loading, error } = useSitePage(id) + // Its title and intro: its own data, or the nav's until that comes. + const known = useSiteNav().pages.find((p) => p.id === id) + const PAGE = { title: page?.title ?? known?.title ?? '', description: page?.description ?? known?.description ?? undefined } - if (page) return + if (page) return return ( <> diff --git a/src/pages/Terms.tsx b/src/pages/Terms.tsx index 2a2f7c0..4ec0491 100644 --- a/src/pages/Terms.tsx +++ b/src/pages/Terms.tsx @@ -2,11 +2,9 @@ import { Link } from "react-router-dom"; import LegalText, { type LegalPart } from "../components/LegalText.tsx"; import PageShell from "../components/PageShell.tsx"; -import { sitePage } from "../lib/site.ts"; +import type { PageText } from "./fixedPages.ts"; import { BRAND } from "../lib/color.ts" -/* Title and intro: site.json, which also gives the search metadata. */ -const PAGE = sitePage("/terms"); /* Change the date when the wording changes. */ const LAST_UPDATED = "September 28, 2026"; @@ -88,6 +86,7 @@ const SECTIONS = [ }, ]; -export default function TermsPage() { - return ; +/* Its title and intro: its site_pages row (Pages → Page management). */ +export default function TermsPage({ page: PAGE }: { page: PageText }) { + return ; } diff --git a/src/pages/admin/AdminHome.tsx b/src/pages/admin/AdminHome.tsx index 232bc70..a32ed95 100644 --- a/src/pages/admin/AdminHome.tsx +++ b/src/pages/admin/AdminHome.tsx @@ -23,7 +23,9 @@ ═══════════════════════════════════════════════════════════════ */ import { ArrowRight, ArrowUpRight } from "@phosphor-icons/react"; +import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; +import { get } from "../../lib/api.ts"; import { useAuth } from "../../lib/auth.tsx"; import { useWideAdminPage } from "../../lib/adminWidth.tsx"; import { SITE_VERSION, VERSION_NAME } from "../../lib/version.ts"; @@ -40,6 +42,8 @@ const tintOf = (color: string) => `color-mix(in srgb, ${color} 12%, var(--color- function NavCard({ item, color }) { const to = target(item); + // The group's banner (Page management): the whole row, a stronger fill. + const banner = Boolean(item.banner); // Drop the child that just repeats the card's own destination: // "All organizations" under Organizations. @@ -47,11 +51,13 @@ function NavCard({ item, color }) { return (
-

+

([]); + useEffect(() => { + get("/admin/pages?limit=200", { ttl: 0 }) + .then((list) => + setCards( + list.rows.map((page) => ({ + to: page.id === "home" ? "/admin/front_page" : `/admin/pages/${page.id}`, + label: page.title, + blurb: [page.path, page.is_hidden ? "Hidden" : null, page.is_disabled ? "Disabled" : null] + .filter(Boolean) + .join(" · "), + })), + ), + ) + .catch(() => setCards([])); + }, []); + return cards; +} + export default function AdminHome() { const { user } = useAuth(); const role = ROLE_LABELS[user?.role] ?? user?.role; useWideAdminPage(); + const pageCards = usePageCards(); return (
@@ -142,9 +171,16 @@ export default function AdminHome() { {GROUPS.map(({ nav, color }) => ( - {visibleItems(nav.children, user).map((item) => ( - - ))} + {visibleItems(nav.children, user) + .filter((item) => !item.menuOnly) + .flatMap((item) => + // Every page gets a card of its own after the banner. + item.banner + ? [, ...pageCards.map((card) => ( + + ))] + : [], + )} ))} diff --git a/src/pages/admin/EntityEdit.tsx b/src/pages/admin/EntityEdit.tsx index f7fed00..9de72a6 100644 --- a/src/pages/admin/EntityEdit.tsx +++ b/src/pages/admin/EntityEdit.tsx @@ -418,7 +418,9 @@ export default function EntityEdit() { } } - const visible = (when) => !when || getPath(form, when.path) === when.value; + // A gate is a field's value, or a test of the whole form (a page's + // id deciding it has sections: sitePages.ts). + const visible = (when) => !when || (when.test ? when.test(form) : getPath(form, when.path) === when.value); const groups = manifest.groups.filter((group) => visible(group.when)); const shownChildren = children.filter((child) => visible(child.when)); diff --git a/src/pages/admin/adminNav.ts b/src/pages/admin/adminNav.ts index 71d4c9a..487c4e8 100644 --- a/src/pages/admin/adminNav.ts +++ b/src/pages/admin/adminNav.ts @@ -120,49 +120,30 @@ export const PAGES_NAV = { label: "Pages", blurb: "What a page shows and in what order.", children: [ - // The header's and footer's links, page titles and hidden pages. + // The banner on the admin home: every page, new ones, the menus. + // Each page's own card follows it there (AdminHome.tsx). { - to: "/admin/navigation", - label: "Navigation", - blurb: "The header's pages and buttons, the footer's links, each page's title and intro, and which pages are hidden.", + to: "/admin/pages", + label: "Page management", + blurb: "Every page of the site: make new ones, change an address, title or intro, and hide or disable any of them. Then each page's sections.", + banner: true, + children: [ + { to: "/admin/pages/new", label: "New page" }, + { to: "/admin/navigation", label: "Menus (Navigation)" }, + ], }, - // One record, not a list: the item opens it directly. + // One record, not a list: the item opens it directly. On the + // admin home, the Home page's own card goes here instead. { to: "/admin/front_page", label: "Front page", blurb: "The hero, its photos or livestream, and which bands the home page draws.", - }, - // The site's own pages, in the header's order: each is its - // sections, built in the editor (sitePages.ts). - { - to: "/admin/retreats_page", - label: "Retreats", - blurb: "Its sections: the event carousels and grids, and anything else written for it.", + menuOnly: true, }, { - to: "/admin/community_page", - label: "Community", - blurb: "Its sections: the blog (and its pinned posts and feeds), groups map, regions and partners.", - }, - { - to: "/admin/resources_page", - label: "Resources", - blurb: "Its sections and their content.", - }, - { - to: "/admin/organization_page", - label: "Organization", - blurb: "Mission, vision and values, the leadership teams and volunteering, details and contact.", - }, - { - to: "/admin/history_page", - label: "History", - blurb: "Its sections: the timeline (its entries are under Data), and anything else.", - }, - { - to: "/admin/shop_page", - label: "Shop", - blurb: "The shop's intro page: its sections and the links out to the store.", + to: "/admin/navigation", + label: "Navigation", + blurb: "The header's pages and buttons and the footer's links.", }, ], }; diff --git a/src/pages/fixedPages.ts b/src/pages/fixedPages.ts new file mode 100644 index 0000000..9416e93 --- /dev/null +++ b/src/pages/fixedPages.ts @@ -0,0 +1,23 @@ +/* ═══════════════════════════════════════════════════════════════ + FIXED PAGES + + The pages the site still draws in code, by their site_pages id + (Pages → Page management can rename, move, hide or disable them, + not delete them: server/src/admin-schema/sitePages.js, + FIXED_PAGES). Every other page is its sections (SitePage.tsx). + Each takes its title and intro from its row. The front page is + the index route of its own (Home.tsx). + ═══════════════════════════════════════════════════════════════ */ + +import { lazy, type ComponentType } from 'react' + +export type PageText = { title: string; description: string | null } + +export const FIXED_PAGES: Record> = { + give: lazy(() => import('./Giving.tsx')), + feedback: lazy(() => import('./Feedback.tsx')), + request: lazy(() => import('./Request.tsx')), + qr: lazy(() => import('./QrCodes.tsx')), + privacy: lazy(() => import('./Privacy.tsx')), + terms: lazy(() => import('./Terms.tsx')), +} diff --git a/src/pages/sections/FeedbackForm.tsx b/src/pages/sections/FeedbackForm.tsx index 1743b5c..c7b0b1d 100644 --- a/src/pages/sections/FeedbackForm.tsx +++ b/src/pages/sections/FeedbackForm.tsx @@ -186,7 +186,7 @@ export function TilePicker({ function LocationPicker({ page, section, onPageChange, onSectionChange }) { const sectionsOf = useNavSections(); - const { pages } = useSiteNav(); + const { pageLinks: pages } = useSiteNav(); const sections = page === SITE_WIDE ? [] : sectionsOf(page); return ( @@ -253,7 +253,7 @@ function describeLocation(page, section, sectionsOf: (path: string) => NavSectio export default function FeedbackForm({ fixedType }: { fixedType?: string } = {}) { const sectionsOf = useNavSections(); - const { pages } = useSiteNav(); + const { pageLinks: pages } = useSiteNav(); const request = fixedType === DATA_REQUEST.id; const [type, setType] = useState(fixedType ?? null); const [page, setPage] = useState(SITE_WIDE); diff --git a/src/pages/sections/QrCodeMaker.tsx b/src/pages/sections/QrCodeMaker.tsx index 8053e88..c11bfa1 100644 --- a/src/pages/sections/QrCodeMaker.tsx +++ b/src/pages/sections/QrCodeMaker.tsx @@ -148,7 +148,7 @@ type Group = { label?: string; choices: Choice[] } on the site rather than an anchor on one of them (Give, not Contact Us). */ function mainPages(nav: ReturnType): Choice[] { - const pages = nav.pages.map((p) => ({ path: p.path, label: p.label })) + const pages = nav.pageLinks.map((p) => ({ path: p.path, label: p.label })) const known = new Set(pages.map((p) => p.path)) for (const action of nav.actions) { if (!action.path.startsWith('/') || action.path.includes('#') || known.has(action.path)) continue