Add link card blocks to post bodies

A "cards" content block: each item is a card with a picture, title and
description that links somewhere, like a link shared in a chat. Fetch
preview fills the card from the link. Migration 044 (not deployed yet)
now allows both table and cards.

Also fixes hidden-field clearing when two fields share a path, and adds
table and card blocks to the showcase post.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-29 15:40:24 -05:00
parent 5dceeb5860
commit 4e9b4e3329
8 changed files with 123 additions and 18 deletions

View file

@ -23,6 +23,9 @@
text, detail, url, location, person, and
a fold-out of description, media, map);
text is an optional intro. ScheduleBlock
table text: a row per line, cells split by |
cards items as link cards: text the title,
detail, url, media the picture
divider nothing
"Formatted" is InlineText.tsx: **bold**, *italic*, [text](url),
@ -34,12 +37,14 @@
═══════════════════════════════════════════════════════════════ */
import { mediaUrl } from '../lib/media.ts'
import type { ContentBlock } from '../lib/useContent.ts'
import { Anchor, Inline, Paragraphs } from './InlineText.tsx'
import type { ContentBlock, ContentBlockItem } from '../lib/useContent.ts'
import { Anchor, Inline, Paragraphs, isExternalUrl } from './InlineText.tsx'
import VideoPlayer from './VideoPlayer.tsx'
import ScheduleBlock from './ScheduleBlock.tsx'
import { accentText, BRAND } from '../lib/color.ts'
import { headingAnchors } from '../lib/contents.ts'
import { SITE_NAME } from '../lib/site.ts'
import { useSmallImage } from '../lib/useSmallImage.ts'
const BODY = 'var(--color-muted)'
@ -66,6 +71,37 @@ export default function ContentBlocks({
)
}
/* One link card: the whole card is the link. The site's name above
the title says where it goes (the host for an outside link). */
function LinkCard({ item }: { item: ContentBlockItem }) {
const url = item.url ?? ''
const img = useSmallImage(mediaUrl(item.media))
const where = isExternalUrl(url)
? (() => {
try {
return new URL(url).hostname.replace(/^www\./, '')
} catch {
return url
}
})()
: SITE_NAME
return (
<Anchor
href={url}
className="group flex h-full flex-col overflow-hidden rounded-2xl border border-brand/15 bg-surface shadow-sm transition-shadow hover:shadow-lg"
>
{!img.failed && (
<img src={img.src} alt="" loading="lazy" onError={img.onError} className="aspect-video w-full object-cover" />
)}
<span className="flex flex-1 flex-col gap-1 p-5">
<span className="text-xs font-semibold text-muted">{where}</span>
<span className="font-display text-lg font-bold leading-snug text-ink group-hover:text-link">{item.text}</span>
{item.detail && <span className="line-clamp-3 text-sm text-body">{item.detail}</span>}
</span>
</Anchor>
)
}
/* A table block's text as rows of cells: one row per line, cells
split by "|" (a literal bar is "\|"), blank lines skipped. A
leading and trailing bar, as in Markdown, is allowed. */
@ -182,6 +218,20 @@ function Block({ block, accent, anchor }: { block: ContentBlock; accent: string;
</figure>
)
case 'cards': {
const cards = (block.items ?? []).filter((item) => item.url && item.text)
if (cards.length === 0) return null
return (
<ul className={cards.length === 1 ? 'max-w-xl' : 'grid gap-4 sm:grid-cols-2'}>
{cards.map((item, i) => (
<li key={i}>
<LinkCard item={item} />
</li>
))}
</ul>
)
}
case 'table': {
const rows = tableRows(text)
if (rows.length === 0) return null