diff --git a/CLAUDE.md b/CLAUDE.md
index 977fbfb..7b23b88 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -22,6 +22,7 @@ Backend (`server/`, Node >= 22). The server reads `HOST` (default `127.0.0.1`),
- `DB_PATH=./dev.db pnpm dev`: run with `node --watch`
- `DB_PATH=./dev.db pnpm migrate`: apply migrations without starting the server
- `DB_PATH=./dev.db node src/admin-cli.js add|list|passwd|role|disable|enable ...`: the only way accounts are created
+- `DB_PATH=./dev.db node src/seed-showcase.js`: writes /blog/content-block-showcase, every content block type in one page, for checking `ContentBlocks.tsx`. Local only; refuses /var/lib/ngu.
In dev, Vite proxies `/api` to the target set in `vite.config.ts`, so the API must listen on that port.
diff --git a/docs/updating-data-in-code.md b/docs/updating-data-in-code.md
index 11b8d6c..8c09e41 100644
--- a/docs/updating-data-in-code.md
+++ b/docs/updating-data-in-code.md
@@ -174,8 +174,8 @@ also in `admin-schema.js` and a CHECK):
| People → Affiliations → Role; Teams → Members → Role | lead, board, staff, volunteer, member | no | `ROLE_LABEL` in `src/pages/PersonDetail.tsx` |
| Links → Kind (on organizations, events, people, teams) | action, social, website, email | no | `splitLinks` in `server/src/shape.js` |
| Links → Platform | instagram, facebook, discord, youtube, tiktok, x, substack, spotify, linkedin | **yes**, `PLATFORMS` | `PlatformIcon.tsx` draws the icon on the button. **No CHECK and no `enumeration`**: the column is plain text, so adding one is an entry in `PLATFORMS` (`src/lib/platforms.ts`) and its icon in `src/components/PlatformIcon.tsx`, no migration. |
-| Content blocks → Slot | card, body | no | `ContentBlocks.tsx` |
-| Content blocks → Type | heading, subheading, paragraph, list, links, quote, image, divider | no | `ContentBlocks.tsx` (one renderer per type) |
+| Content blocks → Shown in (slot) | card, body | **yes** | `paragraphs()` in `server/src/shape.js` (card), `ContentBlocks.tsx` (body) |
+| Content blocks → Type | heading, subheading, paragraph, list, links, quote, image, divider, video, button, callout | **yes**, `BLOCK_TYPES` (with each type's description) | `ContentBlocks.tsx` (one renderer per type). Which fields each type shows is `when` on the fields in `blocksChild` (`src/lib/adminSchema.ts`). |
| Timeline → Kind (+ list filter) | milestone, event, organization, award, people | no | `KIND_NAMES` in `src/pages/sections/history/TimelineEntry.tsx` |
| Timeline → Points at (+ list filter) | event, organization, award, person, team | no | `refHref` in `src/lib/hrefs.ts` |
| Timeline → Precision (and on events/orgs) | year, month, day | no | the history page's grouping |
diff --git a/server/src/admin-schema.js b/server/src/admin-schema.js
index a9c6828..fafa531 100644
--- a/server/src/admin-schema.js
+++ b/server/src/admin-schema.js
@@ -176,12 +176,17 @@ const blocksChild = (ownerKind) => ({
"quote",
"image",
"divider",
+ "video",
+ "button",
+ "callout",
],
{ required: true },
),
text("text"),
text("media"),
text("href"),
+ text("alt"),
+ text("cite"),
],
children: [
{
diff --git a/server/src/migrations/032_content_block_types.sql b/server/src/migrations/032_content_block_types.sql
new file mode 100644
index 0000000..ccb59d5
--- /dev/null
+++ b/server/src/migrations/032_content_block_types.sql
@@ -0,0 +1,80 @@
+-- ═══════════════════════════════════════════════════════════════
+-- 032 CONTENT BLOCKS: VIDEO, BUTTON, CALLOUT, ALT TEXT, ATTRIBUTION
+--
+-- Three new block types, and two columns for types that had to
+-- borrow one:
+--
+-- video href is the link (YouTube, Vimeo, Facebook) or a
+-- video file; text is the caption; media an optional
+-- still. Drawn click-to-play, like a featured card.
+-- button text is the label, href where it goes.
+-- callout text in a tinted box, for a note or announcement.
+--
+-- alt an image's alt text. text stays its caption: a
+-- caption describes the moment, alt describes the
+-- picture to someone who can't see it.
+-- cite who a quote is by.
+--
+-- The type list is a CHECK, so the table is rebuilt, the same way
+-- 031 did (see its header): legacy_alter_table around the rename,
+-- because the *_cleanup triggers on other tables name it, then the
+-- index and the owner trigger again.
+--
+-- PRAGMA user_version; -- reads 31 before this file
+-- ═══════════════════════════════════════════════════════════════
+
+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')),
+ 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')),
+ text TEXT,
+ media TEXT,
+ href TEXT,
+ alt TEXT,
+ cite TEXT
+) STRICT;
+
+INSERT INTO content_blocks_new (id, owner_kind, owner_id, slot, sort_order, type, text, media, href)
+SELECT id, owner_kind, owner_id, slot, sort_order, type, text, media, href
+ 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 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')
+ END;
+END;
diff --git a/server/src/seed-showcase.js b/server/src/seed-showcase.js
new file mode 100644
index 0000000..36c3e28
--- /dev/null
+++ b/server/src/seed-showcase.js
@@ -0,0 +1,109 @@
+/* ═══════════════════════════════════════════════════════════════
+ CONTENT BLOCK SHOWCASE: a local test page
+
+ DB_PATH=./dev.db node src/seed-showcase.js
+
+ Writes one blog post, /blog/content-block-showcase, that uses
+ every content block type and every option each one has, so a
+ change to ContentBlocks.tsx can be checked against all of them
+ in one place. Run it again to put the post back as written here;
+ it replaces the post and its blocks, and nothing else.
+
+ The post is published but unlisted: its page works, and it stays
+ out of the Community page's "newest". It is test content, so this
+ refuses the production database (anything under /var/lib/ngu).
+
+ Image blocks point at /uploads/showcase.jpg. Upload any photo in
+ Admin → Media and paste its path into those blocks, or leave them
+ to check how a missing image degrades.
+ ═══════════════════════════════════════════════════════════════ */
+
+import { openDatabase, migrate, tx } from "./db.js";
+
+const DB_PATH = process.env.DB_PATH ?? "./ngu.db";
+
+// Matched anywhere in the path, not only at its start, so a shell
+// that rewrites /var/lib/... into its own form (Git Bash) is caught too.
+if (/(^|\/)var\/lib\/ngu(\/|$)/.test(DB_PATH.replace(/\\/g, "/"))) {
+ console.error("✗ This is test content. It won't write to the production database.");
+ process.exit(1);
+}
+
+const POST_ID = "content-block-showcase";
+const IMAGE = "/uploads/showcase.jpg";
+
+/* [type, fields, items?] in page order. */
+const BLOCKS = [
+ ["paragraph", { text: "Every content block type, top to bottom, with each of its options. Use it to check the page after changing how blocks draw." }],
+ ["heading", { text: "Heading" }],
+ ["subheading", { text: "Subheading" }],
+ ["paragraph", { text: "A paragraph with **bold**, *italic*, a [link to the history page](/history) and an [outside link](https://example.org).\nThis line follows a single line break.\n\nA blank line starts a second paragraph in the same block." }],
+ ["paragraph", { text: "A whole paragraph that is a link, set with the block's Link field.", href: "/community" }],
+ ["callout", { text: "**A callout.** For a note or an announcement. It takes the same formatting as a paragraph, including [links](/give)." }],
+ ["quote", { text: "Unity is not a feeling we wait for. It is a practice we keep.", cite: "A retreat speaker" }],
+ ["quote", { text: "A quote with no attribution." }],
+ ["divider", {}],
+ ["subheading", { text: "Lists" }],
+ ["list", {}, [
+ { text: "A plain item" },
+ { text: "An item with a detail", detail: "the detail" },
+ { text: "A linked item", url: "/retreats" },
+ { text: "A linked item with a detail", url: "https://example.org", detail: "opens in a new tab" },
+ ]],
+ ["links", {}, [
+ { text: "Retreats", url: "/retreats" },
+ { text: "Community", url: "/community" },
+ { text: "An outside site", url: "https://example.org" },
+ ]],
+ ["button", { text: "A button", href: "/give" }],
+ ["divider", {}],
+ ["subheading", { text: "Images" }],
+ ["image", { media: IMAGE, alt: "Describe the picture here", text: "An image with a caption and alt text" }],
+ ["image", { media: IMAGE, alt: "The same picture, linked", href: "/history" }],
+ ["subheading", { text: "Video" }],
+ ["video", { href: "https://www.youtube.com/watch?v=dQw4w9WgXcQ", text: "A YouTube video, with its own thumbnail" }],
+ ["video", { href: "https://vimeo.com/76979871", media: IMAGE, text: "A Vimeo video with an uploaded still" }],
+];
+
+const db = await openDatabase(DB_PATH);
+migrate(db, { log: () => {} });
+
+tx(db, () => {
+ db.prepare(`DELETE FROM blog_posts WHERE id = ?`).run(POST_ID); // takes its blocks (blog_posts_cleanup)
+
+ db.prepare(
+ `INSERT INTO blog_posts (id, title, excerpt, published_on, tags, guest_author, is_published, is_listed)
+ VALUES (?, ?, ?, date('now'), ?, ?, 1, 0)`,
+ ).run(
+ POST_ID,
+ "Content block showcase",
+ "Every block type in one place, for checking the page.",
+ "Test, Showcase",
+ "The showcase script",
+ );
+
+ const block = db.prepare(
+ `INSERT INTO content_blocks (owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite)
+ VALUES ('blog_post', ?, 'body', ?, ?, ?, ?, ?, ?, ?)`,
+ );
+ const item = db.prepare(
+ `INSERT INTO content_block_items (block_id, sort_order, text, detail, url) VALUES (?, ?, ?, ?, ?)`,
+ );
+
+ BLOCKS.forEach(([type, f, items = []], order) => {
+ const { lastInsertRowid } = block.run(
+ POST_ID,
+ order,
+ type,
+ f.text ?? null,
+ f.media ?? null,
+ f.href ?? null,
+ f.alt ?? null,
+ f.cite ?? null,
+ );
+ items.forEach((it, i) => item.run(lastInsertRowid, i, it.text, it.detail ?? null, it.url ?? null));
+ });
+});
+
+db.close();
+console.log(`✓ ${BLOCKS.length} blocks written. Open /blog/${POST_ID}`);
diff --git a/server/src/shape.js b/server/src/shape.js
index b8dbde4..5973156 100644
--- a/server/src/shape.js
+++ b/server/src/shape.js
@@ -66,7 +66,7 @@ export function loadBlocks(db, ownerKind, ids, slot = "body") {
const blockRows = db
.prepare(
- `SELECT id, owner_id, type, text, media, href
+ `SELECT id, owner_id, type, text, media, href, alt, cite
FROM content_blocks
WHERE owner_kind = ? AND slot = ? AND owner_id IN (${placeholders(ids.length)})
ORDER BY owner_id, sort_order`,
@@ -83,6 +83,8 @@ export function loadBlocks(db, ownerKind, ids, slot = "body") {
text: row.text,
media: row.media,
href: row.href,
+ alt: row.alt,
+ cite: row.cite,
items: [],
};
byId.set(row.id, block);
diff --git a/src/components/ContentBlocks.tsx b/src/components/ContentBlocks.tsx
index fab186c..d94e4b9 100644
--- a/src/components/ContentBlocks.tsx
+++ b/src/components/ContentBlocks.tsx
@@ -1,55 +1,41 @@
/* ═══════════════════════════════════════════════════════════════
CONTENT BLOCKS
- Renders the `body` slot of content_blocks. Events, organizations
- and teams all own blocks and all render them the same way, so
- this is written once and tinted by the caller's accent.
+ Renders the `body` slot of content_blocks. Events, organizations,
+ teams, people and blog posts all own blocks and all render them
+ the same way, so this is written once and tinted by the caller's
+ accent. The admin's block editor previews each block through this
+ same component.
- ⚠ Assumes shape.js's loadBlocks returns rows carrying `type`,
- `text`, `media`, `href` and an `items` array. If the field names
- differ, this is the only file to fix — nothing else reads a
- block.
+ What each type reads (see 032_content_block_types.sql):
+
+ heading, subheading text
+ paragraph text (formatted), href makes it all a link
+ callout text (formatted), in a tinted box
+ quote text (formatted), cite is who said it
+ list items: text, detail, url
+ links items with a url, as outlined buttons
+ button text is the label, href where it goes
+ image media, alt, text is the caption, href
+ video href is the video, media a still, text
+ the caption; click to play
+ divider nothing
+
+ "Formatted" is InlineText.tsx: **bold**, *italic*, [text](url),
+ line breaks, and a blank line for a new paragraph.
An unknown `type` renders its text as a paragraph rather than
disappearing. A block somebody typed into the admin should be
visible even if the renderer hasn't caught up with it.
═══════════════════════════════════════════════════════════════ */
-import { Link } from 'react-router-dom'
import { blockMedia } from '../lib/media.ts'
import type { ContentBlock } from '../lib/useContent.ts'
+import { Anchor, Inline, Paragraphs } from './InlineText.tsx'
+import VideoPlayer from './VideoPlayer.tsx'
const BODY = '#4a6b72'
-/** External if it has a scheme or starts with //; otherwise it's
- * one of our own routes and should go through the router. */
-const isExternal = (url: string) => /^([a-z][a-z0-9+.-]*:|\/\/)/i.test(url)
-
-function Anchor({
- href,
- children,
- className,
- style,
-}: {
- href: string
- children: React.ReactNode
- className?: string
- style?: React.CSSProperties
-}) {
- if (isExternal(href)) {
- return (
-
- {children}
-
- )
- }
- return (
-
- {children}
-
- )
-}
-
export default function ContentBlocks({
blocks,
accent = '#138ba0',
@@ -70,6 +56,15 @@ export default function ContentBlocks({
)
}
+function Caption({ text }: { text?: string | null }) {
+ if (!text) return null
+ return (
+
++++ {block.cite && ( ++ + {block.cite} + + )} + + ) + + case 'callout': + if (!text) return null + return ( +
- {block.href ? (
-
per blank-line-separated part. `Inline` is for text that sits
+ inside something else (a quote, a list item).
+ ═══════════════════════════════════════════════════════════════ */
+
+import { Fragment, type CSSProperties, type ReactNode } from 'react'
+import { Link } from 'react-router-dom'
+
+const TOKEN = /\*\*(.+?)\*\*|\*(.+?)\*|\[([^\]]+)\]\(([^)\s]+)\)/g
+const SAFE_URL = /^(\/(?!\/)|#|https?:\/\/|mailto:|tel:)/i
+
+/** External if it has a scheme or starts with //; otherwise it's
+ * one of our own routes and goes through the router. */
+export const isExternalUrl = (url: string) => /^([a-z][a-z0-9+.-]*:|\/\/)/i.test(url)
+
+export function Anchor({
+ href,
+ children,
+ className,
+ style,
+}: {
+ href: string
+ children: ReactNode
+ className?: string
+ style?: CSSProperties
+}) {
+ if (isExternalUrl(href)) {
+ const app = /^(mailto|tel):/i.test(href)
+ return (
+
+ {children}
+
+ )
+ }
+ if (href.startsWith('#')) {
+ return (
+
+ {children}
+
+ )
+ }
+ return (
+
+ {children}
+
+ )
+}
+
+function line(text: string, accent: string, key: string): ReactNode[] {
+ const out: ReactNode[] = []
+ let last = 0
+ let n = 0
+ for (const match of text.matchAll(TOKEN)) {
+ const at = match.index ?? 0
+ if (at > last) out.push(text.slice(last, at))
+ const [whole, bold, italic, label, url] = match
+ const k = `${key}-${n++}`
+ if (bold != null) out.push({bold})
+ else if (italic != null) out.push({italic})
+ else if (label != null && SAFE_URL.test(url)) {
+ out.push(
+
}
+ {line(part, accent, `l${i}`)}
+
per part separated by a blank line. */ +export function Paragraphs({ + text, + accent, + className, + style, +}: { + text?: string | null + accent: string + className?: string + style?: CSSProperties +}) { + const parts = (text ?? '') + .split(/\n\s*\n/) + .map((part) => part.trim()) + .filter(Boolean) + return ( + <> + {parts.map((part, i) => ( +
+