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
190
src/components/FeaturedCards.tsx
Normal file
190
src/components/FeaturedCards.tsx
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
FEATURED CARDS
|
||||
|
||||
A grid of cards that point somewhere: the front page's featured
|
||||
band now, the Community blog's posts next. The data comes from
|
||||
loadFeaturedCards in server/src/shape.js, already resolved, so
|
||||
this only draws.
|
||||
|
||||
Three kinds of card:
|
||||
|
||||
record links to the record's own page (hrefs.ts builds it)
|
||||
link links to its URL, a new tab when it leaves the site
|
||||
video a still with a play button; pressing it swaps in the
|
||||
player, so the page loads no iframes until then. The
|
||||
still is the card's image, else YouTube's thumbnail,
|
||||
else a plain panel.
|
||||
|
||||
A photo fills the picture area; a logo sits inside it on a soft
|
||||
panel instead, since cropping a logo to 16:9 cuts it off.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useState } from 'react'
|
||||
|
||||
import HomeLink from '../pages/sections/home/HomeLink.tsx'
|
||||
import { refHref } from '../lib/hrefs.ts'
|
||||
import { logoForKind } from '../lib/media.ts'
|
||||
import { playingSource, videoSource, videoThumbnail } from '../lib/embeds.ts'
|
||||
import type { FeaturedCard } from '../lib/useFrontPage.ts'
|
||||
|
||||
const ACCENT = '#138ba0'
|
||||
|
||||
/* Image kinds that are photographs, drawn edge to edge. Anything
|
||||
else is a logo, drawn whole. */
|
||||
const PHOTO_KINDS = new Set(['event-background', 'featured', 'person'])
|
||||
|
||||
function hrefFor(card: FeaturedCard): string | null {
|
||||
if (card.kind === 'record' && card.ref) {
|
||||
return refHref(card.ref.kind, card.ref.id, card.ref.org_kind)
|
||||
}
|
||||
return card.kind === 'link' ? card.url : null
|
||||
}
|
||||
|
||||
function Picture({ card }: { card: FeaturedCard }) {
|
||||
const [failed, setFailed] = useState(false)
|
||||
const src = card.image ? logoForKind(card.image.kind, card.image.file) : null
|
||||
const photo = card.image ? PHOTO_KINDS.has(card.image.kind) : false
|
||||
|
||||
if (!src || failed) {
|
||||
return <div className="aspect-video w-full bg-gradient-to-br from-[#eef9fb] to-[#d9f0f3]" />
|
||||
}
|
||||
|
||||
return photo ? (
|
||||
<img
|
||||
src={src}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
onError={() => setFailed(true)}
|
||||
className="aspect-video w-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<div className="flex aspect-video w-full items-center justify-center bg-[#eef9fb] p-8">
|
||||
<img
|
||||
src={src}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
onError={() => setFailed(true)}
|
||||
className="max-h-full max-w-full object-contain"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function VideoPicture({ card }: { card: FeaturedCard }) {
|
||||
const [playing, setPlaying] = useState(false)
|
||||
const source = videoSource(card.url)
|
||||
|
||||
if (playing && source) {
|
||||
const live = playingSource(source)
|
||||
return live.kind === 'file' ? (
|
||||
<video src={live.src} controls autoPlay playsInline className="aspect-video w-full bg-black" />
|
||||
) : (
|
||||
<iframe
|
||||
src={live.src}
|
||||
title={card.title || 'Video'}
|
||||
allow="autoplay; encrypted-media; picture-in-picture; fullscreen"
|
||||
allowFullScreen
|
||||
className="aspect-video w-full border-0 bg-black"
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const own = card.image ? logoForKind(card.image.kind, card.image.file) : null
|
||||
const still = own ?? videoThumbnail(card.url)
|
||||
|
||||
const face = (
|
||||
<>
|
||||
{still ? (
|
||||
<img src={still} alt="" loading="lazy" className="aspect-video w-full object-cover" />
|
||||
) : (
|
||||
<div className="aspect-video w-full bg-gradient-to-br from-[#073d4a] to-[#04262e]" />
|
||||
)}
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="absolute inset-0 flex items-center justify-center bg-black/10 transition-colors group-hover:bg-black/25"
|
||||
>
|
||||
<span className="flex h-16 w-16 items-center justify-center rounded-full bg-white/90 shadow-lg transition-transform group-hover:scale-110">
|
||||
<svg viewBox="0 0 24 24" className="ml-1 h-7 w-7" fill={ACCENT}>
|
||||
<path d="M8 5v14l11-7z" />
|
||||
</svg>
|
||||
</span>
|
||||
</span>
|
||||
</>
|
||||
)
|
||||
|
||||
// A link that can't be played here still goes somewhere.
|
||||
if (!source) {
|
||||
return card.url ? (
|
||||
<HomeLink url={card.url} className="group relative block">
|
||||
{face}
|
||||
</HomeLink>
|
||||
) : (
|
||||
<div className="relative">{face}</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setPlaying(true)}
|
||||
aria-label={`Play ${card.title || 'video'}`}
|
||||
className="group relative block w-full"
|
||||
>
|
||||
{face}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
function Card({ card }: { card: FeaturedCard }) {
|
||||
const href = hrefFor(card)
|
||||
|
||||
const text = (
|
||||
<div className="flex flex-1 flex-col p-6">
|
||||
{card.eyebrow && (
|
||||
<p className="text-xs font-bold uppercase tracking-[0.2em] text-[#138ba0]">{card.eyebrow}</p>
|
||||
)}
|
||||
{card.title && (
|
||||
<h3 className="mt-2 font-display text-xl font-extrabold leading-snug text-[#073d4a]">
|
||||
{href ? (
|
||||
// Stretched over the whole card, so the picture and the
|
||||
// blurb are part of the click without nesting links.
|
||||
<HomeLink
|
||||
url={href}
|
||||
className="after:absolute after:inset-0 after:rounded-2xl after:content-[''] hover:underline"
|
||||
>
|
||||
{card.title}
|
||||
</HomeLink>
|
||||
) : (
|
||||
card.title
|
||||
)}
|
||||
</h3>
|
||||
)}
|
||||
{card.blurb && <p className="mt-2 leading-relaxed text-[#4a6b72]">{card.blurb}</p>}
|
||||
</div>
|
||||
)
|
||||
|
||||
return (
|
||||
<li className="relative flex flex-col overflow-hidden rounded-2xl border border-[#138ba0]/15 bg-white shadow-sm transition-shadow hover:shadow-lg">
|
||||
{card.kind === 'video' ? (
|
||||
// Above the stretched link, which a video card doesn't have
|
||||
// anyway, so the play button always gets the click.
|
||||
<div className="relative z-10">
|
||||
<VideoPicture card={card} />
|
||||
</div>
|
||||
) : (
|
||||
<Picture card={card} />
|
||||
)}
|
||||
{text}
|
||||
</li>
|
||||
)
|
||||
}
|
||||
|
||||
export default function FeaturedCards({ cards }: { cards: FeaturedCard[] }) {
|
||||
return (
|
||||
<ul className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{cards.map((card, index) => (
|
||||
<Card key={`${card.kind}-${card.ref?.id ?? card.url}-${index}`} card={card} />
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue