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:
parent
b10a263a90
commit
8c26ec4906
8 changed files with 243 additions and 22 deletions
|
|
@ -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>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue