diff --git a/server/src/admin-schema/columns.js b/server/src/admin-schema/columns.js index 37c7eca..bda56ea 100644 --- a/server/src/admin-schema/columns.js +++ b/server/src/admin-schema/columns.js @@ -131,7 +131,7 @@ export const blocksChild = (ownerKind) => ({ owner: { column: "owner_id", kindColumn: "owner_kind", kindValue: ownerKind }, order: "sort_order", columns: [ - enumeration("slot", ["card", "body"], { required: true }), + enumeration("slot", ["card", "body", "both"], { required: true }), enumeration( "type", [ diff --git a/server/src/migrations/071_block_slot_both.sql b/server/src/migrations/071_block_slot_both.sql new file mode 100644 index 0000000..06432fe --- /dev/null +++ b/server/src/migrations/071_block_slot_both.sql @@ -0,0 +1,82 @@ +-- ═══════════════════════════════════════════════════════════════ +-- 071 BLOCK SLOT: BOTH +-- +-- A content block's "Shown in" gets a third choice. Until now a card +-- block showed on the card and on the record's page as well (the +-- pages printed the card's paragraphs above the body), which the +-- editor didn't say. Now: +-- +-- body the page only +-- card the card only +-- both the card and the page (the card takes paragraphs only) +-- +-- Every existing card block becomes both, so nothing on the site +-- moves. The CHECK can't change in place, so the table is rebuilt. +-- ═══════════════════════════════════════════════════════════════ + +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', 'both')), + 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, + captions TEXT +) STRICT; + +INSERT INTO content_blocks_new + (id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite, team_id, captions) +SELECT id, owner_kind, owner_id, CASE slot WHEN 'card' THEN 'both' ELSE slot END, + sort_order, type, text, media, href, alt, cite, team_id, captions + FROM content_blocks; + +-- The cleanup triggers on other tables name content_blocks; legacy +-- mode leaves them alone through the rename. +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); + +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 420134a..0b437ea 100644 --- a/server/src/routes/blog.js +++ b/server/src/routes/blog.js @@ -75,7 +75,7 @@ function firstParagraphs(db, rows) { `SELECT owner_id, text FROM ( SELECT owner_id, text, ROW_NUMBER() OVER (PARTITION BY owner_id ORDER BY sort_order) AS n FROM content_blocks - WHERE owner_kind = 'blog_post' AND slot = 'body' AND type = 'paragraph' + WHERE owner_kind = 'blog_post' AND slot IN ('body', 'both') AND type = 'paragraph' AND text IS NOT NULL AND text <> '' AND owner_id IN (${marks(ids.length)}) ) WHERE n = 1`, diff --git a/server/src/seed-showcase.js b/server/src/seed-showcase.js index 5559559..8c88440 100644 --- a/server/src/seed-showcase.js +++ b/server/src/seed-showcase.js @@ -165,7 +165,10 @@ const pageBody = (what) => [ ["button", { text: "Get involved", href: "/feedback" }], ]; -/* The card slot: paragraphs only, shown on cards and list rows. */ +/* Card text: paragraphs only, shown on cards and list rows. Most + records put it in "both" (the card and the page); the series and + the past event keep it to the card, to check that it stays off + their pages. */ const cardText = (what) => [ ["paragraph", { text: `Showcase ${what}: the short description that appears on its card.` }], ["paragraph", { text: "A second card paragraph, to check how two read." }], @@ -259,7 +262,7 @@ tx(db, () => { insert("region_areas", { region_id: REGION, area_code: "PA", share: 0.5, edge: "top", note: "western half" }); insert("region_areas", { region_id: REGION, area_code: "OH", share: 1 }); links("organization", REGION, standardLinks("Showcase Region")); - blocks("organization", REGION, "card", cardText("region")); + blocks("organization", REGION, "both", cardText("region")); blocks("organization", REGION, "body", pageBody("region")); insert("organizations", { @@ -279,7 +282,7 @@ tx(db, () => { insert("groups", { id: GROUP, region_id: REGION, meets: "2nd Sundays, 6:00pm", started: "Since 2021" }); ["in-person", "online"].forEach((tag_id, i) => insert("organization_tags", { org_id: GROUP, tag_id, sort_order: i })); links("organization", GROUP, standardLinks("Showcase Group")); - blocks("organization", GROUP, "card", cardText("group")); + blocks("organization", GROUP, "both", cardText("group")); blocks("organization", GROUP, "body", pageBody("group")); /* ── People ── */ @@ -315,7 +318,7 @@ tx(db, () => { { kind: "website", label: "Website", url: "https://example.org/person" }, { kind: "action", label: "Book a call", url: "https://example.org/call" }, ]); - blocks("person", PERSON, "card", cardText("person")); + blocks("person", PERSON, "both", cardText("person")); blocks("person", PERSON, "body", pageBody("person")); MEMBERS.forEach((id, i) => @@ -346,7 +349,7 @@ tx(db, () => { sort_order: 99, }); links("team", TEAM, [{ kind: "action", label: "Join the team", url: "https://example.org/join" }]); - blocks("team", TEAM, "card", cardText("team")); + blocks("team", TEAM, "both", cardText("team")); blocks("team", TEAM, "body", pageBody("team")); insert("affiliations", { person_id: PERSON, org_id: REGION, team_id: TEAM, title: "Showcase Team Lead", role: "lead", is_owner: 1, started_on: "2023-01-01", is_public: 1, sort_order: 0 }); @@ -392,7 +395,7 @@ tx(db, () => { { kind: "action", platform: "discord", label: "Event Discord", url: "https://discord.com/invite/example" }, { kind: "social", platform: "instagram", label: "@showcaseretreat", url: "https://instagram.com/showcaseretreat" }, ]); - blocks("event", EVENT, "card", cardText("event")); + blocks("event", EVENT, "both", cardText("event")); blocks("event", EVENT, "body", [...pageBody("event"), ["heading", { text: "Schedule" }], SCHEDULE]); insert("events", { diff --git a/server/src/shape.js b/server/src/shape.js index 1adcb29..e7d617a 100644 --- a/server/src/shape.js +++ b/server/src/shape.js @@ -53,7 +53,8 @@ export function loadLinks(db, ownerKind, ids) { } /* ── Blocks ──────────────────────────────────────────────────── - Map of owner_id → blocks for one slot, items attached. + Map of owner_id → blocks for one slot, items attached. A + "both" block (071) is in the card's and the body's. Two queries: the blocks, then every item belonging to them. Blocks with no children come back with an empty items array @@ -68,7 +69,7 @@ export function loadBlocks(db, ownerKind, ids, slot = "body") { .prepare( `SELECT id, owner_id, type, text, media, href, alt, cite, captions, team_id FROM content_blocks - WHERE owner_kind = ? AND slot = ? AND owner_id IN (${placeholders(ids.length)}) + WHERE owner_kind = ? AND slot IN (?, 'both') AND owner_id IN (${placeholders(ids.length)}) ORDER BY owner_id, sort_order`, ) .all(ownerKind, slot, ...ids); @@ -145,7 +146,8 @@ export function loadBlocks(db, ownerKind, ids, slot = "body") { The card slot is paragraphs by convention, so it collapses to an array of strings, desc_a and desc_b become description[0] and description[1]. A non-paragraph block in the card slot is - ignored here; put it in the body slot instead. + ignored here. Only cards show it: a record's page draws its + body blocks, "both" ones among them. ───────────────────────────────────────────────────────────── */ export function paragraphs(blocks = []) { diff --git a/src/lib/adminSchema/shared.ts b/src/lib/adminSchema/shared.ts index e566bb9..8eb5393 100644 --- a/src/lib/adminSchema/shared.ts +++ b/src/lib/adminSchema/shared.ts @@ -363,8 +363,10 @@ export const blocksChild = { widget: "select", options: [ ["body", "The page"], - ["card", "The card (paragraphs only)"], + ["card", "The card only (paragraphs only)"], + ["both", "The card and the page"], ], + help: "The card is the record's card in lists and carousels, and takes paragraphs only.", }, { path: "type", diff --git a/src/pages/EventDetail.tsx b/src/pages/EventDetail.tsx index 586078e..d237f7b 100644 --- a/src/pages/EventDetail.tsx +++ b/src/pages/EventDetail.tsx @@ -108,12 +108,6 @@ export default function EventDetail() { /> )} - {event.description.map((paragraph, index) => ( -

- {paragraph} -

- ))} -
diff --git a/src/pages/OrganizationDetail.tsx b/src/pages/OrganizationDetail.tsx index eace611..b081bed 100644 --- a/src/pages/OrganizationDetail.tsx +++ b/src/pages/OrganizationDetail.tsx @@ -84,12 +84,6 @@ export default function OrganizationDetail() {
- {org.description.map((paragraph, index) => ( -

- {paragraph} -

- ))} -
diff --git a/src/pages/PersonDetail.tsx b/src/pages/PersonDetail.tsx index a9fa9a5..8ab455a 100644 --- a/src/pages/PersonDetail.tsx +++ b/src/pages/PersonDetail.tsx @@ -85,7 +85,7 @@ export default function PersonDetail() {
- {[...person.bio, ...person.description].map((paragraph, index) => ( + {person.bio.map((paragraph, index) => (

{paragraph}

diff --git a/src/pages/TeamDetail.tsx b/src/pages/TeamDetail.tsx index 3a8659a..f1e1087 100644 --- a/src/pages/TeamDetail.tsx +++ b/src/pages/TeamDetail.tsx @@ -44,7 +44,7 @@ export default function TeamDetail() { const accent = team.color || BRAND const hasAbout = - team.description.length > 0 || team.blocks.length > 0 || team.links.length > 0 + team.blocks.length > 0 || team.links.length > 0 const sections: any[] = [] @@ -57,12 +57,6 @@ export default function TeamDetail() {
- {team.description.map((paragraph, index) => ( -

- {paragraph} -

- ))} -