Add a Featured Content section to the front page

Front page → Featured cards (migration 030) holds cards of three
kinds: a record on the site, whose title, picture and link fill in
from the record; a link, with a Fetch preview button that reads the
page's title, description and preview image into the media library;
and a video, drawn as a thumbnail that loads the player when pressed.
A 'featured' section draws them.

The cards are shared: featured_cards is owned polymorphically and
FeaturedCards.tsx draws them, ready for the Community blog. Deleting
a record removes its cards; an unpublished record's card is hidden.

The preview fetch only goes to public http(s) addresses on standard
ports, pinned to the vetted IP, with each redirect checked again.

Along the way: repeater fields can show by another field's value (a
hidden one is cleared), a CHECK named as a sentence is shown as the
error, and the timeline's record list is now record_refs for both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-27 15:56:29 -05:00
parent 960c854611
commit d4f65d93b4
17 changed files with 1140 additions and 50 deletions

View file

@ -166,4 +166,114 @@ export function shapeSeries(row) {
};
}
/* ── Featured cards ────────────────────────────────────────────
One owner's cards (the front page's, today), in order, with
each record card filled in from its record. Shared so the
Community blog's cards will come out the same shape.
A record card's own title, blurb and image override the
record's. One query per kind that is actually referenced, so a
row of six cards is at most six queries.
`image` is { file, kind }, like the timeline's logo: the record
tables keep bare filenames in different public/ directories,
and logoForKind in media.ts knows which is which. The kinds are
the ref kinds, plus 'event-background' and 'featured' (the
card's own image). An unpublished
record's card is dropped; an unlisted one's stays, since
featuring it is attaching it by hand.
───────────────────────────────────────────────────────────── */
const FEATURED_REFS = {
event: {
sql: (marks) =>
`SELECT id, title, tagline AS blurb, date_label AS eyebrow,
card_image, event_logo
FROM events WHERE is_published = 1 AND id IN (${marks})`,
image: (row) =>
row.card_image
? { file: row.card_image, kind: "event-background" }
: row.event_logo
? { file: row.event_logo, kind: "event" }
: null,
},
organization: {
sql: (marks) =>
`SELECT id, name AS title, tagline AS blurb, kind AS org_kind, logo
FROM organizations WHERE is_published = 1 AND id IN (${marks})`,
image: (row) => (row.logo ? { file: row.logo, kind: "organization" } : null),
},
person: {
sql: (marks) =>
`SELECT id, display_name AS title, tagline AS blurb, photo
FROM people WHERE is_published = 1 AND id IN (${marks})`,
image: (row) => (row.photo ? { file: row.photo, kind: "person" } : null),
},
team: {
sql: (marks) =>
`SELECT t.id, t.name AS title, t.tagline AS blurb, t.logo
FROM teams t
JOIN organizations o ON o.id = t.org_id AND o.is_published = 1
WHERE t.is_published = 1 AND t.id IN (${marks})`,
image: (row) => (row.logo ? { file: row.logo, kind: "team" } : null),
},
award: {
sql: (marks) =>
`SELECT id, name AS title, description AS blurb, logo
FROM awards WHERE is_published = 1 AND id IN (${marks})`,
image: (row) => (row.logo ? { file: row.logo, kind: "award" } : null),
},
};
export function loadFeaturedCards(db, ownerKind, ownerId) {
const rows = db
.prepare(
`SELECT * FROM featured_cards
WHERE owner_kind = ? AND owner_id = ?
ORDER BY sort_order, id`,
)
.all(ownerKind, ownerId);
// kind → id → record row
const records = new Map();
for (const [kind, spec] of Object.entries(FEATURED_REFS)) {
const ids = [
...new Set(rows.filter((r) => r.kind === "record" && r.ref_kind === kind).map((r) => r.ref_id)),
];
if (ids.length === 0) continue;
const found = db.prepare(spec.sql(placeholders(ids.length))).all(...ids);
records.set(kind, new Map(found.map((r) => [r.id, r])));
}
const own = (row) => (row.image ? { file: row.image, kind: "featured" } : null);
const cards = [];
for (const row of rows) {
if (row.kind === "record") {
const record = records.get(row.ref_kind)?.get(row.ref_id);
if (!record) continue; // unpublished, or its organization is
cards.push({
kind: "record",
ref: { kind: row.ref_kind, id: row.ref_id, org_kind: record.org_kind ?? null },
url: null,
eyebrow: row.eyebrow ?? record.eyebrow ?? null,
title: row.title ?? record.title,
blurb: row.blurb ?? record.blurb ?? null,
image: own(row) ?? FEATURED_REFS[row.ref_kind].image(record),
});
} else {
cards.push({
kind: row.kind, // 'link' | 'video'
ref: null,
url: row.url,
eyebrow: row.eyebrow,
title: row.title,
blurb: row.blurb,
image: own(row),
});
}
}
return cards;
}
export { asBool };