Content blocks: Shown in the page, the card only, or both (migration 071)

A card block also showed on the record's page (the pages printed the
card's paragraphs above the body), which the editor didn't say. Shown
in now offers The page, The card only, and The card and the page.
Every existing card block becomes both, so nothing on the site moves;
the pages no longer print card paragraphs, and a both block comes
with the page's blocks, in its place in the list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-10-06 05:27:33 -05:00
parent b55b088e16
commit 8d6bb8c2b8
10 changed files with 103 additions and 32 deletions

View file

@ -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",
[

View file

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

View file

@ -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`,

View file

@ -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", {

View file

@ -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 = []) {

View file

@ -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",

View file

@ -108,12 +108,6 @@ export default function EventDetail() {
/>
)}
{event.description.map((paragraph, index) => (
<p key={index} className="leading-relaxed max-w-3xl" style={{ color: BODY }}>
{paragraph}
</p>
))}
<div className="max-w-3xl">
<ContentBlocks blocks={event.blocks} accent={accent} presentAt={`/events/${encodeURIComponent(event.id)}/present`} />
</div>

View file

@ -84,12 +84,6 @@ export default function OrganizationDetail() {
<div className="max-w-6xl mx-auto px-6 space-y-8">
<Facts org={org} accent={accent} />
{org.description.map((paragraph, index) => (
<p key={index} className="leading-relaxed max-w-3xl" style={{ color: BODY }}>
{paragraph}
</p>
))}
<div className="max-w-3xl">
<ContentBlocks blocks={org.blocks} accent={accent} />
</div>

View file

@ -85,7 +85,7 @@ export default function PersonDetail() {
<div className="max-w-6xl mx-auto px-6 space-y-8">
<Facts person={person} accent={accent} />
{[...person.bio, ...person.description].map((paragraph, index) => (
{person.bio.map((paragraph, index) => (
<p key={index} className="leading-relaxed max-w-3xl" style={{ color: BODY }}>
{paragraph}
</p>

View file

@ -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() {
<div className="max-w-6xl mx-auto px-6 space-y-8">
<Facts orgId={team.org.id} orgKind={team.org.kind} orgName={team.org.name} accent={accent} />
{team.description.map((paragraph, index) => (
<p key={index} className="leading-relaxed max-w-3xl" style={{ color: BODY }}>
{paragraph}
</p>
))}
<div className="max-w-3xl">
<ContentBlocks blocks={team.blocks} accent={accent} />
</div>