Feature updates v1.7.4: media, blog, featured content, editor nav, content blocks #11

Merged
ngu-git-admin merged 22 commits from feature/new-features into main 2026-09-27 23:37:03 +01:00
8 changed files with 243 additions and 22 deletions
Showing only changes of commit 8c26ec4906 - Show all commits

View file

@ -676,7 +676,7 @@ const frontPage = {
}, },
columns: [ columns: [
enumeration("hero_mode", ["brand", "photos", "livestream"]), enumeration("hero_mode", ["brand", "photos", "livestream", "video"]),
text("eyebrow"), text("eyebrow"),
text("headline"), text("headline"),
text("subhead"), text("subhead"),
@ -687,6 +687,8 @@ const frontPage = {
int("slide_seconds"), int("slide_seconds"),
text("livestream_url"), text("livestream_url"),
text("livestream_title"), text("livestream_title"),
text("video_url"),
text("video_title"),
text("countdown_event_id"), text("countdown_event_id"),
], ],

View file

@ -0,0 +1,79 @@
-- ═══════════════════════════════════════════════════════════════
-- 024 FRONT PAGE: FEATURED VIDEO
--
-- A fourth hero mode, 'video': a recorded video beside the words,
-- the way 'livestream' puts a stream there, but without the LIVE
-- badge and without autoplay — a visitor presses play.
--
-- Its own two columns rather than reusing the livestream's, so a
-- featured video and a stream can both be set up ahead of time and
-- the mode switches between them, as photos and livestream already
-- can.
--
-- video_url a YouTube, Vimeo or Facebook link (turned into an
-- embed), or a video file: a filename in
-- public/front-page/, a /path, or an https URL ending
-- in .mp4, .webm, .m4v, .mov or .ogv, which plays in
-- the browser's own player
-- video_title shown after "Featured video" above the headline
--
-- hero_mode's CHECK can't be altered in place, so front_page is
-- rebuilt. Its children (slides, sections, stats, paths) reference
-- it by name; the runner has foreign keys off, so the DROP leaves
-- them alone and the rename puts front_page back underneath them.
-- No view or other table's trigger names front_page, so the rename
-- needs no legacy_alter_table. front_page_touch goes with the old
-- table and is recreated last.
--
-- PRAGMA user_version; -- reads 23 before this file
-- ═══════════════════════════════════════════════════════════════
CREATE TABLE front_page_new (
id TEXT PRIMARY KEY CHECK (id = 'home'),
hero_mode TEXT NOT NULL DEFAULT 'brand'
CHECK (hero_mode IN ('brand', 'photos', 'livestream', 'video')),
eyebrow TEXT,
headline TEXT NOT NULL DEFAULT 'Next Generation of Unity',
subhead TEXT,
primary_label TEXT,
primary_url TEXT,
secondary_label TEXT,
secondary_url TEXT,
slide_seconds INTEGER NOT NULL DEFAULT 7
CHECK (slide_seconds BETWEEN 3 AND 60),
livestream_url TEXT,
livestream_title TEXT,
video_url TEXT,
video_title TEXT,
countdown_event_id TEXT REFERENCES events (id) ON DELETE SET NULL,
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
) STRICT;
INSERT INTO front_page_new
(id, hero_mode, eyebrow, headline, subhead,
primary_label, primary_url, secondary_label, secondary_url,
slide_seconds, livestream_url, livestream_title,
countdown_event_id, updated_at)
SELECT
id, hero_mode, eyebrow, headline, subhead,
primary_label, primary_url, secondary_label, secondary_url,
slide_seconds, livestream_url, livestream_title,
countdown_event_id, updated_at
FROM front_page;
DROP TABLE front_page;
ALTER TABLE front_page_new RENAME TO front_page;
CREATE TRIGGER front_page_touch
AFTER UPDATE ON front_page
FOR EACH ROW WHEN new.updated_at = old.updated_at
BEGIN
UPDATE front_page SET updated_at = datetime('now') WHERE id = new.id;
END;

View file

@ -174,6 +174,9 @@ home.get("/front-page", (c) => {
livestream: page.livestream_url livestream: page.livestream_url
? { url: page.livestream_url, title: page.livestream_title } ? { url: page.livestream_url, title: page.livestream_title }
: null, : null,
video: page.video_url
? { url: page.video_url, title: page.video_title }
: null,
}, },
sections, sections,
stats, stats,

View file

@ -950,8 +950,9 @@ const timeline = {
One record (see the singleton note in server/src/admin-schema.js). 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 groups are the hero; the collections below are the rest of
the page. Photos and the livestream are editable whatever the the page. Photos, the livestream and the featured video are
mode, so either can be ready before the switch is flipped. editable whatever the mode, so each can be ready before the
switch is flipped.
Section keys and stat sources are the CHECK lists on 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 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"], ["brand", "Brand — animated colour, no media"],
["photos", "Photos — cycles through the photos below"], ["photos", "Photos — cycles through the photos below"],
["livestream", "Livestream — embeds the stream with a LIVE badge"], ["livestream", "Livestream — embeds the stream with a LIVE badge"],
["video", "Featured video — shows the video below, click to play"],
], ],
blankLabel: "— brand —", blankLabel: "— brand —",
help: "Switch to Livestream when you go live, and back when you're done", 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: [ fields: [
{ {
path: "slide_seconds", path: "slide_seconds",
@ -1029,6 +1031,15 @@ const frontPage = {
help: "A YouTube, Facebook or Vimeo link, or any embed URL", help: "A YouTube, Facebook or Vimeo link, or any embed URL",
}, },
{ path: "livestream_title", label: "Livestream title", full: true }, { 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 through; anything that isn't https is refused, so the hero never
frames a plain-http or javascript: URL. frames a plain-http or javascript: URL.
Streams start muted: browsers only autoplay muted video, and a Streams start playing, muted: browsers only autoplay muted
hero that starts shouting is worse than one that asks. 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 { function youtubeId(url: URL): string | null {
const host = url.hostname.replace(/^www\.|^m\./, '') const host = url.hostname.replace(/^www\.|^m\./, '')
if (host === 'youtu.be') return url.pathname.slice(1) || null if (host === 'youtu.be') return url.pathname.slice(1) || null
@ -26,8 +37,8 @@ function youtubeId(url: URL): string | null {
return match?.[1] ?? null return match?.[1] ?? null
} }
/** An iframe src for a pasted stream link, or null if it can't be framed. */ /** An iframe src for a pasted link, or null if it can't be framed. */
export function livestreamEmbedUrl(raw?: string | null): string | null { function embedUrl(raw: string | null | undefined, autoplay: boolean): string | null {
if (!raw) return null if (!raw) return null
let url: URL let url: URL
@ -40,7 +51,8 @@ export function livestreamEmbedUrl(raw?: string | null): string | null {
const yt = youtubeId(url) const yt = youtubeId(url)
if (yt) { 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\./, '') const host = url.hostname.replace(/^www\./, '')
@ -48,15 +60,43 @@ export function livestreamEmbedUrl(raw?: string | null): string | null {
if (host === 'vimeo.com') { if (host === 'vimeo.com') {
const id = url.pathname.match(/^\/(?:event\/)?(\d+)/)?.[1] const id = url.pathname.match(/^\/(?:event\/)?(\d+)/)?.[1]
if (id) { if (id) {
const play = autoplay ? '?autoplay=1&muted=1' : ''
return url.pathname.startsWith('/event/') return url.pathname.startsWith('/event/')
? `https://vimeo.com/event/${id}/embed?autoplay=1&muted=1` ? `https://vimeo.com/event/${id}/embed${play}`
: `https://player.vimeo.com/video/${id}?autoplay=1&muted=1` : `https://player.vimeo.com/video/${id}${play}`
} }
} }
if ((host === 'facebook.com' || host === 'fb.watch') && !url.pathname.startsWith('/plugins/')) { 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 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. */ the Front page editor, which names the directory in its help. */
export const heroPhoto = inDir('/front-page') 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, /* content_blocks.media, which can be an image on any owner's page,
so it can't share a per-entity directory. */ so it can't share a per-entity directory. */
export const blockMedia = inDir('/media') // ⚠ guess export const blockMedia = inDir('/media') // ⚠ guess

View file

@ -13,7 +13,7 @@
import { useRecord, type Resource } from './useRecord.ts' import { useRecord, type Resource } from './useRecord.ts'
import type { EventSeries } from './eventSeries.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. */ /** The CHECK list on front_page_sections.section. */
export type FrontPageSectionKey = export type FrontPageSectionKey =
@ -43,6 +43,8 @@ export type Hero = {
slide_seconds: number slide_seconds: number
slides: HeroSlide[] slides: HeroSlide[]
livestream: { url: string; title?: string | null } | null 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 = { export type FrontPageSection = {

View file

@ -11,11 +11,14 @@
that moves on its own for more than five seconds that moves on its own for more than five seconds
needs one) needs one)
livestream the stream beside the words, with a LIVE badge 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 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 no photos, or livestream/video with no link set. A link that
link that can't be framed still gets a "Watch live" button, so can't be framed still gets a "Watch live" or "Watch the video"
switching the mode on is never a no-op. button, so switching the mode on is never a no-op.
`hero` is null while the page config loads or when it failed; the `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 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 HomeLink from './HomeLink.tsx'
import DoveMark from '../../../components/DoveMark.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 { heroPhoto } from '../../../lib/media.ts'
import type { Hero, HeroSlide } from '../../../lib/useFrontPage.ts' import type { Hero, HeroSlide } from '../../../lib/useFrontPage.ts'
@ -35,14 +38,20 @@ const DEEP = '#04262e'
export default function HeroStage({ hero }: { hero: Hero | null }) { export default function HeroStage({ hero }: { hero: Hero | null }) {
const slides = (hero?.slides ?? []).filter((slide) => heroPhoto(slide.media)) const slides = (hero?.slides ?? []).filter((slide) => heroPhoto(slide.media))
const embed = livestreamEmbedUrl(hero?.livestream?.url) const embed = livestreamEmbedUrl(hero?.livestream?.url)
const video = videoSource(hero?.video?.url)
const mode = const mode =
hero?.mode === 'photos' && slides.length > 0 hero?.mode === 'photos' && slides.length > 0
? 'photos' ? 'photos'
: hero?.mode === 'livestream' && hero.livestream : hero?.mode === 'livestream' && hero.livestream
? 'livestream' ? 'livestream'
: hero?.mode === 'video' && hero.video
? 'video'
: 'brand' : 'brand'
// Livestream and video share a layout: words left, player right.
const beside = mode === 'livestream' || mode === 'video'
return ( return (
<section <section
id="hero" id="hero"
@ -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="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'}> <div className={beside ? 'lg:col-span-5' : 'lg:col-span-8'}>
{hero && <Words hero={hero} live={mode === 'livestream'} />} {hero && <Words hero={hero} mode={mode} />}
</div> </div>
{mode === 'livestream' && hero?.livestream && ( {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} /> <LiveFrame src={embed} url={hero.livestream.url} title={hero.livestream.title} />
</div> </div>
)} )}
{mode === 'video' && hero?.video && (
<div className="lg:col-span-7">
<VideoFrame source={video} url={hero.video.url} title={hero.video.title} />
</div>
)}
</div> </div>
</section> </section>
) )
@ -72,8 +87,10 @@ export default function HeroStage({ hero }: { hero: Hero | null }) {
/* ── The words ───────────────────────────────────────────────── */ /* ── 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 words = hero.headline.split(/\s+/).filter(Boolean)
const live = mode === 'livestream'
const beside = live || mode === 'video'
return ( return (
<div className="text-white"> <div className="text-white">
@ -87,6 +104,16 @@ function Words({ hero, live }: { hero: Hero; live: boolean }) {
</span> </span>
)} )}
</p> </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 && ( 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]"> <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 <h1
className={`font-display font-extrabold leading-[0.95] tracking-tight ${ 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) => ( {words.map((word, index) => (
@ -326,3 +353,56 @@ function LiveFrame({ src, url, title }: { src: string | null; url: string; title
</div> </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>
)
}