diff --git a/docs/updating-data-in-code.md b/docs/updating-data-in-code.md
index 325f5df..5e6fa46 100644
--- a/docs/updating-data-in-code.md
+++ b/docs/updating-data-in-code.md
@@ -29,10 +29,11 @@ what a dropdown in the admin editor says.
| ------------------------------------------------------------ | ---------------- | ------------------------------------ |
| A record: an event, organization, person, team, award, timeline entry | the database | editing it in the admin |
| The front page's words, photos, bands, stats and paths | the database | Admin → Pages → Front page |
-| Blog posts, and the Community page's blog section (headings, pins, feeds) | the database | Admin → Data → Blog posts, and Admin → Pages → Community blog section |
+| Blog posts, and the Community page's blog settings (headings, pins, feeds) | the database | Admin → Data → Blog posts, and Admin → Pages → Community |
+| The sections of Retreats, Community, Resources, Organization and History: titles, blurbs, accents, their content blocks and presets (the blog, groups map, regions, partners, events, timeline, NGU's details) | the database | Admin → Pages → the page. A section title is 30 characters at most (it's listed in the side nav); a front page heading fits about 60. Preset names: `PRESETS` in `src/lib/adminSchema/sitePages.ts`, what each draws: `PRESETS` in `src/pages/SitePage.tsx` |
| The **label** a dropdown shows in the admin | code | [one file](#renaming-what-a-dropdown-shows) |
| The **list of allowed values** behind a fixed dropdown | database CHECK + code | [a migration and three files](#adding-removing-or-renaming-a-stored-value) |
-| Navigation, page section titles, colors, the site banner, history decades, the map grid | code | [the file named below](#other-content-that-lives-in-code) |
+| Navigation, colors, the site banner, history decades, the map grid | code | [the file named below](#other-content-that-lives-in-code) |
| A static page's title and intro (also its search title and description), the site's name, description, preview image, icons, search indexing, privacy contact email | the database, over `site.json` | Admin → Panel → Site settings (superadmins). Blank uses `site.json`, which also holds the site's address and the pages' defaults. See `docs/seo.md` |
| Uploaded images | disk + the `media` table | Admin → Tools → Media, or any image field. See `docs/media-uploads.md` |
@@ -185,7 +186,7 @@ also in `server/src/admin-schema/` and a CHECK):
| 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 blog section → 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 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 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` |
| Every list → Published / Listed / Featured filter | 1, 0 | **yes** | n/a |
@@ -201,7 +202,7 @@ code):
| Event → Scope (+ list filter); Front page → 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 |
| Event hosts / event people / team members / timeline people → Person | `people` | people |
-| Community blog section → Pinned posts → Post | `blog_posts` | blog posts, newest first |
+| Community → Community blog: pinned posts (ours) → Post | `blog_posts` | blog posts, newest first |
| Timeline → Record; Featured cards → Record | `record_refs` | every event, organization, 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)" |
@@ -219,7 +220,7 @@ each is changed in a different place:
| **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 subnav links under the header ("#Retreats", "#Calendar") | `PAGE_SECTIONS["/"]` in `src/navConfig.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`:
@@ -267,8 +268,8 @@ 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) | `src/navConfig.ts` | `PAGE_LINKS` (order), `PAGE_SECTIONS`, `NAV_ACTIONS`. The front page's sections aren't listed there: they follow the bands it shows (Front page → Sections), through `src/lib/navSections.ts` and `src/lib/frontPageBands.ts` (each band's anchor and default heading). A new page also needs a route in `src/App.tsx`. |
-| Section titles, blurbs and colors on Retreats, Community, Organization, Resources, Feedback, Privacy, Terms | the page file in `src/pages/` | the `SECTIONS` array at the top. A section's `id` must match its subnav `hash`. |
+| Header and footer navigation, each page's sections (the header dropdowns, mobile menu and footer site map) | `src/navConfig.ts` | `PAGE_LINKS` (order), `NAV_ACTIONS`. 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 also needs a route in `src/App.tsx`. |
+| Section titles, blurbs and colors on Feedback, Privacy, Terms | the page file in `src/pages/` | the `SECTIONS` array at the top. |
| Site-wide announcement banner | `src/data/bannerConfig.ts` | `enabled: false` hides it. Bump `id` when the message changes, so people who dismissed the old one see the new one. |
| History page decade headers | `src/data/historyDecades.ts` | Title, tagline and blurb per decade. |
| 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). |
diff --git a/server/src/admin-crud.js b/server/src/admin-crud.js
index f82a0b4..d7afa70 100644
--- a/server/src/admin-crud.js
+++ b/server/src/admin-crud.js
@@ -189,8 +189,9 @@ export function readRow(db, entity, rawId) {
row[ext.key] = readExtension(db, ext, id);
}
+ // As text, for the reason readChildren gives its nested ids.
for (const child of entity.children ?? []) {
- row[child.key] = readChildren(db, child, id);
+ row[child.key] = readChildren(db, child, String(id));
}
return row;
@@ -236,15 +237,13 @@ function readChildren(db, child, ownerId) {
)
.all(...params);
+ // 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
+ // blocks) holds as '13.0'; text suits an INTEGER owner just as well.
for (const child2 of child.children ?? []) {
for (const row of rows) {
- row[child2.key] = db
- .prepare(
- `SELECT * FROM ${child2.table}
- WHERE ${child2.owner.column} = ?
- ORDER BY ${child2.order}`,
- )
- .all(row.id);
+ row[child2.key] = readChildren(db, child2, String(row.id));
}
}
@@ -378,6 +377,14 @@ export function updateRow(db, entity, rawId, payload) {
`UPDATE ${entity.table} SET ${sets.join(", ")}
WHERE ${entity.idColumn} = ?`,
).run(...Object.values(values), id);
+ } else if (entity.concurrency) {
+ // A row that is only its collections (a site page and its
+ // sections) still marks the save, or the next stale save
+ // would pass the check above.
+ db.prepare(
+ `UPDATE ${entity.table} SET ${entity.concurrency} = datetime('now')
+ WHERE ${entity.idColumn} = ?`,
+ ).run(id);
}
writeExtensions(db, entity, id, payload, merged);
@@ -507,7 +514,10 @@ function keyedDbErrors(prefix, fn) {
}
}
-function writeChildren(db, entity, id, payload, parentValues) {
+function writeChildren(db, entity, rawId, payload, parentValues) {
+ // As text: an auto id is a JS number, which binds as REAL and
+ // lands in a TEXT owner column (a newsletter's blocks) as '1.0'.
+ const id = String(rawId);
for (const child of entity.children ?? []) {
if (!applies(child.when, parentValues)) {
deleteChildren(db, child, id);
@@ -516,80 +526,63 @@ function writeChildren(db, entity, id, payload, parentValues) {
if (payload[child.key] === undefined) continue; // not sent, not touched
deleteChildren(db, child, id);
+ writeRows(db, child, id, payload[child.key], `${child.key}.`, parentValues);
+ }
+}
- const incoming = Array.isArray(payload[child.key]) ? payload[child.key] : [];
+/* One collection's rows under one owner, then each row's own nested
+ collections under it, to any depth. Only the top level is deleted
+ first (writeChildren): a nested row goes with its owner, by a
+ foreign key's cascade or, for a polymorphic owner like a section's
+ blocks, by the owner table's cleanup trigger. */
+function writeRows(db, child, ownerId, incomingRaw, prefix, parentValues) {
+ const incoming = Array.isArray(incomingRaw) ? incomingRaw : [];
- // index is the row's place in what the client sent, so a
- // validation error still points at the row the user is looking
- // at. position counts only the rows that survive, so dropping a
- // blank in the middle doesn't leave a gap in sort_order.
- const rows = incoming
- .map((raw, index) => ({ raw, index }))
- .filter(({ raw }) => child.allowBlank || !isBlankChildRow(child, raw));
+ // index is the row's place in what the client sent, so a
+ // validation error still points at the row the user is looking
+ // at. position counts only the rows that survive, so dropping a
+ // blank in the middle doesn't leave a gap in sort_order.
+ const rows = incoming
+ .map((raw, index) => ({ raw, index }))
+ .filter(({ raw }) => child.allowBlank || !isBlankChildRow(child, raw));
- rows.forEach(({ raw, index }, position) => {
- const { values, errors } = coerceRow(child.columns, raw, {
- prefix: `${child.key}.${index}.`,
- });
- if (Object.keys(errors).length) {
- throw new HttpError(422, "Validation failed", errors);
- }
+ rows.forEach(({ raw, index }, position) => {
+ const rowPrefix = `${prefix}${index}.`;
+ const { values, errors } = coerceRow(child.columns, raw, { prefix: rowPrefix });
+ if (Object.keys(errors).length) {
+ throw new HttpError(422, "Validation failed", errors);
+ }
- const names = [child.owner.column, ...Object.keys(values)];
- const params = [id, ...Object.values(values)];
+ const names = [child.owner.column, ...Object.keys(values)];
+ const params = [ownerId, ...Object.values(values)];
- if (child.owner.kindColumn) {
- names.push(child.owner.kindColumn);
- params.push(child.owner.kindValue);
- }
- for (const [column, from] of Object.entries(child.owner.inherit ?? {})) {
- if (names.includes(column)) continue;
- names.push(column);
- params.push(parentValues[from] ?? id);
- }
- if (child.order === "sort_order" && !names.includes("sort_order")) {
- names.push("sort_order");
- params.push(position);
- }
+ if (child.owner.kindColumn) {
+ names.push(child.owner.kindColumn);
+ params.push(child.owner.kindValue);
+ }
+ for (const [column, from] of Object.entries(child.owner.inherit ?? {})) {
+ if (names.includes(column)) continue;
+ names.push(column);
+ params.push(parentValues[from] ?? ownerId);
+ }
+ if (child.order === "sort_order" && !names.includes("sort_order")) {
+ names.push("sort_order");
+ params.push(position);
+ }
- const result = keyedDbErrors(`${child.key}.${index}.`, () =>
- db
+ const result = keyedDbErrors(rowPrefix, () =>
+ db
.prepare(
`INSERT INTO ${child.table} (${names.join(", ")})
VALUES (${names.map(() => "?").join(", ")})`,
)
.run(...params),
- );
+ );
- for (const child2 of child.children ?? []) {
- const incomingNested = Array.isArray(raw[child2.key]) ? raw[child2.key] : [];
- const nested = incomingNested
- .map((rawItem, i) => ({ rawItem, i }))
- .filter(({ rawItem }) => child2.allowBlank || !isBlankChildRow(child2, rawItem));
-
- nested.forEach(({ rawItem, i }, nestedPosition) => {
- const item = coerceRow(child2.columns, rawItem, {
- prefix: `${child.key}.${index}.${child2.key}.${i}.`,
- });
- if (Object.keys(item.errors).length) {
- throw new HttpError(422, "Validation failed", item.errors);
- }
-
- const itemNames = [child2.owner.column, ...Object.keys(item.values)];
- const itemParams = [result.lastInsertRowid, ...Object.values(item.values)];
- if (!itemNames.includes("sort_order")) {
- itemNames.push("sort_order");
- itemParams.push(nestedPosition);
- }
-
- db.prepare(
- `INSERT INTO ${child2.table} (${itemNames.join(", ")})
- VALUES (${itemNames.map(() => "?").join(", ")})`,
- ).run(...itemParams);
- });
- }
- });
- }
+ for (const child2 of child.children ?? []) {
+ writeRows(db, child2, String(result.lastInsertRowid), raw[child2.key], `${rowPrefix}${child2.key}.`, values);
+ }
+ });
}
function deleteChildren(db, child, ownerId) {
diff --git a/server/src/admin-schema.js b/server/src/admin-schema.js
index ba669dc..5bca3db 100644
--- a/server/src/admin-schema.js
+++ b/server/src/admin-schema.js
@@ -49,9 +49,16 @@ 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, communityPage } from "./admin-schema/blog.js";
+import { blogPosts } from "./admin-schema/blog.js";
import { siteSettings } from "./admin-schema/siteSettings.js";
-import { organizationPage } from "./admin-schema/organizationPage.js";
+import { newsletters } from "./admin-schema/newsletters.js";
+import {
+ communityPage,
+ retreatsPage,
+ resourcesPage,
+ organizationPage,
+ historyPage,
+} from "./admin-schema/sitePages.js";
export const ENTITIES = {
organizations,
@@ -63,8 +70,12 @@ export const ENTITIES = {
front_page: frontPage,
blog_posts: blogPosts,
community_page: communityPage,
+ retreats_page: retreatsPage,
+ resources_page: resourcesPage,
organization_page: organizationPage,
+ history_page: historyPage,
site_settings: siteSettings,
+ newsletters,
};
/* ── Options for the form's select inputs ────────────────────── */
diff --git a/server/src/admin-schema/blog.js b/server/src/admin-schema/blog.js
index 55f3da2..cb09ac8 100644
--- a/server/src/admin-schema/blog.js
+++ b/server/src/admin-schema/blog.js
@@ -1,11 +1,10 @@
-import { text, url, int, bool, date, featuredCardsChild, blocksChild } from "./columns.js";
+import { text, bool, date, blocksChild } from "./columns.js";
/* ── Blog (031_blog.sql) ─────────────────────────────────────────
Posts of our own, with a content-block body and people as
- authors, and the Community page's blog section, a singleton like
- the front page. The section's community posts are featured cards
- owned by 'community_page'. ─────────────────────────────────── */
+ authors. The Community page's blog section is edited with that
+ page (sitePages.js). ──────────────────────────────────────── */
export const blogPosts = {
key: "blog_posts",
@@ -46,48 +45,3 @@ export const blogPosts = {
blocksChild("blog_post"),
],
};
-
-export const communityPage = {
- key: "community_page",
- table: "community_page",
- idColumn: "id",
- idKind: "slug",
- singleton: "community",
- concurrency: "updated_at",
-
- list: {
- columns: ["id", "blog_title", "updated_at"],
- filters: [],
- search: [],
- order: "id",
- },
-
- columns: [
- text("blog_title"),
- text("blog_blurb"),
- text("internal_title"),
- int("internal_slots"),
- text("external_title"),
- int("external_slots"),
- url("external_url"),
- text("external_label"),
- ],
-
- children: [
- {
- key: "pinned_posts",
- table: "community_page_pinned_posts",
- owner: { column: "page_id" },
- order: "sort_order",
- columns: [text("post_id", { required: true })],
- },
- featuredCardsChild("community_page"),
- {
- key: "feeds",
- table: "community_page_feeds",
- owner: { column: "page_id" },
- order: "sort_order",
- columns: [url("url", { required: true }), text("label")],
- },
- ],
-};
diff --git a/server/src/admin-schema/newsletters.js b/server/src/admin-schema/newsletters.js
new file mode 100644
index 0000000..be6d58d
--- /dev/null
+++ b/server/src/admin-schema/newsletters.js
@@ -0,0 +1,27 @@
+import { text, blocksChild } from "./columns.js";
+
+/* ── Newsletter drafts (057_newsletters.sql) ─────────────────────
+
+ Saved from Tools → Newsletter (AdminNewsletter.tsx), which is
+ their only editor: there is no list or form for them in Data.
+ `picks` is the builder's JSON of what's ticked. Deleting a draft
+ takes its blocks with it (newsletters_cleanup). */
+
+export const newsletters = {
+ key: "newsletters",
+ table: "newsletters",
+ idColumn: "id",
+ idKind: "auto",
+ concurrency: "updated_at",
+
+ list: {
+ columns: ["id", "title", "updated_at"],
+ filters: [],
+ search: ["title"],
+ order: "updated_at DESC, id DESC",
+ },
+
+ columns: [text("title"), text("intro"), text("footer"), text("picks")],
+
+ children: [blocksChild("newsletter")],
+};
diff --git a/server/src/admin-schema/organizationPage.js b/server/src/admin-schema/organizationPage.js
deleted file mode 100644
index f641c36..0000000
--- a/server/src/admin-schema/organizationPage.js
+++ /dev/null
@@ -1,43 +0,0 @@
-/* The Organization page (/organization): one row, its blocks and its
- volunteering links (055_organization_page.sql). Two block
- collections, each its own owner kind, so the editor shows them
- apart: the Mission, Vision & Values section, and the Leadership
- section (a People block per team, in order). */
-
-import { text, url, blocksChild } from "./columns.js";
-
-export const organizationPage = {
- key: "organization_page",
- table: "organization_page",
- idColumn: "id",
- idKind: "slug",
- singleton: "organization",
- concurrency: "updated_at",
-
- list: {
- columns: ["id", "updated_at"],
- filters: [],
- search: [],
- order: "id",
- },
-
- columns: [
- text("mission_title"),
- text("leadership_title"),
- text("leadership_blurb"),
- text("volunteer_title"),
- text("volunteer_blurb"),
- ],
-
- children: [
- { ...blocksChild("org_page_mission"), key: "mission_blocks" },
- { ...blocksChild("org_page_leadership"), key: "leadership_blocks" },
- {
- key: "volunteer_links",
- table: "organization_page_links",
- owner: { column: "page_id" },
- order: "sort_order",
- columns: [text("label", { required: true }), url("url", { required: true })],
- },
- ],
-};
diff --git a/server/src/admin-schema/sitePages.js b/server/src/admin-schema/sitePages.js
new file mode 100644
index 0000000..99edd3f
--- /dev/null
+++ b/server/src/admin-schema/sitePages.js
@@ -0,0 +1,95 @@
+import { text, url, int, enumeration, featuredCardsChild, blocksChild } from "./columns.js";
+
+/* ── The site's own pages (056_site_pages.sql) ───────────────────
+
+ Community, Retreats, Resources, Organization and History: one
+ site_pages row each, edited as its own singleton, with its
+ sections nested under it and each section's blocks under that
+ (the blocks' items under them, as on any record). A section is
+ either its blocks or a preset, a prebuilt part of the site
+ (SitePage.tsx draws both).
+
+ 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. */
+
+const sectionsChild = {
+ key: "sections",
+ table: "page_sections",
+ owner: { column: "page_id" },
+ order: "sort_order",
+ columns: [
+ text("anchor", { required: true }),
+ text("title", { required: true }),
+ text("blurb"),
+ enumeration("accent", ["teal", "deep", "green", "amber"]),
+ enumeration("preset", [
+ "community_blog",
+ "group_map",
+ "region_list",
+ "partner_list",
+ "events",
+ "timeline",
+ "organization_details",
+ ]),
+ text("scope_id"),
+ enumeration("event_type", ["retreat", "class", "workshop", "meeting", "other"]),
+ enumeration("view", ["carousel", "grid", "map"]),
+ ],
+ children: [blocksChild("page_section")],
+};
+
+const sitePage = (id, more = {}) => ({
+ key: `${id}_page`,
+ table: "site_pages",
+ idColumn: "id",
+ idKind: "slug",
+ singleton: id,
+ concurrency: "updated_at",
+
+ list: { columns: ["id", "updated_at"], filters: [], search: [], order: "id" },
+
+ columns: [],
+ ...more,
+ children: [sectionsChild, ...(more.children ?? [])],
+});
+
+export const communityPage = sitePage("community", {
+ extensions: [
+ {
+ key: "blog",
+ table: "community_page",
+ idColumn: "id",
+ columns: [
+ text("internal_title"),
+ int("internal_slots"),
+ text("external_title"),
+ int("external_slots"),
+ url("external_url"),
+ text("external_label"),
+ ],
+ },
+ ],
+ children: [
+ {
+ key: "pinned_posts",
+ table: "community_page_pinned_posts",
+ owner: { column: "page_id" },
+ order: "sort_order",
+ columns: [text("post_id", { required: true })],
+ },
+ featuredCardsChild("community_page"),
+ {
+ key: "feeds",
+ table: "community_page_feeds",
+ owner: { column: "page_id" },
+ order: "sort_order",
+ columns: [url("url", { required: true }), text("label")],
+ },
+ ],
+});
+
+export const retreatsPage = sitePage("retreats");
+export const resourcesPage = sitePage("resources");
+export const organizationPage = sitePage("organization");
+export const historyPage = sitePage("history");
diff --git a/server/src/index.js b/server/src/index.js
index c8a0595..104101c 100644
--- a/server/src/index.js
+++ b/server/src/index.js
@@ -26,7 +26,7 @@ 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 organizationPage from "./routes/organizationPage.js";
+import sitePages from "./routes/sitePages.js";
import pages from "./routes/pages.js";
import feedback from "./routes/feedback.js";
import requests from "./routes/requests.js";
@@ -170,7 +170,7 @@ app.route("/api", history);
app.route("/api", home);
app.route("/api", directory);
app.route("/api", blog);
-app.route("/api", organizationPage);
+app.route("/api", sitePages);
// Tighter limit on the write path than anything else gets.
app.use("/api/feedback", rateLimit({ windowMs: 60_000, max: 5 }));
diff --git a/server/src/migrations/056_site_pages.sql b/server/src/migrations/056_site_pages.sql
new file mode 100644
index 0000000..8e72891
--- /dev/null
+++ b/server/src/migrations/056_site_pages.sql
@@ -0,0 +1,221 @@
+-- ═══════════════════════════════════════════════════════════════
+-- 056 PAGE EDITORS: SECTIONS FOR THE SITE'S OWN PAGES
+--
+-- Community, Retreats, Resources, Organization and History are
+-- built in the admin (Pages → each page) as a list of sections. A
+-- section is its title (30 characters at most: it's listed in the
+-- page's side nav), an optional blurb, an accent and the anchor it
+-- sits at, and then either
+--
+-- its own content blocks content_blocks owned 'page_section',
+-- owner_id the section's id
+-- a preset a prebuilt part of the site, drawn by
+-- the page (SitePage.tsx): the Community
+-- blog, the group map, the region list,
+-- the partner cards, an event list (scope,
+-- type and the view it opens in), the
+-- timeline, NGU's address and tax details
+--
+-- Every page's sections are seeded as the code drew them, so nothing
+-- moves on the site. Organization takes what 055's editor held: its
+-- Mission and Leadership blocks, with the Volunteering title, blurb
+-- and links appended to the Leadership section as a heading, a
+-- paragraph and link buttons; 055's tables go.
+--
+-- The Community blog's own settings (its slots, pinned posts, feeds)
+-- stay in community_page, now edited inside the Community page
+-- editor; its heading and blurb become the blog section's own, so
+-- community_page loses blog_title and blog_blurb.
+--
+-- content_blocks is rebuilt for its owner_kind CHECK (as 055 did),
+-- moving 055's blocks across on the way. A section deleted (every
+-- save rewrites them) takes its blocks with it, by trigger, since
+-- the owner is polymorphic and can't be a foreign key.
+-- ═══════════════════════════════════════════════════════════════
+
+CREATE TABLE site_pages (
+ id TEXT PRIMARY KEY
+ CHECK (id IN ('community', 'retreats', 'resources', 'organization', 'history')),
+ updated_at TEXT NOT NULL DEFAULT (datetime('now'))
+) STRICT;
+
+INSERT INTO site_pages (id) VALUES ('community'), ('retreats'), ('resources'), ('organization'), ('history');
+
+CREATE TABLE page_sections (
+ 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)."
+ CHECK (length(title) <= 30),
+ 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', 'organization_details')),
+ -- 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')),
+ UNIQUE (page_id, anchor)
+) STRICT;
+
+CREATE INDEX page_sections_page_idx ON page_sections (page_id, sort_order);
+
+INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, accent, preset, scope_id, event_type, view)
+SELECT 'community', 0, 'blog', COALESCE(blog_title, 'Community Blog'), blog_blurb, 'teal', 'community_blog', NULL, NULL, NULL
+ FROM community_page WHERE id = 'community';
+
+INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, accent, preset, scope_id, event_type, view) VALUES
+ ('community', 1, 'groups', 'Local Groups',
+ 'Young adult groups meeting in person and online across the movement.', 'teal', 'group_map', NULL, NULL, 'map'),
+ ('community', 2, 'regions', 'Unity Regions',
+ 'The regional organizations that support groups and host their own gatherings.', 'deep', 'region_list', NULL, NULL, NULL),
+ ('community', 3, 'partners', 'Partner Organizations',
+ 'Organizations we collaborate with across the Unity movement and beyond.', 'amber', 'partner_list', NULL, NULL, NULL),
+
+ ('retreats', 0, 'national', 'National Retreats',
+ 'Our flagship gatherings, open to young adults across the country.', 'teal', 'events', 'national', 'retreat', 'carousel'),
+ ('retreats', 1, 'regional', 'Regional Retreats',
+ 'Smaller gatherings hosted by regions throughout the year.', 'green', 'events', 'regional', 'retreat', 'grid'),
+ ('retreats', 2, 'partner', 'Partner Events',
+ 'Retreats hosted by organizations we collaborate with.', 'amber', 'events', 'partner', 'retreat', 'grid'),
+
+ ('resources', 0, 'unity', 'Unity Teachings',
+ 'Core principles, readings, and study material from the Unity movement.', 'teal', NULL, NULL, NULL, NULL),
+ ('resources', 1, 'branding', 'Branding & Marketing',
+ 'Logos, colors, templates, and guidelines for representing NGU.', 'green', NULL, NULL, NULL, NULL),
+ ('resources', 2, 'partner', 'Partner Resources',
+ 'Material for the organizations we collaborate with.', 'amber', NULL, NULL, NULL, NULL),
+
+ ('history', 0, 'timeline', 'NGU Timeline', 'Open a year to see what happened.', 'teal', 'timeline', NULL, NULL, NULL),
+
+ ('organization', 2, 'contact', 'Details & Contact', NULL, 'deep', 'organization_details', NULL, NULL, NULL);
+
+INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, accent)
+SELECT 'organization', 0, 'mission', substr(COALESCE(mission_title, 'Mission, Vision & Values'), 1, 30), NULL, 'teal'
+ FROM organization_page WHERE id = 'organization';
+
+INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, accent)
+SELECT 'organization', 1, 'leadership', substr(COALESCE(leadership_title, 'Leadership'), 1, 30), leadership_blurb, 'green'
+ FROM organization_page WHERE id = 'organization';
+
+ALTER TABLE community_page DROP COLUMN blog_title;
+ALTER TABLE community_page DROP COLUMN blog_blurb;
+
+
+-- ── Blocks: the new owner kind, 055's blocks moved across ──────
+
+CREATE TABLE content_blocks_new (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ owner_kind TEXT NOT NULL
+ CHECK (owner_kind IN ('organization', 'event', 'person', 'team', 'blog_post', 'page_section')),
+ owner_id TEXT NOT NULL,
+ slot TEXT NOT NULL DEFAULT 'body' CHECK (slot IN ('card', 'body')),
+ sort_order INTEGER NOT NULL DEFAULT 0,
+
+ type TEXT NOT NULL
+ CHECK (type IN ('heading', 'subheading', 'paragraph',
+ 'list', 'links', 'quote', 'image', 'divider',
+ 'video', 'button', 'callout', 'schedule', 'table', 'cards',
+ 'people')),
+ text TEXT,
+ media TEXT,
+ href TEXT,
+ alt TEXT,
+ cite TEXT,
+ team_id TEXT REFERENCES teams (id) ON DELETE SET NULL
+) STRICT;
+
+INSERT INTO content_blocks_new
+ (id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite, team_id)
+SELECT b.id,
+ CASE WHEN b.owner_kind IN ('org_page_mission', 'org_page_leadership') THEN 'page_section' ELSE b.owner_kind END,
+ CASE b.owner_kind
+ WHEN 'org_page_mission' THEN
+ (SELECT CAST(s.id AS TEXT) FROM page_sections s WHERE s.page_id = 'organization' AND s.anchor = 'mission')
+ WHEN 'org_page_leadership' THEN
+ (SELECT CAST(s.id AS TEXT) FROM page_sections s WHERE s.page_id = 'organization' AND s.anchor = 'leadership')
+ ELSE b.owner_id
+ END,
+ b.slot, b.sort_order, b.type, b.text, b.media, b.href, b.alt, b.cite, b.team_id
+ FROM content_blocks b;
+
+PRAGMA legacy_alter_table = ON;
+DROP TABLE content_blocks;
+ALTER TABLE content_blocks_new RENAME TO content_blocks;
+PRAGMA legacy_alter_table = OFF;
+
+CREATE INDEX content_blocks_owner_idx
+ ON content_blocks (owner_kind, owner_id, slot, sort_order);
+
+-- Volunteering, appended to the Leadership section where 055 had it.
+INSERT INTO content_blocks (owner_kind, owner_id, slot, sort_order, type, text)
+SELECT 'page_section', CAST(s.id AS TEXT), 'body', 1000, 'heading', COALESCE(p.volunteer_title, 'Volunteering')
+ FROM organization_page p
+ JOIN page_sections s ON s.page_id = 'organization' AND s.anchor = 'leadership'
+ WHERE p.volunteer_title IS NOT NULL OR p.volunteer_blurb IS NOT NULL
+ OR EXISTS (SELECT 1 FROM organization_page_links);
+
+INSERT INTO content_blocks (owner_kind, owner_id, slot, sort_order, type, text)
+SELECT 'page_section', CAST(s.id AS TEXT), 'body', 1001, 'paragraph', p.volunteer_blurb
+ FROM organization_page p
+ JOIN page_sections s ON s.page_id = 'organization' AND s.anchor = 'leadership'
+ WHERE p.volunteer_blurb IS NOT NULL;
+
+INSERT INTO content_blocks (owner_kind, owner_id, slot, sort_order, type)
+SELECT 'page_section', CAST(s.id AS TEXT), 'body', 1002, 'links'
+ FROM page_sections s
+ WHERE s.page_id = 'organization' AND s.anchor = 'leadership'
+ AND EXISTS (SELECT 1 FROM organization_page_links);
+
+INSERT INTO content_block_items (block_id, sort_order, text, url)
+SELECT b.id, l.sort_order, l.label, l.url
+ FROM organization_page_links l
+ JOIN content_blocks b ON b.owner_kind = 'page_section' AND b.type = 'links' AND b.sort_order = 1002;
+
+DROP TABLE organization_page_links;
+DROP TABLE organization_page;
+
+
+-- ── Triggers last (see CLAUDE.md, Migrations) ──
+
+CREATE TRIGGER site_pages_touch
+AFTER UPDATE ON site_pages
+FOR EACH ROW WHEN new.updated_at = old.updated_at
+BEGIN
+ UPDATE site_pages SET updated_at = datetime('now') WHERE id = new.id;
+END;
+
+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);
+END;
+
+CREATE TRIGGER content_blocks_owner_exists
+BEFORE INSERT ON content_blocks
+BEGIN
+ SELECT CASE
+ WHEN new.owner_kind = 'event'
+ AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.owner_id)
+ THEN RAISE(ABORT, 'content_blocks: no such event')
+ WHEN new.owner_kind = 'organization'
+ AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.owner_id)
+ THEN RAISE(ABORT, 'content_blocks: no such organization')
+ WHEN new.owner_kind = 'person'
+ AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.owner_id)
+ THEN RAISE(ABORT, 'content_blocks: no such person')
+ WHEN new.owner_kind = 'team'
+ AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.owner_id)
+ THEN RAISE(ABORT, 'content_blocks: no such team')
+ WHEN new.owner_kind = 'blog_post'
+ AND NOT EXISTS (SELECT 1 FROM blog_posts WHERE id = new.owner_id)
+ THEN RAISE(ABORT, 'content_blocks: no such blog post')
+ 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, 'content_blocks: no such page section')
+ END;
+END;
diff --git a/server/src/migrations/057_newsletters.sql b/server/src/migrations/057_newsletters.sql
new file mode 100644
index 0000000..708889d
--- /dev/null
+++ b/server/src/migrations/057_newsletters.sql
@@ -0,0 +1,111 @@
+-- ═══════════════════════════════════════════════════════════════
+-- 057 NEWSLETTER DRAFTS
+--
+-- Tools → Newsletter saves what it builds as a draft, to come back
+-- to, copy into Mailchimp again, or post as a blog post:
+--
+-- title, intro the email's heading and opening lines
+-- footer the closing lines (blank: the site's name and
+-- address); no unsubscribe link, since Mailchimp
+-- adds its own
+-- picks what's ticked, as JSON: event ids, blog post
+-- ids, and the front page cards by their link
+-- ({"events": [...], "posts": [...], "cards": [...]})
+-- blocks content_blocks owned 'newsletter': whatever is
+-- written for this issue, under the intro
+--
+-- content_blocks is rebuilt for its owner_kind CHECK (as 056 did). A
+-- draft deleted takes its blocks with it, by trigger.
+-- ═══════════════════════════════════════════════════════════════
+
+CREATE TABLE newsletters (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ title TEXT,
+ intro TEXT,
+ footer TEXT,
+ picks TEXT NOT NULL DEFAULT '{}' CHECK (json_valid(picks)),
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
+ updated_at TEXT NOT NULL DEFAULT (datetime('now'))
+) STRICT;
+
+
+-- ── Blocks: the new owner kind ─────────────────────────────────
+
+CREATE TABLE content_blocks_new (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ owner_kind TEXT NOT NULL
+ CHECK (owner_kind IN ('organization', 'event', 'person', 'team', 'blog_post', 'page_section',
+ 'newsletter')),
+ owner_id TEXT NOT NULL,
+ slot TEXT NOT NULL DEFAULT 'body' CHECK (slot IN ('card', 'body')),
+ sort_order INTEGER NOT NULL DEFAULT 0,
+
+ type TEXT NOT NULL
+ CHECK (type IN ('heading', 'subheading', 'paragraph',
+ 'list', 'links', 'quote', 'image', 'divider',
+ 'video', 'button', 'callout', 'schedule', 'table', 'cards',
+ 'people')),
+ text TEXT,
+ media TEXT,
+ href TEXT,
+ alt TEXT,
+ cite TEXT,
+ team_id TEXT REFERENCES teams (id) ON DELETE SET NULL
+) STRICT;
+
+INSERT INTO content_blocks_new
+ (id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite, team_id)
+SELECT id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite, team_id
+ FROM content_blocks;
+
+PRAGMA legacy_alter_table = ON;
+DROP TABLE content_blocks;
+ALTER TABLE content_blocks_new RENAME TO content_blocks;
+PRAGMA legacy_alter_table = OFF;
+
+CREATE INDEX content_blocks_owner_idx
+ ON content_blocks (owner_kind, owner_id, slot, sort_order);
+
+
+-- ── Triggers last (see CLAUDE.md, Migrations) ──
+
+CREATE TRIGGER newsletters_touch
+AFTER UPDATE ON newsletters
+FOR EACH ROW WHEN new.updated_at = old.updated_at
+BEGIN
+ UPDATE newsletters SET updated_at = datetime('now') WHERE id = new.id;
+END;
+
+CREATE TRIGGER newsletters_cleanup
+AFTER DELETE ON newsletters
+BEGIN
+ DELETE FROM content_blocks WHERE owner_kind = 'newsletter' AND owner_id = CAST(old.id AS TEXT);
+END;
+
+CREATE TRIGGER content_blocks_owner_exists
+BEFORE INSERT ON content_blocks
+BEGIN
+ SELECT CASE
+ WHEN new.owner_kind = 'event'
+ AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.owner_id)
+ THEN RAISE(ABORT, 'content_blocks: no such event')
+ WHEN new.owner_kind = 'organization'
+ AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.owner_id)
+ THEN RAISE(ABORT, 'content_blocks: no such organization')
+ WHEN new.owner_kind = 'person'
+ AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.owner_id)
+ THEN RAISE(ABORT, 'content_blocks: no such person')
+ WHEN new.owner_kind = 'team'
+ AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.owner_id)
+ THEN RAISE(ABORT, 'content_blocks: no such team')
+ WHEN new.owner_kind = 'blog_post'
+ AND NOT EXISTS (SELECT 1 FROM blog_posts WHERE id = new.owner_id)
+ THEN RAISE(ABORT, 'content_blocks: no such blog post')
+ 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, 'content_blocks: no such page section')
+ WHEN new.owner_kind = 'newsletter'
+ AND NOT EXISTS (SELECT 1 FROM newsletters WHERE CAST(id AS TEXT) = new.owner_id)
+ THEN RAISE(ABORT, 'content_blocks: no such newsletter')
+ END;
+END;
diff --git a/server/src/routes/blog.js b/server/src/routes/blog.js
index d6c890a..7c20922 100644
--- a/server/src/routes/blog.js
+++ b/server/src/routes/blog.js
@@ -191,8 +191,6 @@ blog.get("/community-blog", async (c) => {
return json(c, {
community_blog: {
- title: page.blog_title,
- blurb: page.blog_blurb,
internal: {
title: page.internal_title,
posts: posts.map((row) =>
diff --git a/server/src/routes/organizationPage.js b/server/src/routes/organizationPage.js
deleted file mode 100644
index 500b1c2..0000000
--- a/server/src/routes/organizationPage.js
+++ /dev/null
@@ -1,43 +0,0 @@
-/* ═══════════════════════════════════════════════════════════════
- ORGANIZATION PAGE ROUTE: read-only, mounted under /api
-
- GET /organization-page the Organization page's own content:
- its section titles, the Mission and
- Leadership blocks, and Volunteering
- (title, blurb, links)
-
- Edited in the admin as Pages → Organization page
- (admin-schema/organizationPage.js). The blocks are shaped as on
- any record page (loadBlocks), so ContentBlocks draws them.
- ═══════════════════════════════════════════════════════════════ */
-
-import { Hono } from "hono";
-import { json, loadBlocks } from "../shape.js";
-
-const ID = "organization";
-const organizationPage = new Hono();
-
-organizationPage.get("/organization-page", (c) => {
- const db = c.get("db");
- const row = db.prepare(`SELECT * FROM organization_page WHERE id = ?`).get(ID) ?? {};
- const links = db
- .prepare(`SELECT label, url FROM organization_page_links WHERE page_id = ? ORDER BY sort_order, id`)
- .all(ID);
-
- return json(c, {
- page: {
- mission_title: row.mission_title ?? null,
- mission_blocks: loadBlocks(db, "org_page_mission", [ID]).get(ID) ?? [],
- leadership_title: row.leadership_title ?? null,
- leadership_blurb: row.leadership_blurb ?? null,
- leadership_blocks: loadBlocks(db, "org_page_leadership", [ID]).get(ID) ?? [],
- volunteer: {
- title: row.volunteer_title ?? null,
- blurb: row.volunteer_blurb ?? null,
- links,
- },
- },
- });
-});
-
-export default organizationPage;
diff --git a/server/src/routes/sitePages.js b/server/src/routes/sitePages.js
new file mode 100644
index 0000000..73c614d
--- /dev/null
+++ b/server/src/routes/sitePages.js
@@ -0,0 +1,57 @@
+/* ═══════════════════════════════════════════════════════════════
+ SITE PAGE ROUTES: read-only, mounted under /api
+
+ GET /site-pages every site page's section headings, for
+ the header's dropdowns and the side nav
+ GET /site-pages/:id one page's sections, in order: heading,
+ accent, preset (and an events preset's
+ filter and view), and its blocks
+
+ Edited in the admin as Pages → each page
+ (admin-schema/sitePages.js). Blocks are shaped as on any record
+ page (loadBlocks), so ContentBlocks draws them.
+ ═══════════════════════════════════════════════════════════════ */
+
+import { Hono } from "hono";
+import { json, loadBlocks } from "../shape.js";
+
+const sitePages = new Hono();
+
+sitePages.get("/site-pages", (c) => {
+ const rows = c
+ .get("db")
+ .prepare(`SELECT page_id, anchor, title FROM page_sections ORDER BY page_id, sort_order, id`)
+ .all();
+
+ const pages = {};
+ for (const row of rows) (pages[row.page_id] ??= []).push({ anchor: row.anchor, title: row.title });
+ return json(c, { pages });
+});
+
+sitePages.get("/site-pages/:id", (c) => {
+ const db = c.get("db");
+ const id = c.req.param("id");
+ if (!db.prepare(`SELECT 1 FROM site_pages WHERE id = ?`).get(id)) {
+ return c.json({ error: "No such page." }, 404);
+ }
+
+ const rows = db
+ .prepare(
+ `SELECT id, anchor, title, blurb, accent, preset, scope_id, event_type, view
+ FROM page_sections WHERE page_id = ? ORDER BY sort_order, id`,
+ )
+ .all(id);
+ const blocks = loadBlocks(db, "page_section", rows.map((row) => String(row.id)));
+
+ return json(c, {
+ page: {
+ id,
+ sections: rows.map(({ id: sectionId, ...section }) => ({
+ ...section,
+ blocks: blocks.get(String(sectionId)) ?? [],
+ })),
+ },
+ });
+});
+
+export default sitePages;
diff --git a/src/App.tsx b/src/App.tsx
index 43ae74f..5111b83 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -49,11 +49,9 @@ const lazyPage = (load) =>
throw err
}),
)
-const Retreats = lazyPage(() => import("./pages/Retreats.tsx"))
-const Community = lazyPage(() => import("./pages/Community.tsx"))
-const Organization = lazyPage(() => import("./pages/Organization.tsx"))
-const Resources = lazyPage(() => import("./pages/Resources.tsx"))
-const History = lazyPage(() => import("./pages/History.tsx"))
+// Community, Retreats, Resources, Organization and History: each
+// built in the admin from sections.
+const SitePage = lazyPage(() => import("./pages/SitePage.tsx"))
const Feedback = lazyPage(() => import("./pages/Feedback.tsx"))
const Request = lazyPage(() => import("./pages/Request.tsx"))
const Giving = lazyPage(() => import("./pages/Giving.tsx"))
@@ -91,9 +89,9 @@ export default function App() {
{/* Layout renders the nav once and swaps page content into */}
}>
} />
- } />
+ } />
} />
- } />
+ } />
} />
} />
} />
@@ -102,9 +100,9 @@ export default function App() {
} />
} />
} />
- } />
- } />
- } />
+ } />
+ } />
+ } />
} />
} />
} />
diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx
index c252e21..6f25a42 100644
--- a/src/components/Footer.tsx
+++ b/src/components/Footer.tsx
@@ -50,8 +50,8 @@ export default function Footer() {