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:
parent
960c854611
commit
d4f65d93b4
17 changed files with 1140 additions and 50 deletions
|
|
@ -22,6 +22,7 @@ import {
|
|||
blockMedia,
|
||||
eventBackground,
|
||||
eventLogo,
|
||||
featuredImage,
|
||||
heroPhoto,
|
||||
orgLogo,
|
||||
personPhoto,
|
||||
|
|
@ -148,6 +149,76 @@ const timelineDetailGroup = (noun) => ({
|
|||
fields: timelineExtensionFields(noun),
|
||||
});
|
||||
|
||||
/* Featured cards (030_featured_cards.sql), a front page collection
|
||||
now and the Community blog's next, so it's written once. Fields
|
||||
show by kind; switching kind clears the ones that stop applying
|
||||
(see `when` in fields.tsx). */
|
||||
const FEATURED_KINDS = [
|
||||
["record", "A page on this site (event, org, person…)"],
|
||||
["link", "A link (article, post, any URL)"],
|
||||
["video", "A video (YouTube, Vimeo, Facebook)"],
|
||||
];
|
||||
|
||||
const featuredCardsChild = {
|
||||
key: "featured_cards",
|
||||
label: "Featured cards",
|
||||
note: "Shown by the Featured Content section, in this order.",
|
||||
addLabel: "Add card",
|
||||
title: (row, options) =>
|
||||
row.title ||
|
||||
options?.record_refs?.find((o) => o.kind === row.ref_kind && o.id === row.ref_id)?.label ||
|
||||
row.url ||
|
||||
"New card",
|
||||
blank: { kind: "", ref_kind: "", ref_id: "", url: "", title: "" },
|
||||
fields: [
|
||||
{
|
||||
path: "kind",
|
||||
label: "Card type",
|
||||
widget: "select",
|
||||
options: FEATURED_KINDS,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
path: "ref_kind",
|
||||
label: "Record type",
|
||||
widget: "select",
|
||||
options: ["event", "organization", "person", "team", "award"],
|
||||
required: true,
|
||||
when: { path: "kind", value: "record" },
|
||||
},
|
||||
{
|
||||
path: "ref_id",
|
||||
label: "Record",
|
||||
widget: "select",
|
||||
optionsFrom: "record_refs",
|
||||
filterBy: (option, row) => option.kind === row.ref_kind,
|
||||
required: true,
|
||||
when: { path: "kind", value: "record" },
|
||||
help: "Its title, picture and link fill the card. Anything typed below overrides them.",
|
||||
},
|
||||
{
|
||||
path: "url",
|
||||
label: "URL",
|
||||
widget: "linkPreview",
|
||||
previewWhen: { path: "kind", value: "link" },
|
||||
required: true,
|
||||
full: true,
|
||||
when: { path: "kind", value: ["link", "video"] },
|
||||
},
|
||||
{ path: "eyebrow", label: "Label", help: "Small text above the title, eg. Article, Watch" },
|
||||
{ path: "title", label: "Title" },
|
||||
{ path: "blurb", label: "Blurb", widget: "textarea", full: true },
|
||||
{
|
||||
path: "image",
|
||||
label: "Image",
|
||||
widget: "image",
|
||||
resolve: featuredImage,
|
||||
full: true,
|
||||
help: "Default: the record's own picture, or for a YouTube video, its thumbnail.",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
/* The two collections every entity carries. */
|
||||
const linksChild = {
|
||||
key: "links",
|
||||
|
|
@ -915,7 +986,7 @@ const timeline = {
|
|||
path: "ref_id",
|
||||
label: "Record",
|
||||
widget: "select",
|
||||
optionsFrom: "timeline_refs",
|
||||
optionsFrom: "record_refs",
|
||||
blankLabel: "Default: none",
|
||||
// One flat list of every referenceable row, narrowed to the
|
||||
// kind chosen above. Five dropdowns of which four are always
|
||||
|
|
@ -1015,6 +1086,7 @@ const FRONT_PAGE_SECTIONS = [
|
|||
["stats", "Stats"],
|
||||
["timeline", "Featured Timeline"],
|
||||
["connect", "Connect Nav"],
|
||||
["featured", "Featured Content"],
|
||||
];
|
||||
|
||||
const STAT_SOURCES = [
|
||||
|
|
@ -1196,6 +1268,7 @@ const frontPage = {
|
|||
{ path: "note", label: "Note", full: true },
|
||||
],
|
||||
},
|
||||
featuredCardsChild,
|
||||
{
|
||||
key: "paths",
|
||||
label: "Connect Nav",
|
||||
|
|
|
|||
|
|
@ -100,3 +100,39 @@ export function videoSource(raw?: string | null): VideoSource | null {
|
|||
const src = embedUrl(value, false)
|
||||
return src ? { kind: 'embed', src } : null
|
||||
}
|
||||
|
||||
/* ── Click to play ─────────────────────────────────────────────
|
||||
A featured card shows a still and swaps in the player when it's
|
||||
pressed, so the page loads no iframes until someone asks for
|
||||
one. The press is the user gesture browsers want before playing
|
||||
with sound, so the player can start at once, unmuted.
|
||||
───────────────────────────────────────────────────────────── */
|
||||
|
||||
/** The same source, set to start playing as soon as it loads. */
|
||||
export function playingSource(source: VideoSource): VideoSource {
|
||||
if (source.kind === 'file') return source
|
||||
let url: URL
|
||||
try {
|
||||
url = new URL(source.src)
|
||||
} catch {
|
||||
return source
|
||||
}
|
||||
const host = url.hostname.replace(/^www\./, '')
|
||||
if (host === 'youtube-nocookie.com' || host === 'player.vimeo.com' || host === 'vimeo.com' || host === 'facebook.com') {
|
||||
url.searchParams.set('autoplay', '1')
|
||||
}
|
||||
return { kind: 'embed', src: url.toString() }
|
||||
}
|
||||
|
||||
/** A still for a video link: YouTube's own thumbnail. Other hosts
|
||||
* need an API call to find theirs, so they return null and the
|
||||
* card uses its uploaded image or a plain panel. */
|
||||
export function videoThumbnail(raw?: string | null): string | null {
|
||||
if (!raw) return null
|
||||
try {
|
||||
const id = youtubeId(new URL(raw.trim()))
|
||||
return id ? `https://i.ytimg.com/vi/${encodeURIComponent(id)}/hqdefault.jpg` : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,10 @@ export const heroVideo = inDir('/front-page')
|
|||
so it can't share a per-entity directory. */
|
||||
export const blockMedia = inDir('/media') // ⚠ guess
|
||||
|
||||
/* featured_cards.image, a card's own picture. Normally an upload
|
||||
('/uploads/…'); a bare filename looks here. */
|
||||
export const featuredImage = inDir('/featured')
|
||||
|
||||
/* ── By record kind ────────────────────────────────────────────
|
||||
The timeline sends `logo: { file, kind }` rather than a path,
|
||||
because v_timeline COALESCEs across five tables and only the
|
||||
|
|
@ -64,6 +68,9 @@ const BY_KIND: Record<string, (file?: string | null) => string | null> = {
|
|||
team: teamLogo,
|
||||
award: awardLogo,
|
||||
person: personPhoto,
|
||||
// Featured cards (loadFeaturedCards in shape.js) add two of their own.
|
||||
'event-background': eventBackground,
|
||||
featured: featuredImage,
|
||||
}
|
||||
|
||||
export function logoForKind(
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ export type FrontPageSectionKey =
|
|||
| 'stats'
|
||||
| 'timeline'
|
||||
| 'connect'
|
||||
| 'featured'
|
||||
|
||||
export type HeroButton = { label: string; url: string }
|
||||
|
||||
|
|
@ -90,11 +91,26 @@ export type CountdownEvent = {
|
|||
series: EventSeries | null
|
||||
}
|
||||
|
||||
/** One featured card, as loadFeaturedCards in shape.js shapes it.
|
||||
* A record card's title and image are already its record's unless
|
||||
* the card overrides them; `ref` is what its link is built from. */
|
||||
export type FeaturedCard = {
|
||||
kind: 'record' | 'link' | 'video'
|
||||
ref: { kind: string; id: string; org_kind?: string | null } | null
|
||||
url: string | null
|
||||
eyebrow?: string | null
|
||||
title?: string | null
|
||||
blurb?: string | null
|
||||
/** Resolve with logoForKind in media.ts. */
|
||||
image: { file: string; kind: string } | null
|
||||
}
|
||||
|
||||
export type FrontPage = {
|
||||
hero: Hero
|
||||
sections: FrontPageSection[]
|
||||
stats: FrontPageStat[]
|
||||
paths: FrontPagePath[]
|
||||
featured: FeaturedCard[]
|
||||
countdown: CountdownEvent | null
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue