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:
parent
4a1d6fd6e9
commit
9daf7b1a4f
29 changed files with 972 additions and 938 deletions
221
server/src/migrations/056_site_pages.sql
Normal file
221
server/src/migrations/056_site_pages.sql
Normal 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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue