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>
|
||||
)
|
||||
}
|
||||
|
|
@ -11,6 +11,11 @@
|
|||
(pages/admin/AdminMedia.tsx) draw.
|
||||
UploadButton a file input dressed as a button, with the
|
||||
"keep original" choice beside it.
|
||||
LinkPreviewInput
|
||||
the `widget: "linkPreview"` field: a URL box and a
|
||||
"Fetch preview" button that reads the page's title,
|
||||
description and preview image (the image lands in
|
||||
the library) and fills the row's empty fields.
|
||||
|
||||
An image field stores a path, not a media id: '/uploads/<file>'
|
||||
for an upload, or, as before, a bare filename in the field's
|
||||
|
|
@ -26,7 +31,7 @@
|
|||
|
||||
import { useCallback, useEffect, useId, useRef, useState, type ReactNode } from "react";
|
||||
|
||||
import { ApiError, get, upload } from "../../lib/api.ts";
|
||||
import { ApiError, get, post, upload } from "../../lib/api.ts";
|
||||
import { useAuth } from "../../lib/auth.tsx";
|
||||
import { canWrite as roleCanWrite } from "../../lib/roles.ts";
|
||||
|
||||
|
|
@ -405,3 +410,85 @@ export function ImageInput({
|
|||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/* ── Link preview field ──────────────────────────────────────── */
|
||||
|
||||
/* Fills only what's empty: a title somebody already typed is theirs,
|
||||
not the page's. Which fields it fills is the row's title, blurb and
|
||||
image, the featured card's names. */
|
||||
export function LinkPreviewInput({
|
||||
id,
|
||||
value,
|
||||
row,
|
||||
locked,
|
||||
className,
|
||||
showButton,
|
||||
onChange,
|
||||
onPatch,
|
||||
}: {
|
||||
id: string;
|
||||
value: string | null | undefined;
|
||||
row: Record<string, any>;
|
||||
locked: boolean;
|
||||
className: string;
|
||||
showButton: boolean;
|
||||
onChange: (value: string) => void;
|
||||
onPatch?: (patch: Record<string, any>) => void;
|
||||
}) {
|
||||
const { user } = useAuth();
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [note, setNote] = useState<{ tone: "ok" | "error"; text: string } | null>(null);
|
||||
|
||||
async function fetchPreview() {
|
||||
if (!value || !onPatch) return;
|
||||
setBusy(true);
|
||||
setNote(null);
|
||||
try {
|
||||
const { preview } = await post("/admin/link-preview", { url: value });
|
||||
const patch: Record<string, any> = {};
|
||||
if (!row.title && preview.title) patch.title = preview.title;
|
||||
if (!row.blurb && preview.description) patch.blurb = preview.description;
|
||||
if (!row.image && preview.image) patch.image = preview.image.url;
|
||||
onPatch(patch);
|
||||
|
||||
const filled = Object.keys(patch).length;
|
||||
setNote(
|
||||
preview.image_error
|
||||
? { tone: "error", text: `Filled ${filled} field${filled === 1 ? "" : "s"}. ${preview.image_error}` }
|
||||
: filled
|
||||
? { tone: "ok", text: `Filled ${filled} empty field${filled === 1 ? "" : "s"}.` }
|
||||
: { tone: "ok", text: "Nothing to fill: those fields already have values, or the page has none." },
|
||||
);
|
||||
} catch (err) {
|
||||
setNote({ tone: "error", text: err instanceof ApiError ? err.message : "Couldn't read that page." });
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<input
|
||||
id={id}
|
||||
type="text"
|
||||
value={value ?? ""}
|
||||
readOnly={locked}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
placeholder="https://"
|
||||
className={className}
|
||||
/>
|
||||
{showButton && !locked && roleCanWrite(user) && (
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<button type="button" className={button} disabled={busy || !value} onClick={fetchPreview}>
|
||||
{busy ? "Fetching…" : "Fetch preview"}
|
||||
</button>
|
||||
{note && (
|
||||
<span className={`text-xs ${note.tone === "ok" ? "text-[#138ba0]" : "text-[#b3261e]"}`}>
|
||||
{note.text}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,16 @@
|
|||
that column in the server's admin-schema.js or the row will be
|
||||
saved as real input.
|
||||
|
||||
In a repeater row, `when: { path, value }` shows a field only
|
||||
while another field of the row holds that value (or one of them,
|
||||
given an array). A field that goes hidden is cleared, so a row
|
||||
can't keep a value for a choice it no longer makes: a featured
|
||||
card switched from "record" to "link" drops its record.
|
||||
|
||||
`widget: "linkPreview"` is a URL box with a "Fetch preview" button
|
||||
(LinkPreviewInput in MediaLibrary.tsx) that fills the row's empty
|
||||
title, blurb and image through `onPatch`.
|
||||
|
||||
`widget: "image"` is a text box with a preview and upload and
|
||||
library buttons beside it (ImageInput in MediaLibrary.tsx). Its
|
||||
`resolve` option is the media.ts helper for the field's public/
|
||||
|
|
@ -47,7 +57,7 @@
|
|||
|
||||
import { useRef, useState } from "react";
|
||||
|
||||
import { ImageInput } from "./MediaLibrary.tsx";
|
||||
import { ImageInput, LinkPreviewInput } from "./MediaLibrary.tsx";
|
||||
|
||||
const input =
|
||||
"w-full rounded-lg border border-[#4a6b72]/25 bg-white px-3 py-2 text-sm text-[#26454c] " +
|
||||
|
|
@ -84,9 +94,30 @@ export function setPath(object, path, value) {
|
|||
return { ...object, [head]: setPath(object?.[head] ?? {}, rest.join("."), value) };
|
||||
}
|
||||
|
||||
/* ── Conditional fields ──────────────────────────────────────── */
|
||||
|
||||
export function fieldShown(field, row) {
|
||||
if (!field.when) return true;
|
||||
const want = Array.isArray(field.when.value) ? field.when.value : [field.when.value];
|
||||
return want.includes(row?.[field.when.path]);
|
||||
}
|
||||
|
||||
/* A row after an edit, with any field the edit hid cleared. "" is
|
||||
the engine's deliberate clear, so it saves as NULL. */
|
||||
function withHiddenCleared(fields, row) {
|
||||
let next = row;
|
||||
for (const field of fields) {
|
||||
const value = next[field.path];
|
||||
if (!fieldShown(field, next) && value != null && value !== "") {
|
||||
next = { ...next, [field.path]: "" };
|
||||
}
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
/* ── Field ───────────────────────────────────────────────────── */
|
||||
|
||||
export function Field({ field, value, row, options, error, onChange }: any) {
|
||||
export function Field({ field, value, row, options, error, onChange, onPatch }: any) {
|
||||
const id = `f-${field.path.replace(/\./g, "-")}`;
|
||||
const widget = field.widget ?? "text";
|
||||
const locked = Boolean(field.readOnly);
|
||||
|
|
@ -183,6 +214,17 @@ export function Field({ field, value, row, options, error, onChange }: any) {
|
|||
className={locked ? inputLocked : common.className}
|
||||
/>
|
||||
</div>
|
||||
) : widget === "linkPreview" ? (
|
||||
<LinkPreviewInput
|
||||
id={id}
|
||||
value={value}
|
||||
row={row}
|
||||
locked={locked}
|
||||
className={locked ? inputLocked : common.className}
|
||||
showButton={!field.previewWhen || fieldShown({ when: field.previewWhen }, row)}
|
||||
onChange={onChange}
|
||||
onPatch={onPatch}
|
||||
/>
|
||||
) : widget === "image" ? (
|
||||
<ImageInput
|
||||
id={id}
|
||||
|
|
@ -298,7 +340,7 @@ export function Repeater({
|
|||
const rowRefs = useRef<any[]>([]);
|
||||
|
||||
const update = (index, next) =>
|
||||
onChange(list.map((row, i) => (i === index ? next : row)));
|
||||
onChange(list.map((row, i) => (i === index ? withHiddenCleared(spec.fields, next) : row)));
|
||||
|
||||
const move = (index, delta) => {
|
||||
const target = index + delta;
|
||||
|
|
@ -489,17 +531,20 @@ export function Repeater({
|
|||
{expanded && (
|
||||
<>
|
||||
<FieldGrid>
|
||||
{spec.fields.map((field) => (
|
||||
<Field
|
||||
key={field.path}
|
||||
field={field}
|
||||
row={row}
|
||||
value={row[field.path]}
|
||||
options={options}
|
||||
error={errors?.[`${errorPrefix}${index}.${field.path}`]}
|
||||
onChange={(value) => update(index, { ...row, [field.path]: value })}
|
||||
/>
|
||||
))}
|
||||
{spec.fields
|
||||
.filter((field) => fieldShown(field, row))
|
||||
.map((field) => (
|
||||
<Field
|
||||
key={field.path}
|
||||
field={field}
|
||||
row={row}
|
||||
value={row[field.path]}
|
||||
options={options}
|
||||
error={errors?.[`${errorPrefix}${index}.${field.path}`]}
|
||||
onChange={(value) => update(index, { ...row, [field.path]: value })}
|
||||
onPatch={(patch) => update(index, { ...row, ...patch })}
|
||||
/>
|
||||
))}
|
||||
</FieldGrid>
|
||||
|
||||
{(spec.children ?? []).map((nested) => (
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@
|
|||
|
||||
A band with nothing to show draws nothing: the countdown with no
|
||||
upcoming event, the numbers with no numbers, the timeline with
|
||||
nothing featured, the pathfinder with no paths.
|
||||
nothing featured, the pathfinder with no paths, the featured band
|
||||
with no cards.
|
||||
|
||||
If /front-page fails, the hero still draws (empty) and the error
|
||||
takes the place of the bands, with a retry. There's deliberately
|
||||
|
|
@ -29,6 +30,7 @@ import NextEventCountdown from './sections/home/NextEventCountdown.tsx'
|
|||
import RetreatsBand from './sections/home/RetreatsBand.tsx'
|
||||
import CalendarBand from './sections/home/CalendarBand.tsx'
|
||||
import StatsBand from './sections/home/StatsBand.tsx'
|
||||
import FeaturedBand from './sections/home/FeaturedBand.tsx'
|
||||
import FeaturedTimelineRail from './sections/home/FeaturedTimelineRail.tsx'
|
||||
import Pathfinder from './sections/home/Pathfinder.tsx'
|
||||
import {
|
||||
|
|
@ -90,6 +92,13 @@ const SECTIONS: Record<
|
|||
<Pathfinder id="connect" title={title} blurb={section.blurb} paths={page.paths} />
|
||||
),
|
||||
},
|
||||
featured: {
|
||||
title: 'Featured',
|
||||
render: ({ page, section, title }) =>
|
||||
page.featured.length > 0 && (
|
||||
<FeaturedBand id="featured" title={title} blurb={section.blurb} cards={page.featured} />
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
export default function Home() {
|
||||
|
|
|
|||
32
src/pages/sections/home/FeaturedBand.tsx
Normal file
32
src/pages/sections/home/FeaturedBand.tsx
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
FEATURED BAND
|
||||
|
||||
The front page's featured content: the cards from the admin's
|
||||
Front page editor (Featured cards), under the section's heading.
|
||||
The cards themselves are FeaturedCards, which the Community
|
||||
blog will share. No cards, no band.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import FeaturedCards from '../../../components/FeaturedCards.tsx'
|
||||
import type { FeaturedCard } from '../../../lib/useFrontPage.ts'
|
||||
|
||||
type FeaturedBandProps = {
|
||||
id: string
|
||||
title: string
|
||||
blurb?: string | null
|
||||
cards: FeaturedCard[]
|
||||
}
|
||||
|
||||
export default function FeaturedBand({ id, title, blurb, cards }: FeaturedBandProps) {
|
||||
return (
|
||||
<section id={id} className="py-24" style={{ background: '#f6fbfc' }}>
|
||||
<div className="mx-auto max-w-6xl px-6">
|
||||
<h2 className="font-display text-4xl font-extrabold text-[#073d4a] md:text-5xl">{title}</h2>
|
||||
{blurb && <p className="mt-4 max-w-2xl text-lg text-[#4a6b72]">{blurb}</p>}
|
||||
<div className="mt-12">
|
||||
<FeaturedCards cards={cards} />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue