From f1a0b06ac23163f6f12ffb8228902f55575d8752 Mon Sep 17 00:00:00 2001 From: Aidan Dona Date: Sat, 17 Oct 2026 00:34:56 -0500 Subject: [PATCH] Page management, step 3: section types with their own settings; the front page as sections Migration 083 gives the section types that need more than blocks their own tables (hero, slides, countdown, stats, paths, featured cards, the Community blog's slots, pinned posts and feeds) and turns the front page into Home's sections: the hero, then its bands in order. Any section can be hidden. The Front page editor, its tables and the Community page's are gone; /api/front-page and /api/community-blog fold into the page's sections (sectionData.js). The admin engine reads and writes a child collection's own side tables and gated nested collections. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 3 +- TODO.md | 6 +- docs/performance.md | 15 +- docs/updating-data-in-code.md | 101 ++-- server/src/admin-crud.js | 21 +- server/src/admin-schema-sync.js | 7 + server/src/admin-schema.js | 9 +- server/src/admin-schema/frontPage.js | 129 ------ server/src/admin-schema/sitePages.js | 184 ++++++-- server/src/feeds.js | 2 +- server/src/index.js | 2 - .../src/migrations/083_section_settings.sql | 435 ++++++++++++++++++ server/src/pageMeta.js | 24 +- server/src/routes/blog.js | 90 +--- server/src/routes/home.js | 243 ---------- server/src/routes/sitePages.js | 19 +- server/src/sectionData.js | 288 ++++++++++++ server/src/shape.js | 2 +- src/App.tsx | 17 +- src/components/FeaturedCards.tsx | 2 +- src/components/PageShell.tsx | 12 +- src/data/pathIcons.ts | 2 +- src/lib/adminSchema.ts | 3 - src/lib/adminSchema/frontPage.ts | 306 ------------ src/lib/adminSchema/sitePages.ts | 377 +++++++++++---- src/lib/eventTypes.ts | 2 +- src/lib/frontPageBands.ts | 38 -- src/lib/navSections.ts | 32 +- src/lib/{useFrontPage.ts => sectionTypes.ts} | 50 +- src/lib/useBlog.ts | 9 +- src/lib/useContent.ts | 2 +- src/lib/useSitePages.ts | 5 +- src/pages/Home.tsx | 129 ------ src/pages/PageAtPath.tsx | 2 +- src/pages/SitePage.tsx | 115 ++++- src/pages/admin/AdminHome.tsx | 6 +- src/pages/admin/AdminNewsletter.tsx | 10 +- src/pages/admin/adminNav.ts | 9 +- src/pages/sections/Bands.tsx | 74 +++ src/pages/sections/CommunityBlog.tsx | 25 +- src/pages/sections/home/FeaturedBand.tsx | 2 +- src/pages/sections/home/HeroStage.tsx | 2 +- .../sections/home/NextEventCountdown.tsx | 2 +- src/pages/sections/home/Pathfinder.tsx | 6 +- src/pages/sections/home/RetreatsBand.tsx | 41 -- src/pages/sections/home/StatsBand.tsx | 4 +- 46 files changed, 1525 insertions(+), 1339 deletions(-) delete mode 100644 server/src/admin-schema/frontPage.js create mode 100644 server/src/migrations/083_section_settings.sql delete mode 100644 server/src/routes/home.js create mode 100644 server/src/sectionData.js delete mode 100644 src/lib/adminSchema/frontPage.ts delete mode 100644 src/lib/frontPageBands.ts rename src/lib/{useFrontPage.ts => sectionTypes.ts} (69%) delete mode 100644 src/pages/Home.tsx create mode 100644 src/pages/sections/Bands.tsx delete mode 100644 src/pages/sections/home/RetreatsBand.tsx diff --git a/CLAUDE.md b/CLAUDE.md index f48e3af..1a97833 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/`. -- 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). Every page but the front page is a page of sections (forms and embeds are section types, `src/pages/sections/FormSections.tsx`), and new ones are made there; `PageAtPath.tsx` (the `*` route) draws whatever page is at an address. The pages the code links to (`CORE_PAGES` in `server/src/admin-schema/sitePages.js`: /give, /feedback, /request, /qr, /privacy, /terms) keep their address and 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. +- 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). Every page is a page of sections, the front page included (its hero and bands are section types: `src/pages/sections/Bands.tsx`, their settings in `section_*` tables read by `server/src/sectionData.js`; forms and embeds are section types too, `src/pages/sections/FormSections.tsx`), and new ones are made there; `PageAtPath.tsx` (the `*` route) draws whatever page is at an address. The pages the code links to (`CORE_PAGES` in `server/src/admin-schema/sitePages.js`: /give, /feedback, /request, /qr, /privacy, /terms) keep their address and 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`). @@ -84,6 +84,7 @@ In dev, Vite proxies `/api` to the target set in `vite.config.ts`, so the API mu Descriptor-driven: `server/src/admin-crud.js` and `server/src/admin-schema/` (server, one file per entity, registered in `admin-schema.js`) and `src/lib/adminSchema/` (client, one file per entity, registered in `adminSchema.ts`) generate SQL and form fields from declarative entity configs. Adding an entity should mean adding a descriptor, not new CRUD code. - Child collections are deleted and reinserted wholesale. Unsafe for entities referenced by foreign keys elsewhere. - `reindex: false` prevents cross-entity sort order collisions. +- A child collection can have `extensions` of its own (1:1 side tables keyed by the child row's id, eg. a page section's `section_hero`), and both those and its nested collections take a `when` on the row's values (a section's preset). A `when` value can be a list. - `check: (db, id) => void` runs after a save has written everything, inside its transaction; throwing an `HttpError` refuses the save (Site settings uses it for the color contrast check, `server/src/theme.js`). - The `OMIT` sentinel distinguishes unsent fields from deliberate clears. - `admin-schema-sync.js` runs at boot and throws if descriptors don't match live `PRAGMA table_info`. If boot fails after a schema change, update the descriptor or migration so they agree. diff --git a/TODO.md b/TODO.md index 10bd54f..8ec6990 100644 --- a/TODO.md +++ b/TODO.md @@ -79,7 +79,7 @@ - [ ] **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). - [x] Step 2, the core pages as sections (Done, below). - - [ ] 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. + - [x] Step 3, section types with their own settings and the front page as sections (Done, below). ## Admin @@ -123,7 +123,9 @@ # Part 2: Done -## Page management (branch `page-management`, on top of `page-features`, no PR yet; migrations 080 to 082, back up the database before deploying) +## Page management (branch `page-management`, on top of `page-features`, no PR yet; migrations 080 to 083, back up the database before deploying) +- [x] **Section types with their own settings, and the front page as sections** (migration 083): the front page is Home in Page management, a page of sections like the others: its hero first, then its bands in their old order (hidden ones stay hidden), each a section type that can go on any page with content of its own: Hero (words, buttons, photos, video, livestream or event), Event countdown, Event calendar, Numbers, Featured cards, Connect nav, and a Timeline shown as the rail of featured moments. The Community blog's slots, pinned posts and feeds moved into its section, so it can go on any page too. Any section can be Hidden. The Front page editor is gone (its fields are each section's), and so are its tables and the Community page's. On the front page the bands look as they did and any other section is a band in the same style; on other pages a band brings its own heading. The National Retreats band became an Events section with an All retreats button. The newsletter's "featured cards" come from the front page's featured card sections. Admin engine: a child collection can have its own side tables and gated nested collections. + - [ ] Check in a browser: the front page (every band, the countdown overlapping the hero, reading mode, the menu's Home dropdown), editing the hero and a band in Page management, a Hero and a Numbers section put on another page, hiding a section, the Community blog (pinned posts, feeds), a draft preview of the front page, the newsletter's featured cards. - [x] **Core pages as sections** (migrations 081, 082): Feedback, Request, QR codes, Give, Privacy and Terms are pages of sections now, edited in Page management like any other. Their forms and embeds are section types any page can use (Website feedback form, Request form, Data request form, Giving button, QR code maker); Give's words, and all of Privacy and Terms, are blocks (headings, paragraphs, lists), with "Last updated" in the section's blurb. The privacy contact email was written into the policy's text and its Site settings field is gone. These pages keep their address (the site's code links to them) and can't be deleted. The privacy notice's link now goes to #cookies-and-browser-storage. - [ ] Check in a browser: each of the six pages (reading width of Privacy and Terms, the giving modal opening), editing a Privacy paragraph, a Request form section put on another page. - [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. diff --git a/docs/performance.md b/docs/performance.md index 5744786..e0822bc 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -41,15 +41,14 @@ also take a separate `http2 on;`. ## The bundle -Only the home page is in the main bundle. Every other page, and the -whole admin, loads when first visited (`src/App.tsx`). A tab still -running an old build that asks for a page removed by a deploy reloads -once to pick up the new one. +Every page, the front page included, and the whole admin, loads when +first visited (`src/App.tsx`). A tab still running an old build that +asks for a page removed by a deploy reloads once to pick up the new +one. -The home page asks for events and the timeline alongside its own data -(`src/pages/Home.tsx`), and the server tells the browser to fetch -`/api/front-page` and the first hero photo while the JS downloads -(`preload` in `server/src/pageMeta.js`). +The server tells the browser to fetch the front page's data +(`/api/site-pages/home`) and its hero's first photo while the JS +downloads (`preload` in `server/src/pageMeta.js`). ## Images diff --git a/docs/updating-data-in-code.md b/docs/updating-data-in-code.md index 89f04a0..227a027 100644 --- a/docs/updating-data-in-code.md +++ b/docs/updating-data-in-code.md @@ -15,8 +15,8 @@ what a dropdown in the admin editor says. - [Renaming what a dropdown shows](#renaming-what-a-dropdown-shows) - [Adding, removing or renaming a stored value](#adding-removing-or-renaming-a-stored-value) - [Every dropdown in the editor](#every-dropdown-in-the-editor) -- [Front page section names](#front-page-section-names) -- [Front page stat sources](#front-page-stat-sources) +- [Front page sections](#front-page-sections) +- [Stat sources](#stat-sources) - [Other content that lives in code](#other-content-that-lives-in-code) - [Writing text in the editor](#writing-text-in-the-editor) - [Making the change](#making-the-change) @@ -154,8 +154,9 @@ together, in one branch: 3. **`src/lib/adminSchema/.ts`**: the `options` on the form field, and on the list filter if there is one. 4. **Anywhere the public site renders or relies on the value**, listed in - the table below (for example `EVENT_TYPES` for event types, or the - `SECTIONS` map in `Home.tsx` for front page sections). + the table below (for example `EVENT_TYPES` for event types, or + `PRESETS` in `SitePage.tsx` and `BANDS` in `sections/Bands.tsx` for + section types). If the server descriptor and the database disagree, the API refuses to start: `admin-schema-sync.js` compares them at boot and throws with a @@ -184,16 +185,15 @@ also in `server/src/admin-schema/` and a CHECK): | Timeline → Kind (+ list filter) | milestone, event, organization, award, people | no | `KIND_NAMES` in `src/pages/sections/history/TimelineEntry.tsx` | | Timeline → Points at (+ list filter) | event, organization, award, person, team | no | `refHref` in `src/lib/hrefs.ts` | | Timeline → Precision (and on events/orgs) | year, month, day | no | the history page's grouping | -| Front page → Countdown → Only this type | retreat, class, workshop, meeting, other | **yes** | `server/src/routes/home.js` (picks the countdown event). The same values as Events → Type, so adding a type widens both CHECKs. | -| Front page → Background | brand, photos | **yes** | `HeroStage.tsx` | -| Front page → Feature | none, livestream, video, event | **yes** | `HeroStage.tsx`; the event is picked in `server/src/routes/home.js` | -| Front page → Sections → Section | countdown, retreats, calendar, stats, timeline, connect, featured | **yes**, `FRONT_PAGE_SECTIONS` | `SECTIONS` in `src/pages/Home.tsx`; see [below](#front-page-section-names) | -| Front page → Stats → Number Source | manual, years_since, regions, … | **yes**, `STAT_SOURCES` | `STAT_QUERIES` in `server/src/routes/home.js`; see [below](#front-page-stat-sources) | -| Front page → Featured cards → Card type (Community → Community blog: pinned community posts offers link and video only) | record, link, video | **yes**, `FEATURED_KINDS` | `FeaturedCards.tsx` (how each kind draws), `loadFeaturedCards` in `server/src/shape.js` | -| Front page → Featured Content → Columns (073) | 2, 3, 4 | **yes**, inline in `src/lib/adminSchema/frontPage.ts` | `GRID_COLUMNS` in `FeaturedCards.tsx`; the CHECK on `front_page.featured_columns` | -| Front page → Featured cards → Size (073; front page only, regions and the Community blog stay automatic) | normal, wide, tall, large | **yes**, inline in `src/lib/adminSchema/frontPage.ts` | `SPANS` and `sizeOf` in `FeaturedCards.tsx`; the CHECK on `featured_cards.size` | -| Front page → Featured cards → Record type | event, organization, person, team, award | no | `FEATURED_REFS` in `server/src/shape.js` (what each fills the card with); the triggers in `030_featured_cards.sql` | -| Pages → Sections → Preset | community_blog, group_map, region_list, partner_list, events, timeline, people_directory | **yes**, `PRESETS` in `src/lib/adminSchema/sitePages.ts` (which pages offer which, the list passed to each `sitePage`) | `PRESETS` in `src/pages/SitePage.tsx`. A People directory shows its tag's first `DIRECTORY_PREVIEW` people (`src/pages/sections/PeopleDirectory.tsx`), linking to `/directory/`. | +| Pages → Sections → Countdown: only this type | retreat, class, workshop, meeting, other | **yes** | `server/src/sectionData.js` (picks the countdown event). The same values as Events → Type, so adding a type widens both CHECKs. | +| Pages → Sections → Hero: background | brand, photos | **yes** | `HeroStage.tsx` | +| Pages → Sections → Hero: feature | none, livestream, video, event | **yes** | `HeroStage.tsx`; the event is picked in `server/src/sectionData.js` | +| Pages → Sections → Numbers → Number Source | manual, years_since, regions, … | **yes**, `STAT_SOURCES` in `src/lib/adminSchema/sitePages.ts` | `STAT_QUERIES` in `server/src/sectionData.js`; see [below](#stat-sources) | +| Featured cards → Card type (a Community blog's pinned community posts offer link and video only) | record, link, video | **yes**, `FEATURED_KINDS` | `FeaturedCards.tsx` (how each kind draws), `loadFeaturedCards` in `server/src/shape.js` | +| Pages → Sections → Featured cards: columns (073) | 2, 3, 4 | **yes**, inline in `src/lib/adminSchema/sitePages.ts` | `GRID_COLUMNS` in `FeaturedCards.tsx`; the CHECK on `section_featured.columns` | +| Featured cards → Size (073; featured card sections only, regions and the Community blog stay automatic) | normal, wide, tall, large | **yes**, inline in `src/lib/adminSchema/sitePages.ts` | `SPANS` and `sizeOf` in `FeaturedCards.tsx`; the CHECK on `featured_cards.size` | +| Featured cards → Record type | event, organization, person, team, award | no | `FEATURED_REFS` in `server/src/shape.js` (what each fills the card with); the triggers in `030_featured_cards.sql` | +| Pages → Sections → Preset (section type) | community_blog, group_map, region_list, partner_list, events, timeline, people_directory, feedback_form, request_form, data_request_form, giving, qr_maker, hero, countdown, calendar, stats, featured_cards, connect | **yes**, `PRESETS` in `src/lib/adminSchema/sitePages.ts`, every page offers them all | `PRESETS` in `src/pages/SitePage.tsx`; the bands (hero, countdown, calendar, numbers, featured cards, connect, and a timeline shown as a rail) in `src/pages/sections/Bands.tsx`, their data from `server/src/sectionData.js`; forms and embeds in `src/pages/sections/FormSections.tsx`. A People directory shows each tag's first `DIRECTORY_PREVIEW` people (`src/pages/sections/PeopleDirectory.tsx`), linking to `/directory/`. | | Pages → Sections → Cards: list (organization cards preset, 067) | partner, ministry, partner,ministry | **yes**, inline in `src/lib/adminSchema/sitePages.ts` | `partner_list` in `PRESETS` in `src/pages/SitePage.tsx` passes it as the kind to `OrgListCards`; a section's hand-picked Cards: organizations (`page_section_orgs`) replace it | | Every list → Published / Listed / Featured filter | 1, 0 | **yes** | n/a | @@ -210,67 +210,49 @@ code): | People → Directories → Tag; Pages → Sections → Directory: tag | `person_tag_types` | Data → People tags | | Organizations and Events → Tags → Tag | `tags` | Data → Tags | | Organizations → Contacts → Type | `contact_types` | Data → Contact types | -| Event → Scope (+ list filter); Front page → Countdown → Only this scope | `event_scopes` | the `event_scopes` table (migration only) | +| Event → Scope (+ list filter); Pages → Sections → Countdown: only this scope | `event_scopes` | the `event_scopes` table (migration only) | | Event hosts → Organization; affiliations; team and award "Organization" / "Awarded by"; person → Home organization | `organizations` | organizations, labeled by name, except ministries (they have no page to link to) | | Event hosts / event people / team members / timeline people → Person | `people` | people | -| Community → Community blog: pinned posts (ours) → Post | `blog_posts` | blog posts, newest first | +| Pages → Sections → Blog: pinned posts (ours) → Post | `blog_posts` | blog posts, newest first | | Timeline → Record; Featured cards → Record | `record_refs` | every event, organization (but ministries), award, person and team, narrowed by the type picked beside it | | Affiliations → Team | `teams` | teams, filtered to the chosen organization | | Person awards → Award | `awards` | awards, labeled "Award (Organization)" | -| Person awards → Presented at; Front page → Count down to; Front page → Featured event | `events` | events | +| Person awards → Presented at; Pages → Sections → Count down to, Hero: featured event | `events` | events | --- -## Front page section names +## Front page sections -"Section name" means three different things on the front page, and -each is changed in a different place: +The front page is a page of sections like the others (Admin → Pages → +Page management → Home, migration 083): the hero first, then its +bands, each a section with a type. Its heading is the section's title +(up to 60 characters on the front page), its anchor the section's URL +ID (`#retreats`, `#calendar`, `#numbers`, `#connect`), which the +header's Home dropdown lists (not the hero or the countdown). Rename +a heading freely; change a URL ID only if you mean to break links to +it. The names in the section type dropdown are `PRESETS` in +`src/lib/adminSchema/sitePages.ts`. -| What you see | Where it's set | -| --- | --- | -| **The heading on the page** ("National Retreats", "What's on") | **Admin → Pages → Front page → Page sections → Heading.** Blank uses the default below. | -| The default heading when that field is blank | `SECTIONS` in `src/pages/Home.tsx`, the `title` of each entry | -| **The name in the admin's Section dropdown** ("Events Carousel (National Retreats)") | `FRONT_PAGE_SECTIONS` in `src/lib/adminSchema/frontPage.ts` | -| The links in the header's Home dropdown | the bands shown, under their headings (`src/lib/navSections.ts`) | - -To rename a band **for visitors**, use the admin. To rename how it -reads **in the editor's dropdown**, edit `FRONT_PAGE_SECTIONS`: - -```ts -const FRONT_PAGE_SECTIONS = [ - ["countdown", "Event Countdown"], - ["retreats", "Events Carousel (National Retreats)"], // ← the right-hand side is the label - ["calendar", "Event Calendar"], - ... -]; -``` - -The subnav links jump to each band by its anchor: the `id` passed in -each band's `render` in `Home.tsx` (`#retreats`, `#calendar`, -`#numbers`, `#connect`, and `#hero` for the hero). If you rename a -heading in Front page → Sections, its anchor stays: leave the band's -`id` alone unless you mean to break links to it. - -**Adding a new kind of band** (not just renaming one) is a feature, -not a relabel: it needs a component, an entry in `SECTIONS` in -`Home.tsx`, the key added to `FRONT_PAGE_SECTIONS`, to the -`enumeration("section", …)` in `server/src/admin-schema/frontPage.js`, to the -`FrontPageSectionKey` type in `src/lib/useFrontPage.ts`, and to the -CHECK on `front_page_sections.section` via a migration. +**Adding a new kind of band** is a feature, not a relabel: its +component and an entry in `BANDS` (`src/pages/sections/Bands.tsx`), +its settings table (a migration) and extension or collection in +`sectionsChild` (`server/src/admin-schema/sitePages.js`), its data in +`server/src/sectionData.js`, its fields in `src/lib/adminSchema/sitePages.ts`, +and its value added to the CHECK on `page_sections.preset`. --- -## Front page stat sources +## Stat sources -The numbers band's "Number Source" dropdown works the same way: +A Numbers section's "Number Source" dropdown works the same way: -- **Relabel a source:** `STAT_SOURCES` in `src/lib/adminSchema/frontPage.ts`. +- **Relabel a source:** `STAT_SOURCES` in `src/lib/adminSchema/sitePages.ts`. - **Change what a count counts:** its query in `STAT_QUERIES` in - `server/src/routes/home.js`. Keep it counting exactly what the + `server/src/sectionData.js`. Keep it counting exactly what the matching public page shows (published rows), or the number and the page will disagree. -- **Add a source:** the CHECK on `front_page_stats.source` (migration), - the `enumeration("source", …)` in `server/src/admin-schema/frontPage.js`, +- **Add a source:** the CHECK on `section_stats.source` (migration), + the `enumeration("source", …)` in `server/src/admin-schema/sitePages.js`, `STAT_SOURCES`, and a query in `STAT_QUERIES`. --- @@ -279,15 +261,14 @@ 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. 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. | +| 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` (every page's sections from Admin → Pages → Page management, the front page's included, but its hero and countdown). A new page is made in Page management, no code: it's a page of sections at the address given. | | 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. | | Group map tiles and area names | `src/data/mapGrid.ts` | `AREAS` (tile positions) and `AREA_NAMES`. Which region paints which tile is in the database (Admin → Data → Organizations → a region → Map areas). | | Feedback form types | `src/data/feedbackTypes.ts` **and** `TYPES` in `server/src/routes/feedback.js` | Keep the ids identical in both; the server stores unknown ids as `general`. Labels and hints are client-only. `DATA_REQUEST` ('privacy') isn't a tile: the Privacy page's form sends it, and the server requires an email for it. | | Request form types (what `/request` can ask for) | `src/data/requestTypes.ts` **and** `CATEGORIES` in `server/src/routes/requests.js` **and** the CHECK on `feedback.category` (`046_content_requests.sql`) | Ids and allowed actions (new, update) identical in all three; a new id needs a migration. Labels, hints, the name field's question and each type's `fields` (the details it asks for, and where each lands in the admin editor: a field path, a link row or a description paragraph) are client-only: the server stores whatever detail keys come as JSON (`feedback.details`, 049), so adding a field needs no migration. A button to the form opened on one type: `request: { type, label }` on a section manifest entry, or `` (`src/components/RequestLink.tsx`). | | The site's colors, light and dark | the database over `src/index.css` | Admin → Panel → Site settings → Colors (superadmins): pick a color, set its light and/or dark value; saving refuses anything that makes text hard to read. The defaults are `THEME_DEFAULTS` in `server/src/themeDefaults.js` (the admin and the contrast check read it) and the same values as CSS in `src/index.css`; the build stops if the two differ. The admin's labels for them are `THEME_LABELS` in `src/lib/adminSchema/siteSettings.ts`. Change a token's value in both modes and every use follows. Use the token utilities (`text-muted`, `bg-surface`, `border-brand/20`) or `var(--color-…)`, not hex. A color that arrives as data (a page accent, an event's or region's color) goes through `src/lib/color.ts`: `withAlpha` for tints, `accentText` for text in it, `readableOn` for text on it. | -| The icons a Front page "Find your way in" path can pick | `src/data/pathIcons.ts` (keys and labels) **and** `ICONS` in `src/pages/sections/home/Pathfinder.tsx` (the Phosphor icon for each key) | Add a line to both. A path saved with an emoji from before the list shows it as it is. | +| The icons a Connect nav section's path can pick | `src/data/pathIcons.ts` (keys and labels) **and** `ICONS` in `src/pages/sections/home/Pathfinder.tsx` (the Phosphor icon for each key) | Add a line to both. A path saved with an emoji from before the list shows it as it is. | | A page section's accent color | `BRAND` and `ACCENTS` in `src/lib/color.ts` | Pages pick from these (`accent: ACCENTS.green`); add a color there, not a hex in a page. Each is readable as text on white and the tints. | | The palette (the 16-color grid the theme is drawn from) | `PALETTE` in `src/lib/color.ts` | Four families, a column each. `PALETTE_LIGHT` / `PALETTE_DARK` are the fills things colored by data use (a person's initials tile, `paletteFill`); the page background's layers (how many circles, their sizes and parallax speeds) are `LAYERS` in `src/components/PageBackdrop.tsx` and its shades are in `PageBackdrop.css`; the admin home's two alternating group colors are `BLOCK_COLORS` in `src/pages/admin/AdminHome.tsx`. | | The accessibility panel's choices (bottom right of every public page) | `SETTINGS` in `src/components/AccessibilityPanel.tsx`; the color blind modes are `VISIONS` and `SWAPS` in `src/lib/color.ts` | Each choice is an attribute on `` styled in `src/index.css`, and `index.html` sets it again before the first paint, so a new one goes in all three. A color blind mode replaces all three color families, teal, green and amber (`SWAPS`, picked by simulating each type: see the comment there), in code, in data colors as they load (`src/lib/api.ts`, never under /admin), in CSS (the `--pal-*` variables in `src/index.css`, which hold the same values as `SWAPS`: change both) and in the theme tokens drawn from them. A palette hex in a component or CSS file should be `var(--pal--)` (eg. `var(--pal-amber-2)`), or a color blind mode won't reach it. Reading mode is `src/components/ReaderView.tsx`, which reads the hidden page and writes out its headings, paragraphs, links and described pictures. A part it can't read well (a carousel, tabs, details behind a click, a map) draws its own text version when `useReadingMode()` (`src/lib/readingMode.ts`) is on: the hero, pathfinder, stats, history rail, event lists, calendar (the next six weeks), featured cards, org lists and groups map, history timeline, schedule, people tiles and video player; the countdown draws nothing. A new component with any of those should do the same. Something saved or sent (the newsletter's colors) is a stored hex, which is never swapped. | diff --git a/server/src/admin-crud.js b/server/src/admin-crud.js index 5a3893b..18bfdc5 100644 --- a/server/src/admin-crud.js +++ b/server/src/admin-crud.js @@ -139,7 +139,9 @@ function coerceRow(columns, data, { prefix = "" } = {}) { return { values, errors }; } -const applies = (gate, row) => !gate || row[gate.column] === gate.value; +/* A gate on a column's value: one value, or any of a list. */ +const applies = (gate, row) => + !gate || (Array.isArray(gate.value) ? gate.value.includes(row[gate.column]) : row[gate.column] === gate.value); /* ── Read ────────────────────────────────────────────────────── */ @@ -242,6 +244,12 @@ function readChildren(db, child, ownerId) { ) .all(...params); + // A row's own 1:1 side tables (a section's settings for its type: + // its hero's words, its blog's slots). + for (const ext of child.extensions ?? []) { + for (const row of rows) row[ext.key] = readExtension(db, ext, row.id); + } + // Nested collections, to any depth: a page's sections, each // section's blocks, each block's items. The id goes as text: a JS // number binds as REAL, which a TEXT owner column (a section's @@ -423,7 +431,7 @@ export function deleteRow(db, entity, rawId) { /* ── Write helpers ───────────────────────────────────────────── */ -function writeExtensions(db, entity, id, payload, parentValues) { +function writeExtensions(db, entity, id, payload, parentValues, prefix = "") { for (const ext of entity.extensions ?? []) { if (!applies(ext.when, parentValues)) { // The gate closed (the kind changed away from this side @@ -435,7 +443,7 @@ function writeExtensions(db, entity, id, payload, parentValues) { } const { values, errors } = coerceRow(ext.columns, payload[ext.key] ?? {}, { - prefix: `${ext.key}.`, + prefix: `${prefix}${ext.key}.`, }); if (Object.keys(errors).length) { throw new HttpError(422, "Validation failed", errors); @@ -588,8 +596,13 @@ function writeRows(db, child, ownerId, incomingRaw, prefix, parentValues) { .run(...params), ); + const rowId = Number(result.lastInsertRowid); + // Its own side tables, gated on its values (a section's preset), + // then its collections, gated the same way. + if (child.extensions) writeExtensions(db, child, rowId, raw, values, rowPrefix); for (const child2 of child.children ?? []) { - writeRows(db, child2, String(result.lastInsertRowid), raw[child2.key], `${rowPrefix}${child2.key}.`, values); + if (!applies(child2.when, values)) continue; + writeRows(db, child2, String(rowId), raw[child2.key], `${rowPrefix}${child2.key}.`, values); } }); } diff --git a/server/src/admin-schema-sync.js b/server/src/admin-schema-sync.js index 5c671d0..2ad77c3 100644 --- a/server/src/admin-schema-sync.js +++ b/server/src/admin-schema-sync.js @@ -85,6 +85,13 @@ function collectGroups(entity) { ...Object.keys(child.owner.inherit ?? {}), ].filter(Boolean), }); + for (const ext of child.extensions ?? []) { + groups.push({ + table: ext.table, + columns: ext.columns ?? [], + engineSupplied: [ext.idColumn, ext.owner?.column, ext.owner?.kindColumn].filter(Boolean), + }); + } for (const nested of child.children ?? []) walk(nested); }; diff --git a/server/src/admin-schema.js b/server/src/admin-schema.js index a9c4689..824c108 100644 --- a/server/src/admin-schema.js +++ b/server/src/admin-schema.js @@ -18,9 +18,12 @@ regions or groups row should exist) children ordered collections, replaced wholesale on save; `readRole` on one hides it from lesser roles, as - on an extension (an organization's contacts) + on an extension (an organization's contacts). A + child may have `extensions` of its own (a page + section's settings for its type), and its nested + collections a `when` on its values singleton the one id this entity ever has; the engine - refuses create and delete (see front_page) + refuses create and delete (see navigation) undeletable ids the engine refuses to delete (the pages the site draws in code) check (db, id) => void, run after a save has written @@ -52,7 +55,6 @@ import { people } from "./admin-schema/people.js"; import { teams } from "./admin-schema/teams.js"; import { awards } from "./admin-schema/awards.js"; import { timeline } from "./admin-schema/timeline.js"; -import { frontPage } from "./admin-schema/frontPage.js"; import { blogPosts } from "./admin-schema/blog.js"; import { siteSettings } from "./admin-schema/siteSettings.js"; import { siteNav } from "./admin-schema/siteNav.js"; @@ -74,7 +76,6 @@ export const ENTITIES = { teams, awards, timeline, - front_page: frontPage, blog_posts: blogPosts, pages, navigation: siteNav, diff --git a/server/src/admin-schema/frontPage.js b/server/src/admin-schema/frontPage.js deleted file mode 100644 index bc2be0b..0000000 --- a/server/src/admin-schema/frontPage.js +++ /dev/null @@ -1,129 +0,0 @@ -import { text, url, int, bool, enumeration, featuredCardsChild } from "./columns.js"; - -/* ── Front page ────────────────────────────────────────────────── - - A singleton: one row, id 'home', seeded by the schema and never - created by the admin. `singleton` tells the engine to refuse create - and delete, and the CHECK on front_page.id is what makes a second - row impossible even without it. - - Every collection here is owned by page_id and replaced wholesale. - That is safe for the same reason it is for links and blocks - (nothing has a foreign key into these tables), and paths carry - their actions as a nested collection, the shape content blocks - and their items already use. */ - -export const frontPage = { - key: "front_page", - table: "front_page", - idColumn: "id", - idKind: "slug", - singleton: "home", - concurrency: "updated_at", - - list: { - columns: ["id", "headline", "hero_backdrop", "hero_feature", "updated_at"], - filters: [], - search: [], - order: "id", - }, - - columns: [ - enumeration("hero_backdrop", ["brand", "photos"]), - enumeration("hero_feature", ["none", "livestream", "video", "event"]), - text("hero_event_id"), - text("eyebrow"), - text("headline"), - text("subhead"), - text("primary_label"), - url("primary_url"), - text("secondary_label"), - url("secondary_url"), - int("slide_seconds"), - url("livestream_url"), - text("livestream_title"), - url("video_url"), - text("video_title"), - text("video_captions"), - text("countdown_event_id"), - text("countdown_scope_id"), - enumeration("countdown_event_type", ["retreat", "class", "workshop", "meeting", "other"]), - int("featured_columns"), - text("video_still"), - ], - - children: [ - { - key: "slides", - table: "front_page_slides", - owner: { column: "page_id" }, - order: "sort_order", - columns: [ - text("media", { required: true }), - text("alt"), - text("caption"), - url("link_url"), - ], - }, - { - key: "sections", - table: "front_page_sections", - owner: { column: "page_id" }, - order: "sort_order", - columns: [ - enumeration( - "section", - ["countdown", "retreats", "calendar", "stats", "timeline", "connect", "featured"], - { required: true }, - ), - text("title"), - text("blurb"), - bool("is_hidden"), - ], - }, - { - key: "stats", - table: "front_page_stats", - owner: { column: "page_id" }, - order: "sort_order", - columns: [ - text("label", { required: true }), - enumeration("source", [ - "manual", - "years_since", - "regions", - "groups", - "partners", - "events_held", - "retreats_held", - "people", - "awards_given", - ]), - text("value"), - text("suffix"), - text("note"), - ], - }, - featuredCardsChild("front_page"), - { - key: "paths", - table: "front_page_paths", - owner: { column: "page_id" }, - order: "sort_order", - columns: [text("label", { required: true }), text("icon"), text("blurb")], - children: [ - { - key: "actions", - table: "front_page_path_actions", - owner: { column: "path_id" }, - order: "sort_order", - columns: [ - text("label", { required: true }), - text("description"), - url("url", { required: true }), - ], - }, - ], - }, - ], -}; diff --git a/server/src/admin-schema/sitePages.js b/server/src/admin-schema/sitePages.js index ceb6bce..97e387a 100644 --- a/server/src/admin-schema/sitePages.js +++ b/server/src/admin-schema/sitePages.js @@ -10,10 +10,16 @@ import { text, url, int, bool, enumeration, featuredCardsChild, blocksChild } fr either its blocks or a preset, a prebuilt part of the site (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; only for the page - whose id is community. */ + A section type that needs more than its blocks keeps its settings + in tables of its own (083_section_settings.sql), the section's + extensions and collections here, each gated on its preset: a + hero's words and slides, a countdown's event, a stats band's + numbers, a pathfinder's paths, featured cards, a Community blog's + slots, pinned posts and feeds. The front page is a page of + sections like the rest. */ + +/* Gates on the section's preset. */ +const is = (preset) => ({ column: "preset", value: preset }); const sectionsChild = { key: "sections", @@ -39,12 +45,75 @@ const sectionsChild = { "data_request_form", "giving", "qr_maker", + // The front page's bands, on any page (083). + "hero", + "countdown", + "calendar", + "stats", + "featured_cards", + "connect", ]), text("scope_id"), enumeration("event_type", ["retreat", "class", "workshop", "meeting", "other"]), enumeration("view", ["carousel", "grid", "map"]), // Organization cards (067): the kinds listed by themselves. enumeration("org_kinds", ["partner", "ministry", "partner,ministry"]), + bool("is_hidden"), + ], + extensions: [ + { + key: "hero", + table: "section_hero", + idColumn: "section_id", + when: is("hero"), + columns: [ + text("eyebrow"), + text("headline"), + text("subhead"), + text("primary_label"), + url("primary_url"), + text("secondary_label"), + url("secondary_url"), + enumeration("backdrop", ["brand", "photos"]), + int("slide_seconds"), + enumeration("feature", ["none", "livestream", "video", "event"]), + url("livestream_url"), + text("livestream_title"), + url("video_url"), + text("video_title"), + text("video_captions"), + text("video_still"), + text("event_id"), + ], + }, + { + key: "countdown", + table: "section_countdown", + idColumn: "section_id", + when: is("countdown"), + columns: [text("event_id"), text("scope_id"), enumeration("event_type", ["retreat", "class", "workshop", "meeting", "other"])], + }, + { + key: "featured", + table: "section_featured", + idColumn: "section_id", + when: is("featured_cards"), + columns: [int("columns")], + }, + { + key: "blog", + table: "section_blog", + idColumn: "section_id", + when: is("community_blog"), + columns: [ + text("internal_title"), + int("internal_slots"), + text("external_title"), + int("external_slots"), + url("external_url"), + text("external_label"), + ], + }, ], children: [ blocksChild("page_section"), @@ -64,6 +133,73 @@ const sectionsChild = { order: "sort_order", columns: [text("org_id", { required: true })], }, + { + key: "slides", + table: "section_slides", + owner: { column: "section_id" }, + order: "sort_order", + when: is("hero"), + columns: [text("media", { required: true }), text("alt"), text("caption"), url("link_url")], + }, + { + key: "stats", + table: "section_stats", + owner: { column: "section_id" }, + order: "sort_order", + when: is("stats"), + columns: [ + text("label", { required: true }), + enumeration("source", [ + "manual", + "years_since", + "regions", + "groups", + "partners", + "events_held", + "retreats_held", + "people", + "awards_given", + ]), + text("value"), + text("suffix"), + text("note"), + ], + }, + { + key: "paths", + table: "section_paths", + owner: { column: "section_id" }, + order: "sort_order", + when: is("connect"), + columns: [text("label", { required: true }), text("icon"), text("blurb")], + children: [ + { + key: "actions", + table: "section_path_actions", + owner: { column: "path_id" }, + order: "sort_order", + columns: [text("label", { required: true }), text("description"), url("url", { required: true })], + }, + ], + }, + // Featured cards, and a Community blog's pinned community posts. + { ...featuredCardsChild("page_section"), when: { column: "preset", value: ["featured_cards", "community_blog"] } }, + { + key: "blog_posts", + table: "section_blog_posts", + owner: { column: "section_id" }, + order: "sort_order", + when: is("community_blog"), + columns: [text("post_id", { required: true })], + }, + { + key: "feeds", + table: "section_feeds", + owner: { column: "section_id" }, + order: "sort_order", + when: is("community_blog"), + columns: [url("url", { required: true }), text("label")], + }, ], }; @@ -94,8 +230,6 @@ function checkPage(db, id) { 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", @@ -120,43 +254,7 @@ export const pages = { int("sort_order"), ], - extensions: [ - { - key: "blog", - table: "community_page", - idColumn: "id", - when: isCommunity, - columns: [ - text("internal_title"), - int("internal_slots"), - text("external_title"), - int("external_slots"), - url("external_url"), - text("external_label"), - ], - }, - ], - - 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"), when: isCommunity }, - { - key: "feeds", - table: "community_page_feeds", - owner: { column: "page_id" }, - order: "sort_order", - when: isCommunity, - columns: [url("url", { required: true }), text("label")], - }, - ], + children: [sectionsChild], check: checkPage, }; diff --git a/server/src/feeds.js b/server/src/feeds.js index 43f826a..6b03564 100644 --- a/server/src/feeds.js +++ b/server/src/feeds.js @@ -2,7 +2,7 @@ FEEDS Reads the RSS and Atom feeds the Community page's blog section - lists (community_page_feeds), for its "newest community posts". + lists (section_feeds, 083), for its "newest community posts". A Substack's feed is https://.substack.com/feed. Each feed is fetched through linkPreview.js's safeGet, so it gets diff --git a/server/src/index.js b/server/src/index.js index a1ec0ea..5d193c4 100644 --- a/server/src/index.js +++ b/server/src/index.js @@ -24,7 +24,6 @@ import { rateLimit } from "./rateLimit.js"; import content from "./routes/content.js"; import people from "./routes/people.js"; import history from "./routes/history.js"; -import home from "./routes/home.js"; import directory from "./routes/directory.js"; import blog from "./routes/blog.js"; import sitePages from "./routes/sitePages.js"; @@ -192,7 +191,6 @@ app.get("/api/health", (c) => app.route("/api", content); app.route("/api", people); app.route("/api", history); -app.route("/api", home); app.route("/api", directory); app.route("/api", blog); app.route("/api", sitePages); diff --git a/server/src/migrations/083_section_settings.sql b/server/src/migrations/083_section_settings.sql new file mode 100644 index 0000000..33e0254 --- /dev/null +++ b/server/src/migrations/083_section_settings.sql @@ -0,0 +1,435 @@ +-- ═══════════════════════════════════════════════════════════════ +-- 083 SECTION SETTINGS, AND THE FRONT PAGE AS SECTIONS +-- +-- A section type that needs more than its blocks keeps its settings +-- in a table of its own, one row per section (and its lists in +-- tables under the section), so it can go on any page with content +-- of its own. The admin engine reads and writes them as the section's +-- own side tables (admin-crud.js, a child's extensions): +-- +-- section_hero a hero: words, buttons, backdrop, feature +-- section_slides its photos +-- section_countdown a countdown: the pinned event, or the next +-- one of a scope and type +-- section_stats a stats band's numbers +-- section_paths a pathfinder's paths +-- section_path_actions each path's links +-- section_featured featured cards' columns (the cards are +-- featured_cards owned by 'page_section') +-- section_blog a Community blog's headings and slots +-- section_blog_posts its pinned posts of ours +-- section_feeds the feeds its community posts come from +-- (its pinned community posts are +-- featured_cards owned by 'page_section') +-- +-- page_sections gets is_hidden (any section can be left out without +-- deleting it, as the front page's bands could), and a title of up +-- to 60 characters on the front page, which has no side nav; 30 +-- elsewhere. The table is rebuilt for that. +-- +-- Then what was the front page's own (front_page and its lists, 012 +-- to 074) becomes the home page's sections: the hero first, then +-- each band in its order, hidden ones kept hidden; and the Community +-- page's blog settings (community_page) move into its blog section. +-- Those tables go. A timeline section whose view is 'carousel' is +-- the rail of featured moments the front page showed; the full +-- timeline otherwise. +-- ═══════════════════════════════════════════════════════════════ + +CREATE TABLE page_sections_new ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + page_id TEXT NOT NULL REFERENCES site_pages (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + anchor TEXT NOT NULL + CONSTRAINT "A section's URL ID can use only lowercase letters, numbers and hyphens, eg. leadership." + CHECK (anchor <> '' AND anchor NOT GLOB '*[^a-z0-9-]*'), + title TEXT NOT NULL + CONSTRAINT "A section title can be 30 characters at most (it's listed in the page's side nav), 60 on the front page." + CHECK (length(title) <= CASE WHEN page_id = 'home' THEN 60 ELSE 30 END), + blurb TEXT, + accent TEXT CHECK (accent IN ('teal', 'deep', 'green', 'amber')), + preset TEXT CHECK (preset IN ('community_blog', 'group_map', 'region_list', 'partner_list', + 'events', 'timeline', 'people_directory', + 'feedback_form', 'request_form', 'data_request_form', 'giving', 'qr_maker', + 'hero', 'countdown', 'calendar', 'stats', 'featured_cards', 'connect')), + -- An events preset's filter and first view. + scope_id TEXT REFERENCES event_scopes (id) ON DELETE SET NULL, + event_type TEXT CHECK (event_type IN ('retreat', 'class', 'workshop', 'meeting', 'other')), + view TEXT CHECK (view IN ('carousel', 'grid', 'map')), + -- Organization cards (067): the kinds listed by themselves. + org_kinds TEXT CHECK (org_kinds IN ('partner', 'ministry', 'partner,ministry')), + is_hidden INTEGER NOT NULL DEFAULT 0 CHECK (is_hidden IN (0, 1)), + UNIQUE (page_id, anchor) +) STRICT; + +INSERT INTO page_sections_new + (id, page_id, sort_order, anchor, title, blurb, accent, preset, scope_id, event_type, view, org_kinds) +SELECT id, page_id, sort_order, anchor, title, blurb, accent, preset, scope_id, event_type, view, org_kinds + FROM page_sections; + +PRAGMA legacy_alter_table = ON; +DROP TABLE page_sections; +ALTER TABLE page_sections_new RENAME TO page_sections; +PRAGMA legacy_alter_table = OFF; + +CREATE INDEX page_sections_page_idx ON page_sections (page_id, sort_order); + +-- ── The settings tables ────────────────────────────────────────── + +CREATE TABLE section_hero ( + section_id INTEGER PRIMARY KEY REFERENCES page_sections (id) ON DELETE CASCADE, + eyebrow TEXT, + headline TEXT, + subhead TEXT, + primary_label TEXT, + primary_url TEXT, + secondary_label TEXT, + secondary_url TEXT, + backdrop TEXT NOT NULL DEFAULT 'brand' CHECK (backdrop IN ('brand', 'photos')), + slide_seconds INTEGER NOT NULL DEFAULT 7 CHECK (slide_seconds BETWEEN 3 AND 60), + feature TEXT NOT NULL DEFAULT 'none' CHECK (feature IN ('none', 'livestream', 'video', 'event')), + livestream_url TEXT, + livestream_title TEXT, + video_url TEXT, + video_title TEXT, + video_captions TEXT, + video_still TEXT, + event_id TEXT REFERENCES events (id) ON DELETE SET NULL +) STRICT; + +CREATE TABLE section_slides ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + section_id INTEGER NOT NULL REFERENCES page_sections (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + media TEXT NOT NULL, + alt TEXT, + caption TEXT, + link_url TEXT +) STRICT; +CREATE INDEX section_slides_section_idx ON section_slides (section_id, sort_order); + +CREATE TABLE section_countdown ( + section_id INTEGER PRIMARY KEY REFERENCES page_sections (id) ON DELETE CASCADE, + event_id TEXT REFERENCES events (id) ON DELETE SET NULL, + scope_id TEXT REFERENCES event_scopes (id) ON DELETE SET NULL, + event_type TEXT CHECK (event_type IN ('retreat', 'class', 'workshop', 'meeting', 'other')) +) STRICT; + +CREATE TABLE section_stats ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + section_id INTEGER NOT NULL REFERENCES page_sections (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + label TEXT NOT NULL, + source TEXT NOT NULL DEFAULT 'manual' + CHECK (source IN ('manual', 'years_since', 'regions', 'groups', + 'partners', 'events_held', 'retreats_held', + 'people', 'awards_given')), + value TEXT, + suffix TEXT, + note TEXT +) STRICT; +CREATE INDEX section_stats_section_idx ON section_stats (section_id, sort_order); + +CREATE TABLE section_paths ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + section_id INTEGER NOT NULL REFERENCES page_sections (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + label TEXT NOT NULL, + icon TEXT, + blurb TEXT +) STRICT; +CREATE INDEX section_paths_section_idx ON section_paths (section_id, sort_order); + +CREATE TABLE section_path_actions ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + path_id INTEGER NOT NULL REFERENCES section_paths (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + label TEXT NOT NULL, + description TEXT, + url TEXT NOT NULL +) STRICT; +CREATE INDEX section_path_actions_path_idx ON section_path_actions (path_id, sort_order); + +CREATE TABLE section_featured ( + section_id INTEGER PRIMARY KEY REFERENCES page_sections (id) ON DELETE CASCADE, + columns INTEGER CHECK (columns IN (2, 3, 4)) +) STRICT; + +CREATE TABLE section_blog ( + section_id INTEGER PRIMARY KEY REFERENCES page_sections (id) ON DELETE CASCADE, + internal_title TEXT, + internal_slots INTEGER NOT NULL DEFAULT 3 CHECK (internal_slots BETWEEN 0 AND 12), + external_title TEXT, + external_slots INTEGER NOT NULL DEFAULT 3 CHECK (external_slots BETWEEN 0 AND 12), + external_url TEXT, + external_label TEXT +) STRICT; + +CREATE TABLE section_blog_posts ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + section_id INTEGER NOT NULL REFERENCES page_sections (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + post_id TEXT NOT NULL REFERENCES blog_posts (id) ON DELETE CASCADE +) STRICT; +CREATE INDEX section_blog_posts_section_idx ON section_blog_posts (section_id, sort_order); + +CREATE TABLE section_feeds ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + section_id INTEGER NOT NULL REFERENCES page_sections (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + url TEXT NOT NULL, + label TEXT +) STRICT; +CREATE INDEX section_feeds_section_idx ON section_feeds (section_id, sort_order); + +-- ── featured_cards: owned by a section ─────────────────────────── + +CREATE TABLE featured_cards_new ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + owner_kind TEXT NOT NULL CHECK (owner_kind IN ('page_section', 'organization')), + owner_id TEXT NOT NULL, + sort_order INTEGER NOT NULL DEFAULT 0, + + kind TEXT NOT NULL DEFAULT 'link' + CHECK (kind IN ('record', 'link', 'video')), + + ref_kind TEXT CHECK (ref_kind IN ('event', 'organization', 'person', 'team', 'award')), + ref_id TEXT, + url TEXT, + + eyebrow TEXT, + title TEXT, + blurb TEXT, + image TEXT, + size TEXT CHECK (size IN ('normal', 'wide', 'tall', 'large')), + + CHECK ((ref_kind IS NULL) = (ref_id IS NULL)), + CONSTRAINT "A record card needs a record to point at." + CHECK (kind != 'record' OR ref_kind IS NOT NULL), + CONSTRAINT "A link or video card needs a URL." + CHECK (kind = 'record' OR url IS NOT NULL) +) STRICT; + +-- ── The Community blog into its section ────────────────────────── + +INSERT INTO section_blog (section_id, internal_title, internal_slots, external_title, external_slots, external_url, external_label) +SELECT s.id, c.internal_title, c.internal_slots, c.external_title, c.external_slots, c.external_url, c.external_label + FROM page_sections s, community_page c + WHERE s.page_id = 'community' AND s.preset = 'community_blog' AND c.id = 'community'; + +INSERT INTO section_blog_posts (section_id, sort_order, post_id) +SELECT s.id, p.sort_order, p.post_id + FROM page_sections s JOIN community_page_pinned_posts p ON p.page_id = 'community' + WHERE s.page_id = 'community' AND s.preset = 'community_blog'; + +INSERT INTO section_feeds (section_id, sort_order, url, label) +SELECT s.id, f.sort_order, f.url, f.label + FROM page_sections s JOIN community_page_feeds f ON f.page_id = 'community' + WHERE s.page_id = 'community' AND s.preset = 'community_blog'; + +INSERT INTO featured_cards_new + (owner_kind, owner_id, sort_order, kind, ref_kind, ref_id, url, eyebrow, title, blurb, image, size) +SELECT 'page_section', CAST(s.id AS TEXT), f.sort_order, f.kind, f.ref_kind, f.ref_id, f.url, f.eyebrow, f.title, f.blurb, f.image, f.size + FROM featured_cards f + JOIN page_sections s ON s.page_id = 'community' AND s.preset = 'community_blog' + WHERE f.owner_kind = 'community_page' + AND s.id = (SELECT min(id) FROM page_sections WHERE page_id = 'community' AND preset = 'community_blog'); + +-- ── The front page into the home page's sections ───────────────── + +-- The hero first. +INSERT INTO page_sections (page_id, sort_order, anchor, title, preset) +VALUES ('home', 0, 'hero', 'Welcome', 'hero'); + +INSERT INTO section_hero + (section_id, eyebrow, headline, subhead, primary_label, primary_url, secondary_label, secondary_url, + backdrop, slide_seconds, feature, livestream_url, livestream_title, video_url, video_title, + video_captions, video_still, event_id) +SELECT (SELECT id FROM page_sections WHERE page_id = 'home' AND anchor = 'hero'), + eyebrow, headline, subhead, primary_label, primary_url, secondary_label, secondary_url, + hero_backdrop, slide_seconds, hero_feature, livestream_url, livestream_title, video_url, video_title, + video_captions, video_still, hero_event_id + FROM front_page WHERE id = 'home'; + +INSERT INTO section_slides (section_id, sort_order, media, alt, caption, link_url) +SELECT (SELECT id FROM page_sections WHERE page_id = 'home' AND anchor = 'hero'), sort_order, media, alt, caption, link_url + FROM front_page_slides WHERE page_id = 'home'; + +-- A featured band, hidden, when the front page has cards but no band +-- for them, so they aren't lost. +INSERT INTO front_page_sections (page_id, sort_order, section, is_hidden) +SELECT 'home', 99, 'featured', 1 + WHERE NOT EXISTS (SELECT 1 FROM front_page_sections WHERE page_id = 'home' AND section = 'featured') + AND EXISTS (SELECT 1 FROM featured_cards WHERE owner_kind = 'front_page'); + +-- Each band, in its order: its section type, anchor and heading. +INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, preset, scope_id, event_type, view, is_hidden) +SELECT 'home', + b.sort_order + 1, + CASE b.section + WHEN 'countdown' THEN 'next-up' + WHEN 'stats' THEN 'numbers' + WHEN 'timeline' THEN 'story' + ELSE b.section + END, + substr(COALESCE(b.title, CASE b.section + WHEN 'countdown' THEN 'Next up' + WHEN 'retreats' THEN 'National Retreats' + WHEN 'calendar' THEN 'What''s on' + WHEN 'stats' THEN 'By the numbers' + WHEN 'timeline' THEN 'Our story so far' + WHEN 'connect' THEN 'Find your way in' + ELSE 'Featured' + END), 1, 60), + b.blurb, + CASE b.section + WHEN 'retreats' THEN 'events' + WHEN 'featured' THEN 'featured_cards' + ELSE b.section + END, + CASE WHEN b.section = 'retreats' THEN 'national' END, + CASE WHEN b.section = 'retreats' THEN 'retreat' END, + CASE WHEN b.section IN ('retreats', 'timeline') THEN 'carousel' END, + b.is_hidden + FROM front_page_sections b + WHERE b.page_id = 'home' + ORDER BY b.sort_order; + +-- The retreats band's link through to the Retreats page, as a button +-- above its carousel. +INSERT INTO content_blocks (owner_kind, owner_id, slot, sort_order, type, text, href) +SELECT 'page_section', CAST(id AS TEXT), 'body', 0, 'button', 'All retreats', '/retreats' + FROM page_sections WHERE page_id = 'home' AND anchor = 'retreats'; + +INSERT INTO section_countdown (section_id, event_id, scope_id, event_type) +SELECT (SELECT id FROM page_sections WHERE page_id = 'home' AND preset = 'countdown'), + countdown_event_id, countdown_scope_id, countdown_event_type + FROM front_page + WHERE id = 'home' AND EXISTS (SELECT 1 FROM page_sections WHERE page_id = 'home' AND preset = 'countdown'); + +INSERT INTO section_stats (section_id, sort_order, label, source, value, suffix, note) +SELECT (SELECT id FROM page_sections WHERE page_id = 'home' AND preset = 'stats'), + sort_order, label, source, value, suffix, note + FROM front_page_stats + WHERE page_id = 'home' AND EXISTS (SELECT 1 FROM page_sections WHERE page_id = 'home' AND preset = 'stats'); + +INSERT INTO section_paths (id, section_id, sort_order, label, icon, blurb) +SELECT id, (SELECT id FROM page_sections WHERE page_id = 'home' AND preset = 'connect'), + sort_order, label, icon, blurb + FROM front_page_paths + WHERE page_id = 'home' AND EXISTS (SELECT 1 FROM page_sections WHERE page_id = 'home' AND preset = 'connect'); + +INSERT INTO section_path_actions (path_id, sort_order, label, description, url) +SELECT a.path_id, a.sort_order, a.label, a.description, a.url + FROM front_page_path_actions a + WHERE a.path_id IN (SELECT id FROM section_paths); + +INSERT INTO section_featured (section_id, columns) +SELECT (SELECT id FROM page_sections WHERE page_id = 'home' AND preset = 'featured_cards'), featured_columns + FROM front_page + WHERE id = 'home' AND EXISTS (SELECT 1 FROM page_sections WHERE page_id = 'home' AND preset = 'featured_cards'); + +INSERT INTO featured_cards_new + (owner_kind, owner_id, sort_order, kind, ref_kind, ref_id, url, eyebrow, title, blurb, image, size) +SELECT 'page_section', (SELECT CAST(id AS TEXT) FROM page_sections WHERE page_id = 'home' AND preset = 'featured_cards'), + sort_order, kind, ref_kind, ref_id, url, eyebrow, title, blurb, image, size + FROM featured_cards + WHERE owner_kind = 'front_page' + AND EXISTS (SELECT 1 FROM page_sections WHERE page_id = 'home' AND preset = 'featured_cards'); + +-- An organization's own cards (072) come along as they are. +INSERT INTO featured_cards_new + (id, owner_kind, owner_id, sort_order, kind, ref_kind, ref_id, url, eyebrow, title, blurb, image, size) +SELECT id, owner_kind, owner_id, sort_order, kind, ref_kind, ref_id, url, eyebrow, title, blurb, image, size + FROM featured_cards WHERE owner_kind = 'organization'; + +-- Drafts of what's gone: the Front page editor is the home page's now. +DELETE FROM drafts WHERE entity = 'front_page'; + +-- ── What's gone ────────────────────────────────────────────────── + +-- The cleanup triggers on events, people, teams, awards and +-- organizations name featured_cards; legacy mode leaves them alone +-- through the rename. +PRAGMA legacy_alter_table = ON; +DROP TABLE featured_cards; +ALTER TABLE featured_cards_new RENAME TO featured_cards; +PRAGMA legacy_alter_table = OFF; +CREATE INDEX featured_cards_owner_idx ON featured_cards (owner_kind, owner_id, sort_order); + +DROP TABLE front_page_path_actions; +DROP TABLE front_page_paths; +DROP TABLE front_page_stats; +DROP TABLE front_page_slides; +DROP TABLE front_page_sections; +DROP TABLE front_page; +DROP TABLE community_page_pinned_posts; +DROP TABLE community_page_feeds; +DROP TABLE community_page; + +-- ── Triggers, last ─────────────────────────────────────────────── + +-- A section's blocks and its featured cards go with it. +CREATE TRIGGER page_sections_cleanup +AFTER DELETE ON page_sections +BEGIN + DELETE FROM content_blocks WHERE owner_kind = 'page_section' AND owner_id = CAST(old.id AS TEXT); + DELETE FROM featured_cards WHERE owner_kind = 'page_section' AND owner_id = CAST(old.id AS TEXT); +END; + +CREATE TRIGGER featured_cards_owner_exists +BEFORE INSERT ON featured_cards +BEGIN + SELECT CASE + WHEN new.owner_kind = 'organization' + AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.owner_id) + THEN RAISE(ABORT, 'featured_cards: no such organization') + WHEN new.owner_kind = 'page_section' + AND NOT EXISTS (SELECT 1 FROM page_sections WHERE CAST(id AS TEXT) = new.owner_id) + THEN RAISE(ABORT, 'featured_cards: no such page section') + END; +END; + +CREATE TRIGGER featured_cards_ref_exists +BEFORE INSERT ON featured_cards +BEGIN + SELECT CASE + WHEN new.ref_kind = 'event' + AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such event') + WHEN new.ref_kind = 'organization' + AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such organization') + WHEN new.ref_kind = 'person' + AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such person') + WHEN new.ref_kind = 'team' + AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such team') + WHEN new.ref_kind = 'award' + AND NOT EXISTS (SELECT 1 FROM awards WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such award') + END; +END; + +CREATE TRIGGER featured_cards_ref_exists_update +BEFORE UPDATE OF ref_kind, ref_id ON featured_cards +BEGIN + SELECT CASE + WHEN new.ref_kind = 'event' + AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such event') + WHEN new.ref_kind = 'organization' + AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such organization') + WHEN new.ref_kind = 'person' + AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such person') + WHEN new.ref_kind = 'team' + AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such team') + WHEN new.ref_kind = 'award' + AND NOT EXISTS (SELECT 1 FROM awards WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such award') + END; +END; diff --git a/server/src/pageMeta.js b/server/src/pageMeta.js index e583050..50685d8 100644 --- a/server/src/pageMeta.js +++ b/server/src/pageMeta.js @@ -24,7 +24,7 @@ heading and its search title can't drift. The database: records' names, taglines, first paragraphs and images. A blank site description falls back to the front page's - subhead. + hero's subhead. ── Rules ── published, listed indexed, in the sitemap @@ -167,8 +167,18 @@ function firstParagraph(db, ownerKind, id, slot) { const ORG_ROUTES = { region: "/regions", group: "/groups", partner: "/partners", national: "/organizations" }; +/* The front page's first hero (083): its subhead is the site's + description when Site settings and site.json have none. */ +const homeHero = (db) => + db + .prepare( + `SELECT h.* FROM section_hero h JOIN page_sections s ON s.id = h.section_id + WHERE s.page_id = 'home' AND s.is_hidden = 0 ORDER BY s.sort_order LIMIT 1`, + ) + .get(); + function defaults(site, db, pathname) { - const home = db.prepare(`SELECT headline, subhead FROM front_page WHERE id = 'home'`).get(); + const home = homeHero(db); return { status: 200, title: site.title, @@ -370,18 +380,16 @@ export function metaFor(db, rawPath, user = null) { // The home page's data, and its first hero photo when the hero is // a slideshow, requested alongside the app's JavaScript instead of // after it has run. - const hero = db.prepare(`SELECT hero_backdrop FROM front_page WHERE id = 'home'`).get(); + const hero = homeHero(db); const slide = - hero?.hero_backdrop === "photos" - ? db - .prepare(`SELECT media FROM front_page_slides WHERE page_id = 'home' ORDER BY sort_order LIMIT 1`) - .get() + hero?.backdrop === "photos" + ? db.prepare(`SELECT media FROM section_slides WHERE section_id = ? ORDER BY sort_order LIMIT 1`).get(hero.section_id) : null; const slideSrc = slide?.media ? (/^(https?:|\/)/.test(slide.media) ? slide.media : `${UPLOADS}/${slide.media}`) : null; return { ...meta, preload: [ - { href: "/api/front-page", as: "fetch" }, + { href: "/api/site-pages/home", as: "fetch" }, ...(slideSrc ? [{ href: slideSrc, as: "image" }] : []), ], jsonLd: { diff --git a/server/src/routes/blog.js b/server/src/routes/blog.js index f02799b..41975b7 100644 --- a/server/src/routes/blog.js +++ b/server/src/routes/blog.js @@ -24,13 +24,10 @@ import { Hono } from "hono"; -import { asBool, json, loadBlocks, loadFeaturedCards, marks } from "../shape.js"; -import { readFeeds } from "../feeds.js"; +import { asBool, json, loadBlocks, marks } from "../shape.js"; const blog = new Hono(); -const PAGE_ID = "community"; - const splitTags = (tags) => (tags ?? "") .split(",") @@ -38,7 +35,7 @@ const splitTags = (tags) => .filter(Boolean); /* Published authors for a batch of posts, keyed by post id. */ -function loadAuthors(db, ids) { +export function loadAuthors(db, ids) { const byPost = new Map(); if (ids.length === 0) return byPost; const rows = db @@ -67,7 +64,7 @@ function loadAuthors(db, ids) { /* The first paragraph of each post with no excerpt of its own, the card's fallback text, by post id. Only that one row per post: a card doesn't need the rest of the body. */ -function firstParagraphs(db, rows) { +export function firstParagraphs(db, rows) { const ids = rows.filter((row) => !row.excerpt).map((row) => row.id); if (ids.length === 0) return new Map(); const found = db @@ -84,7 +81,7 @@ function firstParagraphs(db, rows) { return new Map(found.map((row) => [row.owner_id, row.text])); } -function shapeSummary(row, authors, firstParagraph) { +export function shapeSummary(row, authors, firstParagraph) { return { id: row.id, title: row.title, @@ -148,83 +145,4 @@ blog.get("/blog/:id", (c) => { }); }); -/* ── The Community page's section ──────────────────────────── */ - -blog.get("/community-blog", async (c) => { - const db = c.get("db"); - - const page = db.prepare(`SELECT * FROM community_page WHERE id = ?`).get(PAGE_ID); - if (!page) return c.json({ error: "The community page hasn't been set up." }, 500); - - // Ours: pinned, then newest. - const pinned = db - .prepare( - `SELECT b.* - FROM community_page_pinned_posts pp - JOIN blog_posts b ON b.id = pp.post_id AND b.is_published = 1 - WHERE pp.page_id = ? - ORDER BY pp.sort_order`, - ) - .all(PAGE_ID); - - const room = Math.max(0, page.internal_slots - pinned.length); - const pinnedIds = pinned.map((row) => row.id); - const newest = room - ? db - .prepare( - `SELECT * FROM blog_posts - WHERE is_published = 1 AND is_listed = 1 - ${pinnedIds.length ? `AND id NOT IN (${marks(pinnedIds.length)})` : ""} - ORDER BY published_on IS NULL, published_on DESC, created_at DESC - LIMIT ?`, - ) - .all(...pinnedIds, room) - : []; - - const posts = [...pinned, ...newest]; - const ids = posts.map((row) => row.id); - const authors = loadAuthors(db, ids); - const first = firstParagraphs(db, posts); - - // Theirs: pinned cards, then the feeds' newest. - const cards = loadFeaturedCards(db, "community_page", PAGE_ID); - const feedRows = db - .prepare(`SELECT url, label FROM community_page_feeds WHERE page_id = ? ORDER BY sort_order`) - .all(PAGE_ID); - - const shown = new Set(cards.map((card) => card.url).filter(Boolean)); - const spare = Math.max(0, page.external_slots - cards.length); - const fromFeeds = spare && feedRows.length ? await readFeeds(feedRows) : []; - const latest = fromFeeds - .filter((item) => !shown.has(item.url)) - .slice(0, spare) - .map((item) => ({ - kind: "link", - ref: null, - url: item.url, - eyebrow: item.source, - title: item.title, - blurb: item.excerpt, - image: item.image ? { file: item.image, kind: "featured" } : null, - published: item.published, - })); - - return json(c, { - community_blog: { - internal: { - title: page.internal_title, - posts: posts.map((row) => - shapeSummary(row, authors.get(row.id) ?? [], first.get(row.id)), - ), - }, - external: { - title: page.external_title, - url: page.external_url, - label: page.external_label, - cards: [...cards, ...latest], - }, - }, - }); -}); - export default blog; diff --git a/server/src/routes/home.js b/server/src/routes/home.js deleted file mode 100644 index 523f369..0000000 --- a/server/src/routes/home.js +++ /dev/null @@ -1,243 +0,0 @@ -/* ═══════════════════════════════════════════════════════════════ - FRONT PAGE ROUTE: read-only, mounted under /api - - GET /front-page the home page's configuration, resolved - - Everything the admin's Front page editor holds, shaped for the - page: hidden sections dropped, stats counted, paths carrying - their actions, and the countdown's event looked up. - - The retreats carousel and the timeline rail are not in here. - They fetch /events and /history themselves, as they do on their - own pages, so the rules for which events and entries are public - live in one place each. This route only says whether those bands - appear and under what heading. - - ── Stats ── - A stat's source picks a query from STAT_QUERIES. Each counts - exactly what the matching public page shows: published, listed - rows, and for awards only public citations to published people - (an award's page names its recipients whether they're listed or - not, so the count does too). A count - that disagreed with the page it summarizes would be worse than - none. 'manual' and 'years_since' read the row's own value. - - ── Countdown ── - The pinned event if it is still published and not over, listed - or not; otherwise the next published, listed, non-canceled - event that hasn't ended. "Hasn't ended" is COALESCE(ends_on, starts_on) >= today, - so a running series with a start date in the past still counts. - The client works out the next meeting of a series from `series`. - - countdown_scope_id and countdown_event_type narrow "the next - event" (National + Retreat skips a sooner regional class). Null - means any. They don't apply to a pinned event: the admin chose - that one by name. - - ── Hero event ── - With the 'event' feature, the hero draws the pinned hero_event_id - if it's still published and not over, else the countdown's event - (above), so the two never disagree. Its action links ride along - for the card's buttons. - - ── Featured ── - The featured band's cards, record cards filled in from their - records (loadFeaturedCards in shape.js, which the Community - blog will share). - ═══════════════════════════════════════════════════════════════ */ - -import { Hono } from "hono"; - -import { asBool, json, loadFeaturedCards, loadLinks, shapeSeries, splitLinks } from "../shape.js"; - -const home = new Hono(); - -const PAGE_ID = "home"; - -const STAT_QUERIES = { - regions: `SELECT COUNT(*) AS n FROM organizations WHERE kind = 'region' AND is_published = 1 AND is_listed = 1`, - groups: `SELECT COUNT(*) AS n FROM organizations WHERE kind = 'group' AND is_published = 1 AND is_listed = 1`, - partners: `SELECT COUNT(*) AS n FROM organizations WHERE kind = 'partner' AND is_published = 1 AND is_listed = 1`, - events_held: `SELECT COUNT(*) AS n FROM v_events - WHERE is_published = 1 AND is_listed = 1 AND effective_status = 'past'`, - retreats_held: `SELECT COUNT(*) AS n FROM v_events - WHERE is_published = 1 AND is_listed = 1 AND effective_status = 'past' - AND event_type = 'retreat'`, - people: `SELECT COUNT(*) AS n FROM people WHERE is_published = 1 AND is_listed = 1`, - awards_given: `SELECT COUNT(*) AS n - FROM person_awards pa - JOIN v_people_public p ON p.id = pa.person_id AND p.is_published = 1 - JOIN awards a ON a.id = pa.award_id AND a.is_published = 1 - WHERE pa.is_public = 1`, -}; - -/* The number as a string, or null when there's nothing to print: - a manual stat nobody filled in, or a year that isn't one. */ -function statValue(db, row) { - if (row.source === "manual") return row.value || null; - - if (row.source === "years_since") { - const year = Number.parseInt(row.value ?? "", 10); - if (!Number.isInteger(year)) return null; - return String(Math.max(0, new Date().getFullYear() - year)); - } - - const sql = STAT_QUERIES[row.source]; - return sql ? String(db.prepare(sql).get().n) : null; -} - -/* The countdown's fields plus what the hero's event card also draws: - its tagline, place, photo and buttons. */ -function shapeHeroEvent(db, row) { - if (!row) return null; - const { actions } = splitLinks(loadLinks(db, "event", [row.id]).get(row.id) ?? []); - return { - ...shapeCountdown(row), - tagline: row.tagline, - photo: row.photo, - photo_alt: row.photo_alt, - org_logo: row.effective_org_logo, - links: actions, - }; -} - -function shapeCountdown(row) { - if (!row) return null; - return { - id: row.id, - title: row.title, - theme: row.theme, - starts_on: row.starts_on, - ends_on: row.ends_on, - date_label: row.date_label, - location_label: row.location_label, - is_online: asBool(row.is_online), - color: row.effective_color, - event_logo: row.event_logo, - series: shapeSeries(row), - }; -} - -home.get("/front-page", (c) => { - const db = c.get("db"); - - const page = db.prepare(`SELECT * FROM front_page WHERE id = ?`).get(PAGE_ID); - - // The schema seeds the row and the engine refuses to delete it, - // so this is a database that hasn't been migrated. Say so. - if (!page) return c.json({ error: "The front page hasn't been set up." }, 500); - - const byOrder = (table) => - db.prepare(`SELECT * FROM ${table} WHERE page_id = ? ORDER BY sort_order`).all(PAGE_ID); - - const sections = byOrder("front_page_sections") - .filter((row) => !asBool(row.is_hidden)) - .map((row) => ({ section: row.section, title: row.title, blurb: row.blurb })); - - const slides = byOrder("front_page_slides").map((row) => ({ - media: row.media, - alt: row.alt, - caption: row.caption, - link_url: row.link_url, - })); - - const stats = byOrder("front_page_stats") - .map((row) => ({ - label: row.label, - value: statValue(db, row), - suffix: row.suffix, - note: row.note, - })) - .filter((stat) => stat.value !== null); - - const actions = db.prepare( - `SELECT label, description, url FROM front_page_path_actions - WHERE path_id = ? ORDER BY sort_order`, - ); - const paths = byOrder("front_page_paths") - .map((row) => ({ - label: row.label, - icon: row.icon, - blurb: row.blurb, - actions: actions.all(row.id), - })) - // A path with nothing to do is a dead tab. - .filter((path) => path.actions.length > 0); - - const notOver = `is_published = 1 - AND effective_status != 'cancelled' - AND COALESCE(ends_on, starts_on) >= date('now')`; - - const pinned = page.countdown_event_id - ? db - .prepare(`SELECT * FROM v_events WHERE id = ? AND ${notOver}`) - .get(page.countdown_event_id) - : null; - - const filters = []; - const params = []; - if (page.countdown_scope_id) { - filters.push("AND scope_id = ?"); - params.push(page.countdown_scope_id); - } - if (page.countdown_event_type) { - filters.push("AND event_type = ?"); - params.push(page.countdown_event_type); - } - - const next = - pinned ?? - db - .prepare( - `SELECT * FROM v_events - WHERE ${notOver} AND is_listed = 1 ${filters.join(" ")} - ORDER BY starts_on, title - LIMIT 1`, - ) - .get(...params); - - const heroEvent = - page.hero_feature === "event" - ? (page.hero_event_id - ? db - .prepare(`SELECT * FROM v_events WHERE id = ? AND ${notOver}`) - .get(page.hero_event_id) - : null) ?? next - : null; - - return json(c, { - front_page: { - hero: { - backdrop: page.hero_backdrop, - feature: page.hero_feature, - eyebrow: page.eyebrow, - headline: page.headline, - subhead: page.subhead, - primary: page.primary_label && page.primary_url - ? { label: page.primary_label, url: page.primary_url } - : null, - secondary: page.secondary_label && page.secondary_url - ? { label: page.secondary_label, url: page.secondary_url } - : null, - slide_seconds: page.slide_seconds, - slides, - livestream: page.livestream_url - ? { url: page.livestream_url, title: page.livestream_title } - : null, - video: page.video_url - ? { url: page.video_url, title: page.video_title, captions: page.video_captions, still: page.video_still } - : null, - event: shapeHeroEvent(db, heroEvent), - }, - sections, - stats, - paths, - featured: loadFeaturedCards(db, "front_page", PAGE_ID), - // 2, 3 or 4 across (073); null is the grid's own default. - featured_columns: page.featured_columns, - countdown: shapeCountdown(next), - }, - }); -}); - -export default home; diff --git a/server/src/routes/sitePages.js b/server/src/routes/sitePages.js index 491ab1d..9d7d780 100644 --- a/server/src/routes/sitePages.js +++ b/server/src/routes/sitePages.js @@ -7,8 +7,9 @@ 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, + GET /site-pages/:id one page's title and intro and its shown + sections, in order, each with what its type + shows (sectionData.js): heading, accent, preset (and an events preset's filter and view), and its blocks; Not found for a hidden page, below viewer @@ -22,6 +23,7 @@ import { Hono } from "hono"; import { currentUser } from "../auth.js"; import { navFor, seesHidden } from "../siteNav.js"; import { NO_STORE, json, loadBlocks } from "../shape.js"; +import { withSectionData } from "../sectionData.js"; const sitePages = new Hono(); @@ -34,17 +36,18 @@ sitePages.get("/site-pages", (c) => { const rows = c .get("db") .prepare( - `SELECT p.path, s.anchor, s.title FROM page_sections s JOIN site_pages p ON p.id = s.page_id + `SELECT p.path, s.anchor, s.title, s.preset FROM page_sections s JOIN site_pages p ON p.id = s.page_id + WHERE s.is_hidden = 0 ORDER BY p.path, s.sort_order, s.id`, ) .all(); const pages = {}; - for (const row of rows) (pages[row.path] ??= []).push({ anchor: row.anchor, title: row.title }); + for (const row of rows) (pages[row.path] ??= []).push({ anchor: row.anchor, title: row.title, preset: row.preset }); return json(c, { pages }); }); -sitePages.get("/site-pages/:id", (c) => { +sitePages.get("/site-pages/:id", async (c) => { const db = c.get("db"); const id = c.req.param("id"); const found = db.prepare(`SELECT title, description, is_hidden FROM site_pages WHERE id = ?`).get(id); @@ -56,7 +59,7 @@ sitePages.get("/site-pages/:id", (c) => { const rows = db .prepare( `SELECT id, anchor, title, blurb, accent, preset, scope_id, event_type, view, org_kinds - FROM page_sections WHERE page_id = ? ORDER BY sort_order, id`, + FROM page_sections WHERE page_id = ? AND is_hidden = 0 ORDER BY sort_order, id`, ) .all(id); const blocks = loadBlocks(db, "page_section", rows.map((row) => String(row.id))); @@ -82,6 +85,8 @@ sitePages.get("/site-pages/:id", (c) => { tags.set(section_id, [...(tags.get(section_id) ?? []), tag_id]); } + const sections = await withSectionData(db, rows); + // A hidden page is only for those signed in: never kept. const send = hidden ? (body) => c.json(body, 200, NO_STORE) : (body) => json(c, body); return send({ @@ -89,7 +94,7 @@ sitePages.get("/site-pages/:id", (c) => { id, title: found.title, description: found.description, - sections: rows.map(({ id: sectionId, ...section }) => ({ + sections: sections.map(({ id: sectionId, ...section }) => ({ ...section, blocks: blocks.get(String(sectionId)) ?? [], org_ids: picked.get(sectionId) ?? [], diff --git a/server/src/sectionData.js b/server/src/sectionData.js new file mode 100644 index 0000000..ba9cf75 --- /dev/null +++ b/server/src/sectionData.js @@ -0,0 +1,288 @@ +/* ═══════════════════════════════════════════════════════════════ + SECTION DATA + + What a section type shows beyond its blocks, resolved for the page + (routes/sitePages.js, GET /site-pages/:id), from its settings + tables (083_section_settings.sql): + + hero its words, buttons, backdrop, slides, and the + event its card shows (with the 'event' feature) + countdown the event it counts down to + stats its numbers, counted + connect its paths, each with its links + featured_cards its cards, record cards filled in from their + records + community_blog our posts (pinned, then newest) and community + posts (pinned cards, then its feeds' newest) + + ── Stats ── + A stat's source picks a query from STAT_QUERIES. Each counts + exactly what the matching public page shows: published, listed + rows, and for awards only public citations to published people. + A count that disagreed with the page it summarizes would be worse + than none. 'manual' and 'years_since' read the row's own value. + + ── Countdown ── + The pinned event if it is still published and not over, listed + or not; otherwise the next published, listed, non-canceled event + that hasn't ended (COALESCE(ends_on, starts_on) >= today, so a + running series still counts), narrowed by the section's scope and + type. The client works out a series' next meeting from `series`. + + ── Hero event ── + With the 'event' feature, the hero draws its pinned event if it's + still published and not over, else the page's countdown's event, + else the next event, so the two never disagree. + ═══════════════════════════════════════════════════════════════ */ + +import { asBool, loadFeaturedCards, loadLinks, marks, shapeSeries, splitLinks } from "./shape.js"; +import { readFeeds } from "./feeds.js"; +import { firstParagraphs, loadAuthors, shapeSummary } from "./routes/blog.js"; + +const STAT_QUERIES = { + regions: `SELECT COUNT(*) AS n FROM organizations WHERE kind = 'region' AND is_published = 1 AND is_listed = 1`, + groups: `SELECT COUNT(*) AS n FROM organizations WHERE kind = 'group' AND is_published = 1 AND is_listed = 1`, + partners: `SELECT COUNT(*) AS n FROM organizations WHERE kind = 'partner' AND is_published = 1 AND is_listed = 1`, + events_held: `SELECT COUNT(*) AS n FROM v_events + WHERE is_published = 1 AND is_listed = 1 AND effective_status = 'past'`, + retreats_held: `SELECT COUNT(*) AS n FROM v_events + WHERE is_published = 1 AND is_listed = 1 AND effective_status = 'past' + AND event_type = 'retreat'`, + people: `SELECT COUNT(*) AS n FROM people WHERE is_published = 1 AND is_listed = 1`, + awards_given: `SELECT COUNT(*) AS n + FROM person_awards pa + JOIN v_people_public p ON p.id = pa.person_id AND p.is_published = 1 + JOIN awards a ON a.id = pa.award_id AND a.is_published = 1 + WHERE pa.is_public = 1`, +}; + +/* The number as a string, or null when there's nothing to print. */ +function statValue(db, row) { + if (row.source === "manual") return row.value || null; + if (row.source === "years_since") { + const year = Number.parseInt(row.value ?? "", 10); + if (!Number.isInteger(year)) return null; + return String(Math.max(0, new Date().getFullYear() - year)); + } + const sql = STAT_QUERIES[row.source]; + return sql ? String(db.prepare(sql).get().n) : null; +} + +function shapeCountdown(row) { + if (!row) return null; + return { + id: row.id, + title: row.title, + theme: row.theme, + starts_on: row.starts_on, + ends_on: row.ends_on, + date_label: row.date_label, + location_label: row.location_label, + is_online: asBool(row.is_online), + color: row.effective_color, + event_logo: row.event_logo, + series: shapeSeries(row), + }; +} + +/* The countdown's fields plus what the hero's event card also draws. */ +function shapeHeroEvent(db, row) { + if (!row) return null; + const { actions } = splitLinks(loadLinks(db, "event", [row.id]).get(row.id) ?? []); + return { + ...shapeCountdown(row), + tagline: row.tagline, + photo: row.photo, + photo_alt: row.photo_alt, + org_logo: row.effective_org_logo, + links: actions, + }; +} + +const NOT_OVER = `is_published = 1 + AND effective_status != 'cancelled' + AND COALESCE(ends_on, starts_on) >= date('now')`; + +const pinnedEvent = (db, id) => + id ? db.prepare(`SELECT * FROM v_events WHERE id = ? AND ${NOT_OVER}`).get(id) ?? null : null; + +/* A countdown's event: the pinned one, else the next of its scope and type. */ +function countdownEvent(db, settings) { + const pinned = pinnedEvent(db, settings?.event_id); + if (pinned) return pinned; + const filters = []; + const params = []; + if (settings?.scope_id) { + filters.push("AND scope_id = ?"); + params.push(settings.scope_id); + } + if (settings?.event_type) { + filters.push("AND event_type = ?"); + params.push(settings.event_type); + } + return ( + db + .prepare( + `SELECT * FROM v_events + WHERE ${NOT_OVER} AND is_listed = 1 ${filters.join(" ")} + ORDER BY starts_on, title + LIMIT 1`, + ) + .get(...params) ?? null + ); +} + +const byOrder = (db, table, column, id) => + db.prepare(`SELECT * FROM ${table} WHERE ${column} = ? ORDER BY sort_order, id`).all(id); + +function heroOf(db, section, pageCountdown) { + const h = db.prepare(`SELECT * FROM section_hero WHERE section_id = ?`).get(section.id) ?? {}; + const event = + h.feature === "event" ? pinnedEvent(db, h.event_id) ?? pageCountdown ?? countdownEvent(db, null) : null; + return { + backdrop: h.backdrop ?? "brand", + feature: h.feature ?? "none", + eyebrow: h.eyebrow ?? null, + headline: h.headline ?? "", + subhead: h.subhead ?? null, + primary: h.primary_label && h.primary_url ? { label: h.primary_label, url: h.primary_url } : null, + secondary: h.secondary_label && h.secondary_url ? { label: h.secondary_label, url: h.secondary_url } : null, + slide_seconds: h.slide_seconds ?? 7, + slides: byOrder(db, "section_slides", "section_id", section.id).map((row) => ({ + media: row.media, + alt: row.alt, + caption: row.caption, + link_url: row.link_url, + })), + livestream: h.livestream_url ? { url: h.livestream_url, title: h.livestream_title } : null, + video: h.video_url + ? { url: h.video_url, title: h.video_title, captions: h.video_captions, still: h.video_still } + : null, + event: shapeHeroEvent(db, event), + }; +} + +function pathsOf(db, section) { + const actions = db.prepare( + `SELECT label, description, url FROM section_path_actions WHERE path_id = ? ORDER BY sort_order, id`, + ); + return ( + byOrder(db, "section_paths", "section_id", section.id) + .map((row) => ({ label: row.label, icon: row.icon, blurb: row.blurb, actions: actions.all(row.id) })) + // A path with nothing to do is a dead tab. + .filter((path) => path.actions.length > 0) + ); +} + +async function blogOf(db, section) { + const page = db.prepare(`SELECT * FROM section_blog WHERE section_id = ?`).get(section.id) ?? { + internal_slots: 3, + external_slots: 3, + }; + + // Ours: pinned, then newest. + const pinned = db + .prepare( + `SELECT b.* + FROM section_blog_posts pp + JOIN blog_posts b ON b.id = pp.post_id AND b.is_published = 1 + WHERE pp.section_id = ? + ORDER BY pp.sort_order`, + ) + .all(section.id); + const room = Math.max(0, page.internal_slots - pinned.length); + const pinnedIds = pinned.map((row) => row.id); + const newest = room + ? db + .prepare( + `SELECT * FROM blog_posts + WHERE is_published = 1 AND is_listed = 1 + ${pinnedIds.length ? `AND id NOT IN (${marks(pinnedIds.length)})` : ""} + ORDER BY published_on IS NULL, published_on DESC, created_at DESC + LIMIT ?`, + ) + .all(...pinnedIds, room) + : []; + const posts = [...pinned, ...newest]; + const authors = loadAuthors(db, posts.map((row) => row.id)); + const first = firstParagraphs(db, posts); + + // Theirs: pinned cards, then the feeds' newest. + const cards = loadFeaturedCards(db, "page_section", String(section.id)); + const feedRows = db + .prepare(`SELECT url, label FROM section_feeds WHERE section_id = ? ORDER BY sort_order`) + .all(section.id); + const shown = new Set(cards.map((card) => card.url).filter(Boolean)); + const spare = Math.max(0, page.external_slots - cards.length); + const fromFeeds = spare && feedRows.length ? await readFeeds(feedRows) : []; + const latest = fromFeeds + .filter((item) => !shown.has(item.url)) + .slice(0, spare) + .map((item) => ({ + kind: "link", + ref: null, + url: item.url, + eyebrow: item.source, + title: item.title, + blurb: item.excerpt, + image: item.image ? { file: item.image, kind: "featured" } : null, + published: item.published, + })); + + return { + internal: { + title: page.internal_title, + posts: posts.map((row) => shapeSummary(row, authors.get(row.id) ?? [], first.get(row.id))), + }, + external: { + title: page.external_title, + url: page.external_url, + label: page.external_label, + cards: [...cards, ...latest], + }, + }; +} + +/* Each section with what its type shows, as `data`. A page's first + countdown is the event its heroes fall back to. */ +export async function withSectionData(db, sections) { + const countdown = sections.find((s) => s.preset === "countdown"); + const pageCountdown = countdown + ? countdownEvent(db, db.prepare(`SELECT * FROM section_countdown WHERE section_id = ?`).get(countdown.id)) + : null; + + return Promise.all( + sections.map(async (section) => { + switch (section.preset) { + case "hero": + return { ...section, data: heroOf(db, section, pageCountdown) }; + case "countdown": { + const settings = db.prepare(`SELECT * FROM section_countdown WHERE section_id = ?`).get(section.id); + const event = section === countdown ? pageCountdown : countdownEvent(db, settings); + return { ...section, data: shapeCountdown(event) }; + } + case "stats": + return { + ...section, + data: byOrder(db, "section_stats", "section_id", section.id) + .map((row) => ({ label: row.label, value: statValue(db, row), suffix: row.suffix, note: row.note })) + .filter((stat) => stat.value !== null), + }; + case "connect": + return { ...section, data: pathsOf(db, section) }; + case "featured_cards": + return { + ...section, + data: { + cards: loadFeaturedCards(db, "page_section", String(section.id)), + columns: db.prepare(`SELECT columns FROM section_featured WHERE section_id = ?`).get(section.id)?.columns ?? null, + }, + }; + case "community_blog": + return { ...section, data: await blogOf(db, section) }; + default: + return section; + } + }), + ); +} diff --git a/server/src/shape.js b/server/src/shape.js index 8881f2b..715497c 100644 --- a/server/src/shape.js +++ b/server/src/shape.js @@ -212,7 +212,7 @@ export function splitLinks(links = []) { first; an empty list means "starts_on's weekday", which the client resolves since it already holds starts_on. Occurrences are not sent, they are derived, and the client derives them - against its own today. Shared by /events and /front-page. + against its own today. Shared by /events and the sections (sectionData.js). ───────────────────────────────────────────────────────────── */ const SERIES_WEEKDAYS = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"]; diff --git a/src/App.tsx b/src/App.tsx index 1d3e7ad..015cc07 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -14,13 +14,12 @@ import { AuthProvider, RequireAuth } from "./lib/auth.tsx" import RequireRole from "./pages/admin/RequireRole.tsx" /*Pages*/ -// Home is the landing page, so it ships in the main bundle. Every -// other page, and all of the admin, is fetched when first visited: -// a visitor to the front page never downloads the admin, the QR -// encoder, the calendar or the group map. Layout and AdminLayout -// wrap their in , so the header stays put while -// a page loads. -import Home from "./pages/Home.tsx" +// Every page, the front page included, and all of the admin, is +// fetched when first visited: a visitor never downloads the admin, +// and a page's own parts come with it. The front page's data is asked +// for by its HTML before this runs (pageMeta.js, preload). Layout and +// AdminLayout wrap their in , so the header stays +// put while a page loads. /* A page's chunk can be missing when a deploy replaced the build while this tab still ran the old one. Reload once to pick up the new @@ -51,6 +50,8 @@ const lazyPage = (load) => ) // Every page at its address (Pages → Page management): its sections. const PageAtPath = lazyPage(() => import("./pages/PageAtPath.tsx")) +// The front page: its sections, in the front page's layout. +const SitePage = lazyPage(() => import("./pages/SitePage.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")) @@ -91,7 +92,7 @@ export default function App() { {/* Layout renders the nav once and swaps page content into */} }> - } /> + } /> } /> } /> } /> diff --git a/src/components/FeaturedCards.tsx b/src/components/FeaturedCards.tsx index 9f95836..23ca4eb 100644 --- a/src/components/FeaturedCards.tsx +++ b/src/components/FeaturedCards.tsx @@ -42,7 +42,7 @@ import HomeLink from '../pages/sections/home/HomeLink.tsx' import VideoPlayer from './VideoPlayer.tsx' import { refHref } from '../lib/hrefs.ts' import { mediaUrl } from '../lib/media.ts' -import type { FeaturedCard, FeaturedColumns, FeaturedSize } from '../lib/useFrontPage.ts' +import type { FeaturedCard, FeaturedColumns, FeaturedSize } from '../lib/sectionTypes.ts' import { useReadingMode } from '../lib/readingMode.ts' import { useSmallImage } from '../lib/useSmallImage.ts' diff --git a/src/components/PageShell.tsx b/src/components/PageShell.tsx index 2a73468..5a98c26 100644 --- a/src/components/PageShell.tsx +++ b/src/components/PageShell.tsx @@ -54,6 +54,10 @@ export type ShellSection = { accent: string; actions?: ReactNode; content: ReactNode; + /** It draws its own heading (a band, sections/Bands.tsx): the shell adds none. */ + bare?: boolean; + /** Left out of the side nav (the hero, a countdown). */ + unlisted?: boolean; }; type PageShellProps = { @@ -75,8 +79,12 @@ export function Section({ section }: { section: ShellSection }) { // shell just gives it a place to sit. actions, content, + bare, } = section; + // A band brings its own heading, padding and anchor. + if (bare) return <>{content}; + return (
ro.disconnect(); }, [sideNav]); - const navSections = sideNav ? sections.map((s) => ({ id: s.id, label: s.title, accent: s.accent })) : []; + const navSections = sideNav + ? sections.filter((s) => !s.unlisted).map((s) => ({ id: s.id, label: s.title, accent: s.accent })) + : []; const active = useActiveSection(navSections); const activeAccent = sections.find((s) => s.id === active)?.accent; diff --git a/src/data/pathIcons.ts b/src/data/pathIcons.ts index c6be376..f34c020 100644 --- a/src/data/pathIcons.ts +++ b/src/data/pathIcons.ts @@ -1,7 +1,7 @@ /* ═══════════════════════════════════════════════════════════════ PATH ICONS - The icons a "Find your way in" path can show (Front page → + The icons a "Find your way in" path can show (Pages → a page's Connect nav section → Connect Nav → Icon), as [key, label]. The admin's dropdown lists the labels; Pathfinder.tsx draws the Phosphor icon for each key. Adding one is a line here and one in ICONS in Pathfinder.tsx. diff --git a/src/lib/adminSchema.ts b/src/lib/adminSchema.ts index 56a654e..053a7c8 100644 --- a/src/lib/adminSchema.ts +++ b/src/lib/adminSchema.ts @@ -25,7 +25,6 @@ import { people } from "./adminSchema/people.ts"; import { teams } from "./adminSchema/teams.ts"; import { awards } from "./adminSchema/awards.ts"; 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"; @@ -46,7 +45,6 @@ export const ADMIN_ENTITIES: Record = { teams, awards, timeline, - front_page: frontPage, blog_posts: blogPosts, pages, navigation: siteNav, @@ -65,7 +63,6 @@ export const PREVIEW_PATHS: Record string | null> = { teams: (row) => teamHref(row.id), awards: (row) => awardHref(row.id), timeline: () => "/history", - front_page: () => "/", blog_posts: (row) => blogHref(row.id), pages: (row) => row.path || null, // The menus are on every page. diff --git a/src/lib/adminSchema/frontPage.ts b/src/lib/adminSchema/frontPage.ts deleted file mode 100644 index cfaf6e4..0000000 --- a/src/lib/adminSchema/frontPage.ts +++ /dev/null @@ -1,306 +0,0 @@ -import { mediaUrl } from "../media.ts"; -import { featuredCardsChild } from "./shared.ts"; -import { PATH_ICONS } from "../../data/pathIcons.ts"; - -/* ── Front page ────────────────────────────────────────────────── - - One record (see the singleton note in server/src/admin-schema.js). - The groups are the hero; the collections below are the rest of - the page. Photos, the livestream and the featured video are - editable whatever the mode, so each can be ready before the - switch is flipped. - - Section keys and stat sources are the CHECK lists on - front_page_sections and front_page_stats. The labels here are what the admin reads; the values are - what the page and the API key on. */ - -const FRONT_PAGE_SECTIONS = [ - ["countdown", "Event Countdown"], - ["retreats", "Events Carousel (National Retreats)"], - ["calendar", "Event Calendar"], - ["stats", "Stats"], - ["timeline", "Featured Timeline"], - ["connect", "Connect Nav"], - ["featured", "Featured Content"], -]; - -const STAT_SOURCES = [ - ["manual", "Print Value Field"], - ["years_since", "Years Since Value"], - ["regions", "Count: regions"], - ["groups", "Count: groups"], - ["partners", "Count: partners"], - ["events_held", "Count: past events"], - ["retreats_held", "Count: past retreats"], - ["people", "Count: people in database"], - ["awards_given", "Count: public awards given"], -]; - -export const frontPage = { - key: "front_page", - label: "Front page", - singular: "front page", - idLabel: "Page", - singleton: "home", - - list: { columns: [], filters: [] }, - - groups: [ - { - legend: "Hero - Primary Section", - note: "The first thing a visitor sees. Blank buttons don't render.", - fields: [ - { - path: "hero_backdrop", - label: "Background", - widget: "select", - options: [ - ["brand", "Brand: animated color and the dove"], - ["photos", "Photos: cycles through the photos below"], - ], - blankLabel: "Default: brand", - help: "Photos with none added shows the brand background", - }, - { - path: "hero_feature", - label: "Feature", - widget: "select", - options: [ - ["none", "Nothing: No additional overlay"], - ["livestream", "Livestream: the stream, with a LIVE badge"], - ["video", "Featured video: click to play"], - ["event", "Featured event: an event's card"], - ], - blankLabel: "Default: nothing", - help: "Switch to Livestream when you go live, and back when you're done", - }, - { path: "eyebrow", label: "Eyebrow", help: "Small line above the headline" }, - { path: "headline", label: "Headline", full: true }, - { path: "subhead", label: "Subhead", widget: "textarea", full: true }, - { path: "primary_label", label: "Main button label" }, - { path: "primary_url", label: "Main button link", help: "/page, #section-id or a full URL" }, - { path: "secondary_label", label: "Second button label" }, - { path: "secondary_url", label: "Second button link" }, - ], - }, - { - legend: "Photos, livestream, video and event", - fields: [ - { - path: "slide_seconds", - label: "Seconds per photo", - widget: "number", - help: "Photos Background. Set from 3 to 60 seconds", - }, - { - path: "livestream_url", - label: "Livestream link", - full: true, - help: "A YouTube, Facebook or Vimeo link, or any embed URL", - }, - { path: "livestream_title", label: "Livestream title", full: true }, - { - path: "video_url", - label: "Featured video", - full: true, - help: - "A YouTube, Vimeo or Facebook link, or a video file: a filename in " + - "the uploads folder, or a link ending in .mp4 or .webm", - }, - { - path: "video_still", - label: "Video still", - widget: "image", - crop: 16 / 9, - resolve: mediaUrl, - full: true, - frameFrom: "video_url", - help: "Shown before it plays. Default: YouTube's own thumbnail, or a video file's first frame. Frame at takes a still from a YouTube or Facebook video.", - }, - { - path: "video_captions", - label: "Video captions", - widget: "image", - folder: "captions", - resolve: mediaUrl, - full: true, - help: "A WebVTT (.vtt) file, for a video file; YouTube, Vimeo and Facebook show their own. Default: none.", - }, - { path: "video_title", label: "Video title", full: true, help: "Shown after \"Featured video\" above the headline" }, - { - path: "hero_event_id", - label: "Featured event", - widget: "select", - optionsFrom: "events", - blankLabel: "Default: the countdown's event", - full: true, - help: "For the Featured event feature. A pinned event that's over falls back to the countdown's", - }, - ], - }, - { - legend: "Countdown", - fields: [ - { - path: "countdown_event_id", - label: "Count down to", - widget: "select", - optionsFrom: "events", - blankLabel: "Default: the next upcoming event", - help: "Leave blank almost always. A pinned event that's over falls back to the next one", - }, - { - path: "countdown_scope_id", - label: "Only this scope", - widget: "select", - optionsFrom: "event_scopes", - blankLabel: "Default: any scope", - help: "Narrows the next upcoming event. Ignored when an event is pinned above", - }, - { - path: "countdown_event_type", - label: "Only this type", - widget: "select", - options: [ - ["retreat", "Retreat"], - ["class", "Class"], - ["workshop", "Workshop"], - ["meeting", "Meeting"], - ["other", "Other"], - ], - blankLabel: "Default: any type", - help: "Combines with the scope: National + Retreat counts down to the next national retreat", - }, - ], - }, - { - legend: "Featured Content", - note: "The cards themselves are under Featured cards below, each with its own Size.", - fields: [ - { - path: "featured_columns", - label: "Columns", - widget: "select", - options: [ - ["2", "2 across"], - ["3", "3 across"], - ["4", "4 across"], - ], - blankLabel: "Default: 3 across", - help: "On a wide screen. Tablets show 2, phones 1", - }, - ], - }, - ], - - children: [ - { - key: "sections", - label: "Page sections", - note: "Drag to reorder. Each section can appear once; leave one out to drop it.", - addLabel: "Add section", - title: (row) => - FRONT_PAGE_SECTIONS.find(([key]) => key === row.section)?.[1] ?? "New section", - blank: { section: "", title: "", blurb: "" }, - fields: [ - { - path: "section", - label: "Section", - widget: "select", - options: FRONT_PAGE_SECTIONS, - required: true, - }, - { path: "title", label: "Heading", help: "Default: the band's own name. Up to about 60 characters fit." }, - { path: "blurb", label: "Blurb", full: true }, - { path: "is_hidden", label: "Hidden", widget: "checkbox", help: "Hide for now" }, - ], - }, - { - key: "slides", - label: "Hero photos", - note: "Shown in Photos mode, in this order.", - addLabel: "Add photo", - title: (row) => row.caption || row.media || "New photo", - blank: { media: "", alt: "", caption: "" }, - fields: [ - { path: "media", label: "Photo", required: true, widget: "image", crop: 16 / 9, resolve: mediaUrl, full: true }, - { path: "alt", label: "Description", help: "For screen readers" }, - { path: "caption", label: "Caption", full: true }, - { path: "link_url", label: "Link", help: "Optional; makes the caption a link" }, - ], - }, - { - key: "stats", - label: "Numbers", - note: "Counts update themselves. A typed-in number with no value is left out.", - addLabel: "Add number", - title: (row) => row.label || "New number", - blank: { label: "", source: "", value: "" }, - fields: [ - { path: "label", label: "Label", required: true }, - { - path: "source", - label: "Number Source", - widget: "select", - options: STAT_SOURCES, - blankLabel: "Default: Print Value", - }, - { path: "value", label: "Value", help: "The number thats printed" }, - { path: "suffix", label: "Suffix", help: "+, k, % …" }, - { path: "note", label: "Note", full: true }, - ], - }, - { - ...featuredCardsChild, - fields: [ - ...featuredCardsChild.fields, - { - path: "size", - label: "Size", - widget: "select", - options: [ - ["normal", "Normal: one cell"], - ["wide", "Wide: two columns"], - ["tall", "Tall: two rows"], - ["large", "Large: two columns, two rows"], - ], - blankLabel: "Default: automatic (the first of three or more is large)", - help: "On a wide screen. Phones show one card per row", - }, - ], - }, - { - key: "paths", - label: "Connect Nav", - note: "Each path is a choice a visitor can pick; its actions appear when they do.", - addLabel: "Add path", - title: (row) => row.label || "New path", - blank: { label: "", icon: "", blurb: "" }, - fields: [ - { path: "label", label: "Label", required: true, help: "eg. Attend, Serve…" }, - { - path: "icon", - label: "Icon", - widget: "select", - options: PATH_ICONS, - blankLabel: "Default: a dot", - }, - { path: "blurb", label: "Blurb", full: true }, - ], - children: [ - { - key: "actions", - label: "Actions", - addLabel: "Add action", - title: (row) => row.label || "New action", - blank: { label: "", url: "" }, - fields: [ - { path: "label", label: "Label", required: true }, - { path: "url", label: "Link", required: true }, - { path: "description", label: "Description", full: true }, - ], - }, - ], - }, - ], -}; diff --git a/src/lib/adminSchema/sitePages.ts b/src/lib/adminSchema/sitePages.ts index d621692..97b18b9 100644 --- a/src/lib/adminSchema/sitePages.ts +++ b/src/lib/adminSchema/sitePages.ts @@ -12,6 +12,8 @@ the Community page only (its id), for now. */ import { FEATURED_KINDS, featuredCardsChild, blocksChild } from "./shared.ts"; +import { mediaUrl } from "../media.ts"; +import { PATH_ICONS } from "../../data/pathIcons.ts"; const PRESETS = { community_blog: "Community blog (its settings are below)", @@ -26,6 +28,12 @@ const PRESETS = { data_request_form: "Data request form (see, correct or delete)", giving: "Giving button (Church Center)", qr_maker: "QR code maker", + hero: "Hero (headline, photos, video, livestream or event)", + countdown: "Event countdown", + calendar: "Event calendar", + stats: "Numbers", + featured_cards: "Featured cards", + connect: "Connect nav (paths to choose from)", }; const ACCENT_OPTIONS = [ @@ -43,6 +51,272 @@ const EVENT_TYPES = [ ["other", "Other"], ]; + +/* Gates on the section's type. */ +const IS = (preset) => ({ path: "preset", value: preset }); + +const STAT_SOURCES = [ + ["manual", "Print Value Field"], + ["years_since", "Years Since Value"], + ["regions", "Count: regions"], + ["groups", "Count: groups"], + ["partners", "Count: partners"], + ["events_held", "Count: past events"], + ["retreats_held", "Count: past retreats"], + ["people", "Count: people in database"], + ["awards_given", "Count: public awards given"], +]; + +/* The settings of the section types that need them (083): each shows + only for its type. A band draws its own heading from the section's + title and blurb. */ +const BAND_FIELDS = [ + { + path: "hero.backdrop", + label: "Hero: background", + widget: "select", + options: [ + ["brand", "Brand: animated color and the dove"], + ["photos", "Photos: cycles through the hero photos below"], + ], + blankLabel: "Default: brand", + help: "Photos with none added shows the brand background", + when: IS("hero"), + }, + { + path: "hero.feature", + label: "Hero: feature", + widget: "select", + options: [ + ["none", "Nothing: No additional overlay"], + ["livestream", "Livestream: the stream, with a LIVE badge"], + ["video", "Featured video: click to play"], + ["event", "Featured event: an event's card"], + ], + blankLabel: "Default: nothing", + help: "Switch to Livestream when you go live, and back when you're done", + when: IS("hero"), + }, + { path: "hero.eyebrow", label: "Hero: eyebrow", help: "Small line above the headline", when: IS("hero") }, + { path: "hero.headline", label: "Hero: headline", full: true, when: IS("hero") }, + { path: "hero.subhead", label: "Hero: subhead", widget: "textarea", full: true, when: IS("hero") }, + { path: "hero.primary_label", label: "Hero: main button label", when: IS("hero") }, + { path: "hero.primary_url", label: "Hero: main button link", help: "/page, #section-id or a full URL", when: IS("hero") }, + { path: "hero.secondary_label", label: "Hero: second button label", when: IS("hero") }, + { path: "hero.secondary_url", label: "Hero: second button link", when: IS("hero") }, + { path: "hero.slide_seconds", label: "Hero: seconds per photo", widget: "number", help: "Photos background. 3 to 60. Default: 7", when: IS("hero") }, + { path: "hero.livestream_url", label: "Hero: livestream link", full: true, help: "A YouTube, Facebook or Vimeo link, or any embed URL", when: IS("hero") }, + { path: "hero.livestream_title", label: "Hero: livestream title", full: true, when: IS("hero") }, + { + path: "hero.video_url", + label: "Hero: featured video", + full: true, + help: "A YouTube, Vimeo or Facebook link, or a video file: a filename in the uploads folder, or a link ending in .mp4 or .webm", + when: IS("hero"), + }, + { + path: "hero.video_still", + label: "Hero: video still", + widget: "image", + crop: 16 / 9, + resolve: mediaUrl, + full: true, + frameFrom: "hero.video_url", + help: "Shown before it plays. Default: YouTube's own thumbnail, or a video file's first frame. Frame at takes a still from a YouTube or Facebook video.", + when: IS("hero"), + }, + { + path: "hero.video_captions", + label: "Hero: video captions", + widget: "image", + folder: "captions", + resolve: mediaUrl, + full: true, + help: "A WebVTT (.vtt) file, for a video file; YouTube, Vimeo and Facebook show their own. Default: none.", + when: IS("hero"), + }, + { path: "hero.video_title", label: "Hero: video title", full: true, help: "Shown after \"Featured video\" above the headline", when: IS("hero") }, + { + path: "hero.event_id", + label: "Hero: featured event", + widget: "select", + optionsFrom: "events", + blankLabel: "Default: the page's countdown's event", + full: true, + help: "For the Featured event feature. A pinned event that's over falls back to the countdown's", + when: IS("hero"), + }, + { + path: "countdown.event_id", + label: "Count down to", + widget: "select", + optionsFrom: "events", + blankLabel: "Default: the next upcoming event", + help: "Leave blank almost always. A pinned event that's over falls back to the next one", + when: IS("countdown"), + }, + { + path: "countdown.scope_id", + label: "Countdown: only this scope", + widget: "select", + optionsFrom: "event_scopes", + blankLabel: "Default: any scope", + help: "Narrows the next upcoming event. Ignored when an event is pinned above", + when: IS("countdown"), + }, + { + path: "countdown.event_type", + label: "Countdown: only this type", + widget: "select", + options: [ + ["retreat", "Retreat"], + ["class", "Class"], + ["workshop", "Workshop"], + ["meeting", "Meeting"], + ["other", "Other"], + ], + blankLabel: "Default: any type", + help: "Combines with the scope: National + Retreat counts down to the next national retreat", + when: IS("countdown"), + }, + { + path: "featured.columns", + label: "Featured cards: columns", + widget: "select", + options: [ + ["2", "2 across"], + ["3", "3 across"], + ["4", "4 across"], + ], + blankLabel: "Default: 3 across", + help: "On a wide screen. Tablets show 2, phones 1", + when: IS("featured_cards"), + }, + { path: "blog.internal_title", label: "Blog: our posts' heading", help: "Default: From NGU", when: IS("community_blog") }, + { path: "blog.internal_slots", label: "Blog: our posts' slots", widget: "number", help: "0 to 12. Pinned posts first, then the newest. Default: 3", when: IS("community_blog") }, + { path: "blog.external_title", label: "Blog: community posts' heading", help: "Default: From our community", when: IS("community_blog") }, + { path: "blog.external_slots", label: "Blog: community posts' slots", widget: "number", help: "0 to 12. Pinned cards first, then the feeds' newest. Default: 3", when: IS("community_blog") }, + { path: "blog.external_url", label: "Blog: button link", help: "eg. https://ngu.substack.com", full: true, when: IS("community_blog") }, + { path: "blog.external_label", label: "Blog: button text", help: "Default: Read more on Substack", when: IS("community_blog") }, +]; + +const BAND_CHILDREN = [ + { + key: "slides", + label: "Hero photos", + note: "Shown with the Photos background, in this order.", + addLabel: "Add photo", + when: IS("hero"), + title: (row) => row.caption || row.media || "New photo", + blank: { media: "", alt: "", caption: "" }, + fields: [ + { path: "media", label: "Photo", required: true, widget: "image", crop: 16 / 9, resolve: mediaUrl, full: true }, + { path: "alt", label: "Description", help: "For screen readers" }, + { path: "caption", label: "Caption", full: true }, + { path: "link_url", label: "Link", help: "Optional; makes the caption a link" }, + ], + }, + { + key: "stats", + label: "Numbers", + note: "Counts update themselves. A typed-in number with no value is left out.", + addLabel: "Add number", + when: IS("stats"), + title: (row) => row.label || "New number", + blank: { label: "", source: "", value: "" }, + fields: [ + { path: "label", label: "Label", required: true }, + { path: "source", label: "Number Source", widget: "select", options: STAT_SOURCES, blankLabel: "Default: Print Value" }, + { path: "value", label: "Value", help: "The number that's printed" }, + { path: "suffix", label: "Suffix", help: "+, k, % …" }, + { path: "note", label: "Note", full: true }, + ], + }, + { + ...featuredCardsChild, + label: "Featured cards", + when: IS("featured_cards"), + fields: [ + ...featuredCardsChild.fields, + { + path: "size", + label: "Size", + widget: "select", + options: [ + ["normal", "Normal: one cell"], + ["wide", "Wide: two columns"], + ["tall", "Tall: two rows"], + ["large", "Large: two columns, two rows"], + ], + blankLabel: "Default: automatic (the first of three or more is large)", + help: "On a wide screen. Phones show one card per row", + }, + ], + }, + { + ...featuredCardsChild, + label: "Blog: pinned community posts", + note: "Always shown, before the feeds' newest. Paste a post's link and press Fetch preview.", + addLabel: "Pin a post", + when: IS("community_blog"), + blank: { kind: "", url: "", title: "" }, + fields: featuredCardsChild.fields.map((field) => + field.path === "kind" ? { ...field, options: FEATURED_KINDS.filter(([kind]) => kind !== "record") } : field, + ), + }, + { + key: "blog_posts", + label: "Blog: pinned posts (ours)", + note: "Always shown, before the newest.", + addLabel: "Pin a post", + when: IS("community_blog"), + title: (row, options) => options?.blog_posts?.find((p) => p.id === row.post_id)?.label ?? "New pin", + blank: { post_id: "" }, + fields: [{ path: "post_id", label: "Post", widget: "select", optionsFrom: "blog_posts", required: true }], + }, + { + key: "feeds", + label: "Blog: feeds", + note: "RSS or Atom feeds whose newest posts fill the community slots. Read about every 30 minutes.", + addLabel: "Add feed", + when: IS("community_blog"), + title: (row) => row.label || row.url || "New feed", + blank: { url: "", label: "" }, + fields: [ + { path: "url", label: "Feed URL", required: true, full: true, help: "eg. https://ngu.substack.com/feed" }, + { path: "label", label: "Source name", help: "Shown on its cards. Default: the feed's own title" }, + ], + }, + { + key: "paths", + label: "Connect nav: paths", + note: "Each path is a choice a visitor can pick; its actions appear when they do.", + addLabel: "Add path", + when: IS("connect"), + title: (row) => row.label || "New path", + blank: { label: "", icon: "", blurb: "" }, + fields: [ + { path: "label", label: "Label", required: true, help: "eg. Attend, Serve…" }, + { path: "icon", label: "Icon", widget: "select", options: PATH_ICONS, blankLabel: "Default: a dot" }, + { path: "blurb", label: "Blurb", full: true }, + ], + children: [ + { + key: "actions", + label: "Actions", + addLabel: "Add action", + title: (row) => row.label || "New action", + blank: { label: "", url: "" }, + fields: [ + { path: "label", label: "Label", required: true }, + { path: "url", label: "Link", required: true }, + { path: "description", label: "Description", full: true }, + ], + }, + ], + }, +]; + const EVENTS = { path: "preset", value: "events" }; const CARDS = { path: "preset", value: "partner_list" }; @@ -58,7 +332,7 @@ const sectionsChild = (presets: string[]) => ({ path: "title", label: "Title", required: true, - help: "Up to 30 characters, so it fits the side nav. eg. Mission, Vision & Values", + help: "Up to 30 characters, so it fits the side nav (60 on the front page). A band (hero, numbers...) draws it as its heading; the hero's isn't shown. eg. Mission, Vision & Values", }, { path: "anchor", @@ -68,6 +342,7 @@ const sectionsChild = (presets: string[]) => ({ }, { path: "blurb", label: "Blurb", widget: "textarea", full: true, help: "A line under the title" }, { path: "accent", label: "Accent", widget: "select", options: ACCENT_OPTIONS, blankLabel: "Default: Teal" }, + { path: "is_hidden", label: "Hidden", widget: "checkbox", help: "Left off the page for now, kept here." }, ...(presets.length ? [ { @@ -125,6 +400,19 @@ const sectionsChild = (presets: string[]) => ({ }, ] : []), + ...(presets.includes("timeline") + ? [ + { + path: "view", + label: "Shows", + widget: "select", + options: [["carousel", "A rail of the featured moments (the front page's)"]], + blankLabel: "Default: the whole timeline", + when: { path: "preset", value: "timeline" }, + }, + ] + : []), + ...BAND_FIELDS, ...(presets.includes("group_map") ? [ { @@ -139,6 +427,7 @@ const sectionsChild = (presets: string[]) => ({ : []), ], children: [ + ...BAND_CHILDREN, { key: "tags", label: "Directory: tags", @@ -168,16 +457,11 @@ const sectionsChild = (presets: string[]) => ({ ], }); -const COMMUNITY = { path: "id", value: "community" }; const ALL_PRESETS = Object.keys(PRESETS); /* Pages the site's own code links to: their address stays (server/src/admin-schema/sitePages.js, CORE_PAGES). */ const CORE_PAGE_IDS = ["home", "give", "feedback", "request", "qr", "privacy", "terms"]; -const isHome = (row) => row?.id === "home"; - -const communityGroups = (groups) => groups.map((group) => ({ ...group, when: COMMUNITY })); -const communityChildren = (children) => children.map((child) => ({ ...child, when: COMMUNITY })); export const pages = { key: "pages", @@ -186,8 +470,7 @@ export const pages = { 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. + // sections, the front page's included (its hero and bands). list: { columns: [ { key: "title", label: "Page", primary: true }, @@ -229,83 +512,7 @@ export const pages = { { 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: isHome }, - 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.", - fields: [ - { path: "blog.internal_title", label: "Heading", help: "Default: From NGU" }, - { path: "blog.internal_slots", label: "Slots", widget: "number", help: "0 to 12. Default: 3" }, - ], - }, - { - legend: "Community blog: community posts", - note: "Pinned cards first, then the newest items from the feeds below, up to the number of slots.", - fields: [ - { path: "blog.external_title", label: "Heading", help: "Default: From our community" }, - { path: "blog.external_slots", label: "Slots", widget: "number", help: "0 to 12. Default: 3" }, - { path: "blog.external_url", label: "Button link", help: "eg. https://ngu.substack.com", full: true }, - { path: "blog.external_label", label: "Button text", help: "Default: Read more on Substack" }, - ], - }, - ] - ), ], - children: [ - { ...sectionsChild(ALL_PRESETS), when: { test: (row) => !isHome(row) } }, - ...communityChildren( - [ - { - key: "pinned_posts", - label: "Community blog: pinned posts (ours)", - note: "Always shown, before the newest.", - addLabel: "Pin a post", - title: (row, options) => - options?.blog_posts?.find((p) => p.id === row.post_id)?.label ?? "New pin", - blank: { post_id: "" }, - fields: [ - { - path: "post_id", - label: "Post", - widget: "select", - optionsFrom: "blog_posts", - required: true, - }, - ], - }, - { - ...featuredCardsChild, - label: "Community blog: pinned community posts", - note: "Always shown, before the feeds' newest. Paste a post's link and press Fetch preview.", - addLabel: "Pin a post", - blank: { kind: "", url: "", title: "" }, - fields: featuredCardsChild.fields.map((field) => - field.path === "kind" - ? { ...field, options: FEATURED_KINDS.filter(([kind]) => kind !== "record") } - : field, - ), - }, - { - key: "feeds", - label: "Community blog: feeds", - note: "RSS or Atom feeds whose newest posts fill the community slots. Read about every 30 minutes.", - addLabel: "Add feed", - title: (row) => row.label || row.url || "New feed", - blank: { url: "", label: "" }, - fields: [ - { path: "url", label: "Feed URL", required: true, full: true, help: "eg. https://ngu.substack.com/feed" }, - { path: "label", label: "Source name", help: "Shown on its cards. Default: the feed's own title" }, - ], - }, - ] - ), - ], + children: [sectionsChild(ALL_PRESETS)], }; diff --git a/src/lib/eventTypes.ts b/src/lib/eventTypes.ts index 7f42bc7..6662ed8 100644 --- a/src/lib/eventTypes.ts +++ b/src/lib/eventTypes.ts @@ -13,7 +13,7 @@ renders as its own name, so a CHECK is enough. Adding a type is three edits: the CHECKs in a migration (on - events.event_type and front_page.countdown_event_type), the enums + events.event_type and section_countdown.event_type), the enums in both descriptor halves (the event's type and the front page's countdown type), and this list. Adding it here alone means the site offers a filter the database will refuse to store. diff --git a/src/lib/frontPageBands.ts b/src/lib/frontPageBands.ts deleted file mode 100644 index 17aa390..0000000 --- a/src/lib/frontPageBands.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* ═══════════════════════════════════════════════════════════════ - FRONT PAGE BANDS - - Each band the front page can show (front_page_sections.section): - the anchor it sits at, and the heading it gets when the admin gives - it none. Home.tsx draws the bands; the nav and footer list the ones - the front page is showing (navSections.ts). The countdown has no - anchor: it's a card under the hero, not a section to jump to. - ═══════════════════════════════════════════════════════════════ */ - -import type { FrontPage, FrontPageSectionKey } from './useFrontPage.ts' - -export const FRONT_PAGE_BANDS: Record = { - countdown: { id: null, title: 'Next up' }, - retreats: { id: 'retreats', title: 'National Retreats' }, - calendar: { id: 'calendar', title: 'What’s on' }, - stats: { id: 'numbers', title: 'By the numbers' }, - timeline: { id: 'story', title: 'Our story so far' }, - connect: { id: 'connect', title: 'Find your way in' }, - featured: { id: 'featured', title: 'Featured' }, -} - -/* Whether a band has anything to draw: Home.tsx leaves out a band - with nothing in it, and so does the nav. */ -export function bandShows(page: FrontPage, key: FrontPageSectionKey): boolean { - switch (key) { - case 'countdown': - return Boolean(page.countdown) - case 'stats': - return page.stats.length > 0 - case 'connect': - return page.paths.length > 0 - case 'featured': - return page.featured.length > 0 - default: - return true - } -} diff --git a/src/lib/navSections.ts b/src/lib/navSections.ts index a099eb4..e147f6e 100644 --- a/src/lib/navSections.ts +++ b/src/lib/navSections.ts @@ -3,39 +3,27 @@ dropdowns, the mobile menu and the footer's site map Every page's list comes from the page itself, so adding, moving - or renaming a section changes the menus too: the site pages' - sections (Pages → each page, GET /site-pages), and the front - page's bands it is showing, in the admin's order, each under its - heading (Front page → Sections). + or renaming a section changes the menus too (Pages → Page + management, GET /site-pages), the front page's included. The hero + and a countdown aren't listed: they're the top of a page, not a + place to jump to (sections/Bands.tsx). ═══════════════════════════════════════════════════════════════ */ import { useCallback } from 'react' import { useSitePageHeadings } from './useSitePages.ts' -import { useFrontPage } from './useFrontPage.ts' -import { FRONT_PAGE_BANDS, bandShows } from './frontPageBands.ts' +import { UNLISTED_PRESETS } from '../pages/sections/Bands.tsx' export type NavSection = { label: string; hash: string } export function useNavSections(): (path: string) => NavSection[] { - const { data: page } = useFrontPage() const { data: sitePages } = useSitePageHeadings() return useCallback( - (path: string) => { - if (path !== '/') { - return (sitePages?.[path] ?? []).map((section) => ({ - label: section.title, - hash: `#${section.anchor}`, - })) - } - if (!page) return [] - return page.sections.flatMap((section) => { - const band = FRONT_PAGE_BANDS[section.section] - if (!band?.id || !bandShows(page, section.section)) return [] - return [{ label: section.title || band.title, hash: `#${band.id}` }] - }) - }, - [page, sitePages], + (path: string) => + (sitePages?.[path] ?? []) + .filter((section) => !UNLISTED_PRESETS.includes(section.preset ?? '')) + .map((section) => ({ label: section.title, hash: `#${section.anchor}` })), + [sitePages], ) } diff --git a/src/lib/useFrontPage.ts b/src/lib/sectionTypes.ts similarity index 69% rename from src/lib/useFrontPage.ts rename to src/lib/sectionTypes.ts index 767336b..2329346 100644 --- a/src/lib/useFrontPage.ts +++ b/src/lib/sectionTypes.ts @@ -1,16 +1,11 @@ /* ═══════════════════════════════════════════════════════════════ - FRONT PAGE DATA + SECTION TYPES' DATA - GET /front-page, as routes/home.js shapes it: the hero, the - visible sections in order, counted stats, paths with actions, - and the countdown's event. Edited in the admin under Front page. - - No fallback content. If the request fails the page says so: a - plausible default home page would hide a broken server behind - something that looks fine. + What a band section's `data` holds (server/src/sectionData.js, + in GET /site-pages/:id): a hero, a countdown's event, stats, a + pathfinder's paths, featured cards. sections/Bands.tsx draws them. ═══════════════════════════════════════════════════════════════ */ -import { useRecord, type Resource } from './useRecord.ts' import type { EventSeries } from './eventSeries.ts' import type { Link } from './useContent.ts' @@ -20,16 +15,6 @@ export type HeroBackdrop = 'brand' | 'photos' /** What sits beside the words, over the backdrop. */ export type HeroFeature = 'none' | 'livestream' | 'video' | 'event' -/** The CHECK list on front_page_sections.section. */ -export type FrontPageSectionKey = - | 'countdown' - | 'retreats' - | 'calendar' - | 'stats' - | 'timeline' - | 'connect' - | 'featured' - export type HeroButton = { label: string; url: string } export type HeroSlide = { @@ -53,18 +38,11 @@ export type Hero = { /** A link to embed or a video file; see videoSource in embeds.ts. */ /** `still` is shown before it plays; resolve it with mediaUrl. */ video: { url: string; title?: string | null; captions?: string | null; still?: string | null } | null - /** With the 'event' feature: the pinned event, else the countdown's. */ + /** With the 'event' feature: the pinned event, else the page's countdown's. */ event: HeroEvent | null } -export type FrontPageSection = { - section: FrontPageSectionKey - /** Null → the section's own heading. */ - title?: string | null - blurb?: string | null -} - -export type FrontPageStat = { +export type SectionStat = { label: string /** Already counted or typed; never null, since the API drops those. */ value: string @@ -74,7 +52,7 @@ export type FrontPageStat = { export type PathAction = { label: string; description?: string | null; url: string } -export type FrontPagePath = { +export type SectionPath = { label: string icon?: string | null blurb?: string | null @@ -122,17 +100,3 @@ export type HeroEvent = CountdownEvent & { org_logo?: string | null links: Link[] } - -export type FrontPage = { - hero: Hero - sections: FrontPageSection[] - stats: FrontPageStat[] - paths: FrontPagePath[] - featured: FeaturedCard[] - /** Columns across on a wide screen; null is the grid's default. */ - featured_columns: FeaturedColumns | null - countdown: CountdownEvent | null -} - -export const useFrontPage = (): Resource => - useRecord('/front-page', 'front_page') diff --git a/src/lib/useBlog.ts b/src/lib/useBlog.ts index c5ddfcf..fb3b93c 100644 --- a/src/lib/useBlog.ts +++ b/src/lib/useBlog.ts @@ -1,15 +1,16 @@ /* ═══════════════════════════════════════════════════════════════ BLOG DATA - GET /blog/:id and GET /community-blog, as routes/blog.js shapes - them. The section's community posts arrive as featured cards, so + GET /blog/:id, as routes/blog.js shapes it, and what a Community + blog section shows (its `data`, server/src/sectionData.js). The + section's community posts arrive as featured cards, so FeaturedCards.tsx draws them unchanged. ═══════════════════════════════════════════════════════════════ */ import { detailPath } from './hrefs.ts' import { useRecord, type Resource } from './useRecord.ts' import type { ContentBlock } from './useContent.ts' -import type { FeaturedCard } from './useFrontPage.ts' +import type { FeaturedCard } from './sectionTypes.ts' export type BlogAuthor = { id: string @@ -59,8 +60,6 @@ export type CommunityBlog = { export const useBlogPost = (id?: string | null): Resource => useRecord(detailPath('/blog', id), 'post') -export const useCommunityBlog = (): Resource => - useRecord('/community-blog', 'community_blog') /** '2026-09-01' → 'September 1, 2026'. Parsed as a local date, so * it can't slip a day in a timezone west of UTC. */ diff --git a/src/lib/useContent.ts b/src/lib/useContent.ts index 8b27a55..d92b902 100644 --- a/src/lib/useContent.ts +++ b/src/lib/useContent.ts @@ -12,7 +12,7 @@ */ import type { BlogPostSummary } from './useBlog.ts' -import type { FeaturedCard } from './useFrontPage.ts' +import type { FeaturedCard } from './sectionTypes.ts' import { detailPath } from './hrefs.ts' import { useRecord, type Resource } from './useRecord.ts' import type { EventType } from './eventTypes.ts' diff --git a/src/lib/useSitePages.ts b/src/lib/useSitePages.ts index 8c64dbc..8632b55 100644 --- a/src/lib/useSitePages.ts +++ b/src/lib/useSitePages.ts @@ -21,11 +21,14 @@ export type SitePageSection = { org_kinds?: string | null /** Organization cards: a hand-picked list, in order, shown instead. */ org_ids: string[] + /** What its type shows beyond its blocks (server/src/sectionData.js): + * a hero, a countdown's event, stats, paths, featured cards, a blog. */ + data?: any blocks: ContentBlock[] } export const useSitePage = (id: string): Resource<{ id: string; title: string; description: string | null; sections: SitePageSection[] }> => useRecord(`/site-pages/${id}`, 'page') -export const useSitePageHeadings = (): Resource>> => +export const useSitePageHeadings = (): Resource>> => useRecord('/site-pages', 'pages') diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx deleted file mode 100644 index 22b1e35..0000000 --- a/src/pages/Home.tsx +++ /dev/null @@ -1,129 +0,0 @@ -/* ═══════════════════════════════════════════════════════════════ - HOME: / - - Not a PageShell page: the front page has no title bar, and each - band draws its own heading in its own style. - - Driven by the admin's Front page editor through GET /front-page. - The hero comes first, always. After it, the bands in the order - the admin dragged them into, minus any they hid. Which component - draws a band is decided here, in SECTIONS, keyed on the same list - the CHECK on front_page_sections holds, the database says "retreats, - third, called National Retreats"; this file says what a retreats - band looks like. - - A band with nothing to show draws nothing: the countdown with no - upcoming event, the numbers with no numbers, the timeline with - nothing featured, the pathfinder with no paths, the featured band - with no cards. - - If /front-page fails, the hero still draws (empty) and the error - takes the place of the bands, with a retry. There's deliberately - no default page to fall back to: it would look fine and hide a - broken server. - ═══════════════════════════════════════════════════════════════ */ - -import { useEffect, type ReactNode } from 'react' - -import HeroStage from './sections/home/HeroStage.tsx' -import NextEventCountdown from './sections/home/NextEventCountdown.tsx' -import RetreatsBand from './sections/home/RetreatsBand.tsx' -import CalendarBand from './sections/home/CalendarBand.tsx' -import StatsBand from './sections/home/StatsBand.tsx' -import FeaturedBand from './sections/home/FeaturedBand.tsx' -import FeaturedTimelineRail from './sections/home/FeaturedTimelineRail.tsx' -import Pathfinder from './sections/home/Pathfinder.tsx' -import { get } from '../lib/api.ts' -import { documentTitle } from '../lib/site.ts' -import { - useFrontPage, - type FrontPage, - type FrontPageSection, - type FrontPageSectionKey, -} from '../lib/useFrontPage.ts' -import { FRONT_PAGE_BANDS, bandShows } from '../lib/frontPageBands.ts' -import './sections/home/home.css' - -type BandProps = { - page: FrontPage - section: FrontPageSection - title: string - /** Position among the visible bands, 0 = straight after the hero. */ - position: number -} - -/* How each band renders. Its anchor, its heading when the admin - gave it none, and whether it has anything to draw are - frontPageBands.ts's, which the nav and footer read too; #connect is - what the hero's second button points at out of the box. */ -const id = (key: FrontPageSectionKey) => FRONT_PAGE_BANDS[key].id ?? undefined - -const BANDS: Record ReactNode> = { - countdown: ({ page, position }) => , - retreats: ({ section, title }) => , - calendar: ({ section, title }) => , - stats: ({ page, section, title }) => ( - - ), - timeline: ({ section, title }) => , - connect: ({ page, section, title }) => ( - - ), - featured: ({ page, section, title }) => ( - - ), -} - -export default function Home() { - const { data: page, error, reload } = useFrontPage() - - // The bands below ask for the timeline once the front page has said - // which of them to show. Start it now, alongside it: api.ts hands the - // same request to the band when it mounts, so the page waits for one - // round trip instead of two. Events aren't fetched ahead: each band - // asks the server for only its own, so there's no one list to start. - useEffect(() => { - get('/history').catch(() => {}) - }, []) - - // Back to the site name when a visitor returns here from a page. - useEffect(() => { - document.title = documentTitle() - }, []) - - return ( - <> - - - {error && ( -
-

Couldn’t load the front page. {error}

- -
- )} - - {page?.sections.map((section, position) => { - const render = BANDS[section.section] - // A key the CHECK has gained since this file was written, or a - // band with nothing to draw. - if (!render || !bandShows(page, section.section)) return null - return ( -
- {render({ - page, - section, - title: section.title || FRONT_PAGE_BANDS[section.section].title, - position, - })} -
- ) - })} - - ) -} diff --git a/src/pages/PageAtPath.tsx b/src/pages/PageAtPath.tsx index dc1f7ae..ac5efc4 100644 --- a/src/pages/PageAtPath.tsx +++ b/src/pages/PageAtPath.tsx @@ -3,7 +3,7 @@ Pages → Page management decides what's where: the site_pages row at this path (useSiteNav), drawn as its sections (SitePage). The - front page is the index route of its own (Home.tsx). No page there + front page is the index route, SitePage too. No page there (or a hidden one, below viewer, which isn't sent): Not found. ═══════════════════════════════════════════════════════════════ */ diff --git a/src/pages/SitePage.tsx b/src/pages/SitePage.tsx index 0374822..a57f276 100644 --- a/src/pages/SitePage.tsx +++ b/src/pages/SitePage.tsx @@ -1,12 +1,21 @@ /* ═══════════════════════════════════════════════════════════════ - SITE PAGE: /community, /retreats, /resources, /organization, - /history + SITE PAGE: every page of the site, the front page included - Each is a list of sections built in the admin (Pages → the page, - GET /site-pages/:id). A section is its heading, then its own - content blocks, then its preset if it has one: a prebuilt part of - the site, from PRESETS below. A section with neither says it's - coming (ComingSoon) rather than showing a heading over nothing. + Each is a list of sections built in the admin (Pages → Page + management, GET /site-pages/:id). A section is its heading, then + its own content blocks, then its preset if it has one: a prebuilt + part of the site, from PRESETS below. A section with neither says + it's coming (ComingSoon) rather than showing a heading over + nothing. A band (the hero, the countdown, the numbers...: + sections/Bands.tsx) draws itself, heading and all. + + Two layouts: + the front page no title bar: the bands one after another, as + they always were, and any other section as a + band of its own in the same style + any other page PageShell: the title and intro, then each + section under its heading (a band without one, + since it draws its own) The title and intro are its site_pages row's (Pages → Page management), which also give the search metadata. @@ -16,6 +25,8 @@ import { useEffect } from 'react' import { useLocation } from 'react-router-dom' import PageShell from '../components/PageShell.tsx' +import { documentTitle } from '../lib/site.ts' +import { bandFor, UNLISTED_PRESETS } from './sections/Bands.tsx' import ComingSoon from '../components/ComingSoon.tsx' import ContentBlocks from '../components/ContentBlocks.tsx' import { useSiteNav } from '../lib/useSiteNav.ts' @@ -45,9 +56,10 @@ const PROGRAM_START_YEAR = 2000 const NO_EVENT_REQUEST_SCOPES = ['national'] const PRESETS: Record Record> = { - community_blog: () => ({ + community_blog: (section) => ({ Component: CommunityBlog, request: { type: 'blog', label: 'Write for the blog' }, + props: { blog: section.data }, }), group_map: (section) => ({ Component: OrgListMap, @@ -103,12 +115,16 @@ const PRESETS: Record Record> qr_maker: () => ({ Component: QrSection }), } +/* The front page's id (site_pages). */ +export const HOME = 'home' + export default function SitePage({ id }: { id: string }) { - const { data: page, loading, error } = useSitePage(id) + const { data: page, loading, error, reload } = 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 (id === HOME) return if (page) return return ( @@ -136,8 +152,21 @@ function Sections({ title, intro, sections }: { title: string; intro?: string; s }, [hash]) const manifest = useSectionManifest( - sections.map((section) => { + sections.map((section, index) => { const accent = ACCENTS[section.accent ?? 'teal'] ?? BRAND + // A band draws itself, heading and all: no heading of the shell's. + const band = bandFor(section) + if (band) { + const node = band(section, { afterHero: sections[index - 1]?.preset === 'hero' }) + return { + id: section.anchor, + title: section.title, + accent, + bare: true, + unlisted: UNLISTED_PRESETS.includes(section.preset ?? ''), + Component: () => node, + } + } const preset = section.preset ? PRESETS[section.preset]?.(section) : null return { id: section.anchor, @@ -155,6 +184,72 @@ function Sections({ title, intro, sections }: { title: string; intro?: string; s return } +/* The front page: its bands one after another, under no title bar. A + section that isn't a band is one in the same style: its heading, + then its blocks and preset. If the page can't load, the error + takes the bands' place, with a retry: there's deliberately no + default page to fall back to, which would hide a broken server. */ +function FrontPage({ sections, error, reload }: { sections: SitePageSection[] | null; error: string | null; reload: () => void }) { + const { hash } = useLocation() + useEffect(() => { + if (hash) jumpTo(decodeURIComponent(hash.slice(1))) + }, [hash, sections]) + + // Back to the site name when a visitor returns here from a page. + useEffect(() => { + document.title = documentTitle() + }, []) + + if (error) { + return ( +
+

Couldn’t load the front page. {error}

+ +
+ ) + } + if (!sections) return null + + return ( + <> + {sections.map((section, index) => { + const band = bandFor(section) + return ( +
+ {band ? band(section, { afterHero: sections[index - 1]?.preset === 'hero' }) : } +
+ ) + })} + + ) +} + +/* A section on the front page that isn't a band: the bands' heading, + then its blocks and preset as on any page. */ +function PlainBand({ section }: { section: SitePageSection }) { + const accent = ACCENTS[section.accent ?? 'teal'] ?? BRAND + const preset = section.preset ? PRESETS[section.preset]?.(section) : null + const views = preset?.views + return ( +
+
+

{section.title}

+ {section.blurb &&

{section.blurb}

} +
+ +
+ ) +} + function SectionBody({ blocks, title, Preset, presetProps, ...rest }: any) { if (!blocks.length && !Preset) return return ( diff --git a/src/pages/admin/AdminHome.tsx b/src/pages/admin/AdminHome.tsx index a32ed95..3477e7c 100644 --- a/src/pages/admin/AdminHome.tsx +++ b/src/pages/admin/AdminHome.tsx @@ -133,8 +133,7 @@ const QUICK_ADD = [ { to: "/admin/timeline/new", label: "New timeline entry" }, ]; -/* A card per page (Pages → Page management), in its order: the - front page's opens Front page, the others their page. */ +/* A card per page (Pages → Page management), in its order. */ function usePageCards() { const [cards, setCards] = useState([]); useEffect(() => { @@ -142,7 +141,7 @@ function usePageCards() { .then((list) => setCards( list.rows.map((page) => ({ - to: page.id === "home" ? "/admin/front_page" : `/admin/pages/${page.id}`, + to: `/admin/pages/${page.id}`, label: page.title, blurb: [page.path, page.is_hidden ? "Hidden" : null, page.is_disabled ? "Disabled" : null] .filter(Boolean) @@ -172,7 +171,6 @@ export default function AdminHome() { {GROUPS.map(({ nav, color }) => ( {visibleItems(nav.children, user) - .filter((item) => !item.menuOnly) .flatMap((item) => // Every page gets a card of its own after the banner. item.banner diff --git a/src/pages/admin/AdminNewsletter.tsx b/src/pages/admin/AdminNewsletter.tsx index 406caeb..0c9ce59 100644 --- a/src/pages/admin/AdminNewsletter.tsx +++ b/src/pages/admin/AdminNewsletter.tsx @@ -35,7 +35,8 @@ import { blocksChild, BLOCK_TYPES } from '../../lib/adminSchema/shared.ts' import { Repeater } from '../../components/admin/fields.tsx' import NewsletterRecipients from '../../components/admin/NewsletterRecipients.tsx' import { useEvents } from '../../lib/eventData.ts' -import { useFrontPage, type FeaturedCard } from '../../lib/useFrontPage.ts' +import type { FeaturedCard } from '../../lib/sectionTypes.ts' +import { useSitePage } from '../../lib/useSitePages.ts' import type { BlogPostRecord } from '../../lib/useBlog.ts' import { blogHref, eventHref, refHref } from '../../lib/hrefs.ts' import { mediaUrl } from '../../lib/media.ts' @@ -274,8 +275,11 @@ export default function AdminNewsletter() { const [message, setMessage] = useState<{ tone: 'ok' | 'error'; text: string } | null>(null) const { events, loading: eventsLoading } = useEvents({ status: 'upcoming' }) - const { data: frontPage } = useFrontPage() - const cards = frontPage?.featured ?? [] + // The front page's featured cards: its featured card sections'. + const { data: frontPage } = useSitePage('home') + const cards: FeaturedCard[] = (frontPage?.sections ?? []) + .filter((section) => section.preset === 'featured_cards') + .flatMap((section) => section.data?.cards ?? []) useEffect(() => { get('/admin/blog_posts?is_published=1&is_listed=1&limit=200', { ttl: 0 }) diff --git a/src/pages/admin/adminNav.ts b/src/pages/admin/adminNav.ts index 487c4e8..970d7b1 100644 --- a/src/pages/admin/adminNav.ts +++ b/src/pages/admin/adminNav.ts @@ -128,18 +128,11 @@ export const PAGES_NAV = { 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/home", label: "Front page" }, { to: "/admin/pages/new", label: "New page" }, { to: "/admin/navigation", label: "Menus (Navigation)" }, ], }, - // 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.", - menuOnly: true, - }, { to: "/admin/navigation", label: "Navigation", diff --git a/src/pages/sections/Bands.tsx b/src/pages/sections/Bands.tsx new file mode 100644 index 0000000..ef60e49 --- /dev/null +++ b/src/pages/sections/Bands.tsx @@ -0,0 +1,74 @@ +/* ═══════════════════════════════════════════════════════════════ + BANDS + + The section types that draw a whole band of their own, heading + included, in the front page's style (083: they were the front + page's, and go on any page now): the hero, the countdown, the + calendar, the numbers, featured cards, the pathfinder, and the + timeline's rail of featured moments (a timeline section opened as + 'carousel'). SitePage.tsx draws them as they are on the front + page, and without its own heading on any other page. + + Each takes the section (its anchor, title, blurb) and what its + type shows (`data`, server/src/sectionData.js). A band with + nothing to show draws nothing: the countdown with no upcoming + event, the numbers with no numbers, the pathfinder with no paths, + featured cards with no cards. + ═══════════════════════════════════════════════════════════════ */ + +import type { ReactNode } from 'react' + +import HeroStage from './home/HeroStage.tsx' +import NextEventCountdown from './home/NextEventCountdown.tsx' +import CalendarBand from './home/CalendarBand.tsx' +import StatsBand from './home/StatsBand.tsx' +import FeaturedBand from './home/FeaturedBand.tsx' +import FeaturedTimelineRail from './home/FeaturedTimelineRail.tsx' +import Pathfinder from './home/Pathfinder.tsx' +import type { SitePageSection } from '../../lib/useSitePages.ts' +import './home/home.css' + +type BandContext = { + /** The section before it is a hero: a countdown overlaps its foot. */ + afterHero: boolean +} + +type Band = (section: SitePageSection, context: BandContext) => ReactNode + +const BANDS: Record = { + hero: (section) => , + countdown: (section, { afterHero }) => + section.data ? : null, + calendar: (section) => , + stats: (section) => + section.data?.length ? ( + + ) : null, + featured_cards: (section) => + section.data?.cards?.length ? ( + + ) : null, + connect: (section) => + section.data?.length ? ( + + ) : null, +} + +/* The band a section draws, or undefined when its type isn't one + (it's its blocks and preset, in a plain section). */ +export function bandFor(section: SitePageSection): Band | undefined { + if (section.preset === 'timeline' && section.view === 'carousel') { + return () => + } + return section.preset ? BANDS[section.preset] : undefined +} + +/* Section types the menus don't list: the hero and the countdown are + the top of a page, not places to jump to. */ +export const UNLISTED_PRESETS = ['hero', 'countdown'] diff --git a/src/pages/sections/CommunityBlog.tsx b/src/pages/sections/CommunityBlog.tsx index ed73083..acf28da 100644 --- a/src/pages/sections/CommunityBlog.tsx +++ b/src/pages/sections/CommunityBlog.tsx @@ -21,7 +21,7 @@ import PlatformIcon from '../../components/PlatformIcon.tsx' import { blogHref } from '../../lib/hrefs.ts' import { mediaUrl } from '../../lib/media.ts' import { preview } from '../../lib/text.ts' -import { postDate, useCommunityBlog, type BlogPostSummary } from '../../lib/useBlog.ts' +import { postDate, type BlogPostSummary, type CommunityBlog as CommunityBlogData } from '../../lib/useBlog.ts' import HomeLink from './home/HomeLink.tsx' import { accentText, BRAND } from '../../lib/color.ts' import { useSmallImage } from '../../lib/useSmallImage.ts' @@ -83,25 +83,10 @@ function Subheading({ children, accent }: { children: string; accent: string }) ) } -export default function CommunityBlog({ accent = BRAND }: { accent?: string }) { - const { data: blog, loading, error, reload } = useCommunityBlog() - - if (!blog) { - return ( -
- {loading ? ( - 'Loading…' - ) : ( - <> - Couldn’t load the blog. {error}{' '} - - - )} -
- ) - } +/* Its posts come with the page (the section's data), so there's no + loading here: the page has it or the page says it couldn't load. */ +export default function CommunityBlog({ blog, accent = BRAND }: { blog?: CommunityBlogData | null; accent?: string }) { + if (!blog) return null const { internal, external } = blog const hasInternal = internal.posts.length > 0 diff --git a/src/pages/sections/home/FeaturedBand.tsx b/src/pages/sections/home/FeaturedBand.tsx index 6834786..6299d16 100644 --- a/src/pages/sections/home/FeaturedBand.tsx +++ b/src/pages/sections/home/FeaturedBand.tsx @@ -8,7 +8,7 @@ ═══════════════════════════════════════════════════════════════ */ import FeaturedCards from '../../../components/FeaturedCards.tsx' -import type { FeaturedCard, FeaturedColumns } from '../../../lib/useFrontPage.ts' +import type { FeaturedCard, FeaturedColumns } from '../../../lib/sectionTypes.ts' type FeaturedBandProps = { id: string diff --git a/src/pages/sections/home/HeroStage.tsx b/src/pages/sections/home/HeroStage.tsx index 3f00a2b..52131d1 100644 --- a/src/pages/sections/home/HeroStage.tsx +++ b/src/pages/sections/home/HeroStage.tsx @@ -56,7 +56,7 @@ import { focusOnMount } from '../../../lib/focus.ts' import { useReadingMode } from '../../../lib/readingMode.ts' import { eventHref } from '../../../lib/hrefs.ts' import { seriesLabel } from '../../../lib/eventSeries.ts' -import type { Hero, HeroBackdrop, HeroEvent, HeroFeature, HeroSlide } from '../../../lib/useFrontPage.ts' +import type { Hero, HeroBackdrop, HeroEvent, HeroFeature, HeroSlide } from '../../../lib/sectionTypes.ts' const DEEP = '#001011' diff --git a/src/pages/sections/home/NextEventCountdown.tsx b/src/pages/sections/home/NextEventCountdown.tsx index f14917c..b9a7c38 100644 --- a/src/pages/sections/home/NextEventCountdown.tsx +++ b/src/pages/sections/home/NextEventCountdown.tsx @@ -24,7 +24,7 @@ import { Link } from 'react-router-dom' import { eventHref } from '../../../lib/hrefs.ts' import { upcomingOccurrences } from '../../../lib/eventSeries.ts' -import type { CountdownEvent } from '../../../lib/useFrontPage.ts' +import type { CountdownEvent } from '../../../lib/sectionTypes.ts' import { withAlpha, accentText, BRAND } from '../../../lib/color.ts' import { useReadingMode } from '../../../lib/readingMode.ts' diff --git a/src/pages/sections/home/Pathfinder.tsx b/src/pages/sections/home/Pathfinder.tsx index ae30366..5a8326d 100644 --- a/src/pages/sections/home/Pathfinder.tsx +++ b/src/pages/sections/home/Pathfinder.tsx @@ -3,7 +3,7 @@ The connect section as a question rather than a wall of forms: pick what you're here for, and that path's actions arrive. Paths - and actions are the admin's (Front page → Find your way in); + and actions are the admin's (a Connect nav section's paths, Pages → Page management); a path with no actions never reaches this component. The choices are a real tablist: arrow keys move between them, @@ -28,7 +28,7 @@ import { ArrowRight, ArrowUpRight, BookOpen, Dot, CalendarBlank, ChatCircle, Com import { useId, useRef, useState, type CSSProperties, type KeyboardEvent } from 'react' import HomeLink, { isExternal } from './HomeLink.tsx' -import type { FrontPagePath } from '../../../lib/useFrontPage.ts' +import type { SectionPath } from '../../../lib/sectionTypes.ts' import { ACCENTS, accentText, readableOn } from '../../../lib/color.ts' import { useReadingMode } from '../../../lib/readingMode.ts' @@ -36,7 +36,7 @@ type PathfinderProps = { id: string title: string blurb?: string | null - paths: FrontPagePath[] + paths: SectionPath[] } /* One accent per position, cycling. Paths are data; color is diff --git a/src/pages/sections/home/RetreatsBand.tsx b/src/pages/sections/home/RetreatsBand.tsx deleted file mode 100644 index d5c497c..0000000 --- a/src/pages/sections/home/RetreatsBand.tsx +++ /dev/null @@ -1,41 +0,0 @@ -/* ═══════════════════════════════════════════════════════════════ - RETREATS BAND - - The National Retreats carousel from the Retreats page, as-is: - same component, same filter, so an event edited in the admin - shows up identically in both places. This file only adds the - front page's heading and a way through to the full page. - ═══════════════════════════════════════════════════════════════ */ - -import { ArrowRight } from '@phosphor-icons/react' -import { Link } from 'react-router-dom' - -import EventListCards from '../EventList-Cards.tsx' -import { accentText, BRAND } from '../../../lib/color.ts' - - -type RetreatsBandProps = { id: string; title: string; blurb?: string | null } - -export default function RetreatsBand({ id, title, blurb }: RetreatsBandProps) { - return ( -
-
-
-

- {title} -

- {blurb &&

{blurb}

} -
- - All retreats
- - -
- ) -} diff --git a/src/pages/sections/home/StatsBand.tsx b/src/pages/sections/home/StatsBand.tsx index bf15ef6..0ad8f2a 100644 --- a/src/pages/sections/home/StatsBand.tsx +++ b/src/pages/sections/home/StatsBand.tsx @@ -12,7 +12,7 @@ import { useEffect, useRef, useState } from 'react' -import type { FrontPageStat } from '../../../lib/useFrontPage.ts' +import type { SectionStat } from '../../../lib/sectionTypes.ts' import { prefersLessMotion } from '../../../lib/motion.ts' import { useReadingMode } from '../../../lib/readingMode.ts' @@ -22,7 +22,7 @@ type StatsBandProps = { id: string title: string blurb?: string | null - stats: FrontPageStat[] + stats: SectionStat[] } export default function StatsBand({ id, title, blurb, stats }: StatsBandProps) {