Improve content blocks: new types, formatting, and a better editor

Blocks (migration 032): video (click to play, sharing the featured
cards' player), button and callout types; quotes get an attribution
and images alt text separate from the caption. Paragraphs, callouts,
quotes and list items take **bold**, *italic*, [text](url), line
breaks and blank-line paragraphs, parsed into elements (never HTML)
with only safe link schemes. A list item's detail no longer uses an
em-dash.

Editor: each block type shows only its fields, with a named type and
a description, and every open block previews itself with the site's
renderer. Any repeater row can now be duplicated or have a new row
inserted below it; nested collections take `when`, and help text can
depend on the row.

src/seed-showcase.js writes a local test post using every block type
and option. It refuses the production database.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-27 16:50:21 -05:00
parent c62dc84add
commit c5f12c769f
13 changed files with 723 additions and 169 deletions

109
server/src/seed-showcase.js Normal file
View file

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