Add a featured video mode to the front page hero

A fourth hero mode beside brand, photos and livestream: a recorded
video next to the words, under a "Featured video · <title>" badge.
Unlike the livestream it never autoplays: an embed waits for play,
and a file shows the browser's own player with preload="metadata".

video_url takes a YouTube, Vimeo or Facebook link (turned into an
embed, as the livestream's is) or a video file: a filename in
public/front-page/, a /path, or an https URL ending in .mp4, .webm,
.m4v, .mov or .ogv. Anything else that can't be framed still gets a
"Watch the video" button. Files follow the embeds' https-only rule.

Its own video_url and video_title columns rather than the
livestream's, so both can be set up ahead of time and the mode
switches between them. Migration 024 rebuilds front_page for the
wider hero_mode CHECK; its children, keys and touch trigger survive.

embeds.ts gains an autoplay switch shared by both modes, and
videoSource() to tell a file from an embed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-26 17:55:51 -05:00
parent b10a263a90
commit 8c26ec4906
8 changed files with 243 additions and 22 deletions

View file

@ -950,8 +950,9 @@ const timeline = {
One record (see the singleton note in server/src/admin-schema.js).
The groups are the hero; the collections below are the rest of
the page. Photos and the livestream are editable whatever the
mode, so either can be ready before the switch is flipped.
the page. Photos, the livestream and the featured video are
editable whatever the mode, so each can be ready before the
switch is flipped.
Section keys and stat sources are the CHECK lists on
front_page_sections and front_page_stats. The labels here are what the admin reads; the values are
@ -1000,6 +1001,7 @@ const frontPage = {
["brand", "Brand — animated colour, no media"],
["photos", "Photos — cycles through the photos below"],
["livestream", "Livestream — embeds the stream with a LIVE badge"],
["video", "Featured video — shows the video below, click to play"],
],
blankLabel: "— brand —",
help: "Switch to Livestream when you go live, and back when you're done",
@ -1014,7 +1016,7 @@ const frontPage = {
],
},
{
legend: "Photos and livestream",
legend: "Photos, livestream and video",
fields: [
{
path: "slide_seconds",
@ -1029,6 +1031,15 @@ const frontPage = {
help: "A YouTube, Facebook or Vimeo link, or any embed URL",
},
{ path: "livestream_title", label: "Livestream title", full: true },
{
path: "video_url",
label: "Featured video",
full: true,
help:
"A YouTube, Vimeo or Facebook link, or a video file: a filename in " +
"public/front-page/ or a link ending in .mp4 or .webm",
},
{ path: "video_title", label: "Video title", full: true, help: "Shown after \"Featured video\" above the headline" },
],
},
{

View file

@ -9,10 +9,21 @@
through; anything that isn't https is refused, so the hero never
frames a plain-http or javascript: URL.
Streams start muted: browsers only autoplay muted video, and a
hero that starts shouting is worse than one that asks.
Streams start playing, muted: browsers only autoplay muted
video, and a hero that starts shouting is worse than one that
asks. A featured video doesn't start at all — it's a recording,
so the visitor presses play.
A featured video can also be a file rather than a link: a
filename in public/front-page/, a /path, or an https URL ending
in a video extension. videoSource() says which, so the hero can
hand a file to <video> and a link to an <iframe>.
═══════════════════════════════════════════════════════════════ */
import { heroVideo } from './media.ts'
const VIDEO_FILE = /\.(mp4|webm|m4v|mov|ogv)$/i
function youtubeId(url: URL): string | null {
const host = url.hostname.replace(/^www\.|^m\./, '')
if (host === 'youtu.be') return url.pathname.slice(1) || null
@ -26,8 +37,8 @@ function youtubeId(url: URL): string | null {
return match?.[1] ?? null
}
/** An iframe src for a pasted stream link, or null if it can't be framed. */
export function livestreamEmbedUrl(raw?: string | null): string | null {
/** An iframe src for a pasted link, or null if it can't be framed. */
function embedUrl(raw: string | null | undefined, autoplay: boolean): string | null {
if (!raw) return null
let url: URL
@ -40,7 +51,8 @@ export function livestreamEmbedUrl(raw?: string | null): string | null {
const yt = youtubeId(url)
if (yt) {
return `https://www.youtube-nocookie.com/embed/${encodeURIComponent(yt)}?autoplay=1&mute=1&playsinline=1`
const play = autoplay ? '?autoplay=1&mute=1&playsinline=1' : '?playsinline=1'
return `https://www.youtube-nocookie.com/embed/${encodeURIComponent(yt)}${play}`
}
const host = url.hostname.replace(/^www\./, '')
@ -48,15 +60,43 @@ export function livestreamEmbedUrl(raw?: string | null): string | null {
if (host === 'vimeo.com') {
const id = url.pathname.match(/^\/(?:event\/)?(\d+)/)?.[1]
if (id) {
const play = autoplay ? '?autoplay=1&muted=1' : ''
return url.pathname.startsWith('/event/')
? `https://vimeo.com/event/${id}/embed?autoplay=1&muted=1`
: `https://player.vimeo.com/video/${id}?autoplay=1&muted=1`
? `https://vimeo.com/event/${id}/embed${play}`
: `https://player.vimeo.com/video/${id}${play}`
}
}
if ((host === 'facebook.com' || host === 'fb.watch') && !url.pathname.startsWith('/plugins/')) {
return `https://www.facebook.com/plugins/video.php?href=${encodeURIComponent(url.href)}&autoplay=1&mute=1`
const play = autoplay ? '&autoplay=1&mute=1' : ''
return `https://www.facebook.com/plugins/video.php?href=${encodeURIComponent(url.href)}${play}`
}
return url.href
}
/** An iframe src for a pasted stream link, or null if it can't be framed. */
export function livestreamEmbedUrl(raw?: string | null): string | null {
return embedUrl(raw, true)
}
export type VideoSource = { kind: 'file' | 'embed'; src: string }
/** How to play a featured video: a file for <video>, an embed for
* an <iframe>, or null when it's neither (the hero then links to
* it instead). Files follow the same https-only rule as embeds. */
export function videoSource(raw?: string | null): VideoSource | null {
const value = raw?.trim()
if (!value) return null
if (VIDEO_FILE.test(value.split(/[?#]/)[0])) {
if (/^https:\/\//i.test(value) || !/^[a-z][a-z0-9+.-]*:/i.test(value)) {
const src = heroVideo(value)
if (src) return { kind: 'file', src }
}
return null
}
const src = embedUrl(value, false)
return src ? { kind: 'embed', src } : null
}

View file

@ -35,6 +35,10 @@ export const awardLogo = inDir('/award-logos') // ⚠ guess
the Front page editor, which names the directory in its help. */
export const heroPhoto = inDir('/front-page')
/* front_page.video_url when it names a file rather than a link:
same directory as the photos. */
export const heroVideo = inDir('/front-page')
/* content_blocks.media, which can be an image on any owner's page,
so it can't share a per-entity directory. */
export const blockMedia = inDir('/media') // ⚠ guess

View file

@ -13,7 +13,7 @@
import { useRecord, type Resource } from './useRecord.ts'
import type { EventSeries } from './eventSeries.ts'
export type HeroMode = 'brand' | 'photos' | 'livestream'
export type HeroMode = 'brand' | 'photos' | 'livestream' | 'video'
/** The CHECK list on front_page_sections.section. */
export type FrontPageSectionKey =
@ -43,6 +43,8 @@ export type Hero = {
slide_seconds: number
slides: HeroSlide[]
livestream: { url: string; title?: string | null } | null
/** A link to embed or a video file; see videoSource in embeds.ts. */
video: { url: string; title?: string | null } | null
}
export type FrontPageSection = {

View file

@ -11,11 +11,14 @@
that moves on its own for more than five seconds
needs one)
livestream the stream beside the words, with a LIVE badge
video a featured video beside the words, under a
"Featured video" badge. Never autoplays: an embed
waits for play, a file shows the browser's player
A mode that has nothing to show falls back to brand: photos with
no photos, or a livestream link that can't be embedded. A stream
link that can't be framed still gets a "Watch live" button, so
switching the mode on is never a no-op.
no photos, or livestream/video with no link set. A link that
can't be framed still gets a "Watch live" or "Watch the video"
button, so switching the mode on is never a no-op.
`hero` is null while the page config loads or when it failed; the
stage still draws, empty, so the page doesn't jump when it
@ -26,7 +29,7 @@ import { useEffect, useState, type CSSProperties } from 'react'
import HomeLink from './HomeLink.tsx'
import DoveMark from '../../../components/DoveMark.tsx'
import { livestreamEmbedUrl } from '../../../lib/embeds.ts'
import { livestreamEmbedUrl, videoSource, type VideoSource } from '../../../lib/embeds.ts'
import { heroPhoto } from '../../../lib/media.ts'
import type { Hero, HeroSlide } from '../../../lib/useFrontPage.ts'
@ -35,13 +38,19 @@ const DEEP = '#04262e'
export default function HeroStage({ hero }: { hero: Hero | null }) {
const slides = (hero?.slides ?? []).filter((slide) => heroPhoto(slide.media))
const embed = livestreamEmbedUrl(hero?.livestream?.url)
const video = videoSource(hero?.video?.url)
const mode =
hero?.mode === 'photos' && slides.length > 0
? 'photos'
: hero?.mode === 'livestream' && hero.livestream
? 'livestream'
: 'brand'
: hero?.mode === 'video' && hero.video
? 'video'
: 'brand'
// Livestream and video share a layout: words left, player right.
const beside = mode === 'livestream' || mode === 'video'
return (
<section
@ -56,8 +65,8 @@ export default function HeroStage({ hero }: { hero: Hero | null }) {
)}
<div className="relative z-10 mx-auto grid w-full max-w-7xl items-center gap-12 px-6 lg:grid-cols-12">
<div className={mode === 'livestream' ? 'lg:col-span-5' : 'lg:col-span-8'}>
{hero && <Words hero={hero} live={mode === 'livestream'} />}
<div className={beside ? 'lg:col-span-5' : 'lg:col-span-8'}>
{hero && <Words hero={hero} mode={mode} />}
</div>
{mode === 'livestream' && hero?.livestream && (
@ -65,6 +74,12 @@ export default function HeroStage({ hero }: { hero: Hero | null }) {
<LiveFrame src={embed} url={hero.livestream.url} title={hero.livestream.title} />
</div>
)}
{mode === 'video' && hero?.video && (
<div className="lg:col-span-7">
<VideoFrame source={video} url={hero.video.url} title={hero.video.title} />
</div>
)}
</div>
</section>
)
@ -72,8 +87,10 @@ export default function HeroStage({ hero }: { hero: Hero | null }) {
/* ── The words ───────────────────────────────────────────────── */
function Words({ hero, live }: { hero: Hero; live: boolean }) {
function Words({ hero, mode }: { hero: Hero; mode: 'brand' | 'photos' | 'livestream' | 'video' }) {
const words = hero.headline.split(/\s+/).filter(Boolean)
const live = mode === 'livestream'
const beside = live || mode === 'video'
return (
<div className="text-white">
@ -87,6 +104,16 @@ function Words({ hero, live }: { hero: Hero; live: boolean }) {
</span>
)}
</p>
) : mode === 'video' ? (
<p className="mb-6 inline-flex items-center gap-3 rounded-full bg-white/10 px-4 py-1.5 text-sm font-semibold uppercase tracking-[0.2em] backdrop-blur">
<span className="text-[#9fe7d0]" aria-hidden="true">▶</span>
Featured video
{hero.video?.title && (
<span className="normal-case tracking-normal text-white/75">
· {hero.video.title}
</span>
)}
</p>
) : (
hero.eyebrow && (
<p className="mb-6 inline-block rounded-full border border-white/20 px-4 py-1.5 text-xs font-semibold uppercase tracking-[0.25em] text-[#9fe7d0]">
@ -97,7 +124,7 @@ function Words({ hero, live }: { hero: Hero; live: boolean }) {
<h1
className={`font-display font-extrabold leading-[0.95] tracking-tight ${
live ? 'text-5xl md:text-6xl' : 'text-6xl md:text-8xl'
beside ? 'text-5xl md:text-6xl' : 'text-6xl md:text-8xl'
}`}
>
{words.map((word, index) => (
@ -326,3 +353,56 @@ function LiveFrame({ src, url, title }: { src: string | null; url: string; title
</div>
)
}
/* ── Featured video ──────────────────────────────────────────── */
/* A file plays in <video> with the browser's controls; preload
"metadata" fetches enough for the first frame and the length,
not the whole file. An embed waits for play. A link that is
neither still gets a button out to it. */
function VideoFrame({
source,
url,
title,
}: {
source: VideoSource | null
url: string
title?: string | null
}) {
return (
<div
className="relative overflow-hidden rounded-3xl border border-white/15 bg-black shadow-2xl"
style={{ boxShadow: '0 30px 80px -20px rgba(92, 231, 255, 0.35)' }}
>
<div className="aspect-video w-full">
{source?.kind === 'file' ? (
<video
src={source.src}
title={title || 'Featured video'}
className="h-full w-full"
controls
playsInline
preload="metadata"
/>
) : source?.kind === 'embed' ? (
<iframe
src={source.src}
title={title || 'Featured video'}
className="h-full w-full"
allow="encrypted-media; picture-in-picture; fullscreen"
allowFullScreen
/>
) : (
<div className="flex h-full w-full items-center justify-center">
<HomeLink
url={url}
className="rounded-full bg-white px-6 py-3 font-semibold text-[#04262e] hover:scale-105"
>
Watch the video
</HomeLink>
</div>
)}
</div>
</div>
)
}