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
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue