Page editors: Retreats, Community, Resources, Organization and History built from sections

Each page is now a list of sections edited in Admin → Pages: a title
(30 characters at most, for the side nav), URL ID, blurb and accent,
its own content blocks, and an optional preset (Community blog, groups
map, region list, partner cards, events, timeline, NGU's details).
Migration 056 seeds every page as the code drew it and moves the
Organization editor's blocks and volunteering into its sections. The
Community blog's settings move into the Community editor. The header,
footer and side nav read each page's sections from the API.

The admin engine reads and writes nested collections to any depth.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-10-01 00:15:30 -05:00
parent 4a1d6fd6e9
commit 9daf7b1a4f
29 changed files with 972 additions and 938 deletions

View file

@ -236,15 +236,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 +376,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);
@ -516,80 +522,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) {

View file

@ -49,9 +49,15 @@ 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 {
communityPage,
retreatsPage,
resourcesPage,
organizationPage,
historyPage,
} from "./admin-schema/sitePages.js";
export const ENTITIES = {
organizations,
@ -63,7 +69,10 @@ 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,
};

View file

@ -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")],
},
],
};

View file

@ -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 })],
},
],
};

View file

@ -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");

View file

@ -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 }));

View file

@ -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;

View file

@ -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) =>

View file

@ -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;

View file

@ -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;