Region featured cards, featured grid, video stills, media naming (v1.13.2-region-cards) #30

Merged
ngu-git-admin merged 6 commits from region-featured-cards into main 2026-10-16 20:13:17 +01:00
12 changed files with 240 additions and 13 deletions
Showing only changes of commit 14a22ca44d - Show all commits

View file

@ -14,11 +14,18 @@ it: **Save to library** and **Save to Drive** on the download itself.
It stays on the server to cut clips from either way (until the day's It stays on the server to cut clips from either way (until the day's
sweep). sweep).
The same tools take stills: a video featured card's Image field has The same tools take stills (editors and up), each saving the frame at
**Frame at** (editors and up), which saves the frame at a typed time to a typed time to `/uploads/thumbnails/` (`grabFrame` in
`/uploads/thumbnails/` (`grabFrame` in `server/src/clips.js`). It `server/src/clips.js`, `POST /api/admin/video-frame`). It downloads only
downloads only that frame, outside the queue. A link's own `t=` (eg. that frame, outside the queue. A link's own `t=` (eg. `?t=83`) fills in
`?t=83`) fills in the time. the time. **Frame at** is on:
- a video featured card's Image field (the front page, a region)
- a video content block's Image field (its still)
- the front page's Video still (the hero's featured video, migration 074)
and **Tools → Video thumbnails** (`AdminVideoFrames.tsx`) takes one from
any link, to download or copy its path into a field.
Clips queue and run one at a time. A finished clip is deleted from the Clips queue and run one at a time. A finished clip is deleted from the
server once it's downloaded, unless **Save to library** is pressed first, server once it's downloaded, unless **Save to library** is pressed first,

View file

@ -49,6 +49,7 @@ export const frontPage = {
text("countdown_scope_id"), text("countdown_scope_id"),
enumeration("countdown_event_type", ["retreat", "class", "workshop", "meeting", "other"]), enumeration("countdown_event_type", ["retreat", "class", "workshop", "meeting", "other"]),
int("featured_columns"), int("featured_columns"),
text("video_still"),
], ],
children: [ children: [

View file

@ -0,0 +1,11 @@
-- ═══════════════════════════════════════════════════════════════
-- 074 FRONT PAGE VIDEO STILL
--
-- The hero's featured video gets a still of its own: the picture
-- shown before it plays (a /uploads/ path, a bare filename or a
-- URL, like every image field). Null keeps YouTube's thumbnail, or
-- for a video file, its first frame. The editor's Frame at fills it
-- from the video at a typed time.
-- ═══════════════════════════════════════════════════════════════
ALTER TABLE front_page ADD COLUMN video_still TEXT;

View file

@ -225,7 +225,7 @@ home.get("/front-page", (c) => {
? { url: page.livestream_url, title: page.livestream_title } ? { url: page.livestream_url, title: page.livestream_title }
: null, : null,
video: page.video_url video: page.video_url
? { url: page.video_url, title: page.video_title, captions: page.video_captions } ? { url: page.video_url, title: page.video_title, captions: page.video_captions, still: page.video_still }
: null, : null,
event: shapeHeroEvent(db, heroEvent), event: shapeHeroEvent(db, heroEvent),
}, },

View file

@ -80,6 +80,7 @@ const AdminHome = lazyPage(() => import("./pages/admin/AdminHome.tsx"))
const AdminFeedback = lazyPage(() => import("./pages/admin/AdminFeedback.tsx")) const AdminFeedback = lazyPage(() => import("./pages/admin/AdminFeedback.tsx"))
const AdminMedia = lazyPage(() => import("./pages/admin/AdminMedia.tsx")) const AdminMedia = lazyPage(() => import("./pages/admin/AdminMedia.tsx"))
const AdminClips = lazyPage(() => import("./pages/admin/AdminClips.tsx")) const AdminClips = lazyPage(() => import("./pages/admin/AdminClips.tsx"))
const AdminVideoFrames = lazyPage(() => import("./pages/admin/AdminVideoFrames.tsx"))
const AdminNewsletter = lazyPage(() => import("./pages/admin/AdminNewsletter.tsx")) const AdminNewsletter = lazyPage(() => import("./pages/admin/AdminNewsletter.tsx"))
const EntityList = lazyPage(() => import("./pages/admin/EntityList.tsx")) const EntityList = lazyPage(() => import("./pages/admin/EntityList.tsx"))
const EntityEdit = lazyPage(() => import("./pages/admin/EntityEdit.tsx")) const EntityEdit = lazyPage(() => import("./pages/admin/EntityEdit.tsx"))
@ -145,6 +146,9 @@ export default function App() {
<Route path="requests" element={<AdminFeedback kind="content" />} /> <Route path="requests" element={<AdminFeedback kind="content" />} />
<Route path="media" element={<AdminMedia />} /> <Route path="media" element={<AdminMedia />} />
<Route path="newsletter" element={<AdminNewsletter />} /> <Route path="newsletter" element={<AdminNewsletter />} />
<Route element={<RequireRole role="editor" />}>
<Route path="thumbnails" element={<AdminVideoFrames />} />
</Route>
<Route element={<RequireRole role="admin" />}> <Route element={<RequireRole role="admin" />}>
<Route path="clips" element={<AdminClips />} /> <Route path="clips" element={<AdminClips />} />
</Route> </Route>

View file

@ -647,8 +647,9 @@ export function ImageInput({
/* ── Frame from a video ──────────────────────────────────────── */ /* ── Frame from a video ──────────────────────────────────────── */
/* A link's own start time (YouTube's t=83 or t=83s), so a link /* A link's own start time (YouTube's t=83 or t=83s), so a link
copied at the moment wanted starts the picker there. */ copied at the moment wanted starts the picker there. Tools →
function startOf(url: string): number { Video thumbnails (AdminVideoFrames.tsx) reads it too. */
export function startOf(url: string): number {
try { try {
const t = new URL(url).searchParams.get("t") ?? ""; const t = new URL(url).searchParams.get("t") ?? "";
return /^\d+s?$/.test(t) ? parseInt(t, 10) : 0; return /^\d+s?$/.test(t) ? parseInt(t, 10) : 0;

View file

@ -107,6 +107,16 @@ export const frontPage = {
"A YouTube, Vimeo or Facebook link, or a video file: a filename in " + "A YouTube, Vimeo or Facebook link, or a video file: a filename in " +
"the uploads folder, or a link ending in .mp4 or .webm", "the uploads folder, or a link ending in .mp4 or .webm",
}, },
{
path: "video_still",
label: "Video still",
widget: "image",
crop: 16 / 9,
resolve: mediaUrl,
full: true,
frameFrom: "video_url",
help: "Shown before it plays. Default: YouTube's own thumbnail, or a video file's first frame. Frame at takes a still from a YouTube or Facebook video.",
},
{ {
path: "video_captions", path: "video_captions",
label: "Video captions", label: "Video captions",

View file

@ -408,8 +408,12 @@ export const blocksChild = {
resolve: mediaUrl, resolve: mediaUrl,
full: true, full: true,
when: { path: "type", value: ["image", "video"] }, when: { path: "type", value: ["image", "video"] },
frameFrom: "href",
frameWhen: { path: "type", value: "video" },
help: (row) => help: (row) =>
row?.type === "video" ? "Still shown before it plays. Default: YouTube's own thumbnail." : undefined, row?.type === "video"
? "Still shown before it plays. Default: YouTube's own thumbnail. Frame at takes a still from a YouTube or Facebook video."
: undefined,
}, },
{ {
path: "captions", path: "captions",

View file

@ -51,7 +51,8 @@ export type Hero = {
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. */ /** A link to embed or a video file; see videoSource in embeds.ts. */
video: { url: string; title?: string | null; captions?: string | null } | null /** `still` is shown before it plays; resolve it with mediaUrl. */
video: { url: string; title?: string | null; captions?: string | null; still?: string | null } | null
/** With the 'event' feature: the pinned event, else the countdown's. */ /** With the 'event' feature: the pinned event, else the countdown's. */
event: HeroEvent | null event: HeroEvent | null
} }

View file

@ -0,0 +1,171 @@
/* ═══════════════════════════════════════════════════════════════
ADMIN: VIDEO THUMBNAILS (Tools → Video thumbnails, editors and up)
Paste a YouTube or Facebook link and a time, and the server takes
that one frame (grabFrame in server/src/clips.js, the same as an
image field's Frame at) and saves it to the media library's
Previews folder (thumbnails/). A link's own t= fills in the time.
Frames taken here are listed until the page is left, each with a
full-size link, a download and its path to copy into a field.
They stay in the library (Tools → Media) after that.
═══════════════════════════════════════════════════════════════ */
import { useId, useState, type FormEvent } from "react";
import { Link } from "react-router-dom";
import { ApiError, post } from "../../lib/api.ts";
import { clock, parseClock } from "../../lib/clock.ts";
import { startOf, type MediaItem } from "../../components/admin/MediaLibrary.tsx";
const MUTED = "var(--color-muted)";
const button =
"btn border border-brand px-4 py-2 text-sm text-link transition-colors hover:bg-tint disabled:cursor-default disabled:opacity-50";
const primary =
"btn bg-action px-5 py-2.5 text-white transition-colors hover:bg-action-hover disabled:bg-muted/25";
const input =
"border border-muted/25 bg-surface px-3 py-2 text-sm text-body outline-none focus:border-brand focus:ring-2 focus:ring-brand/25";
type Taken = { media: MediaItem; url: string; seconds: number };
function Frame({ frame }: { frame: Taken }) {
const [copied, setCopied] = useState(false);
async function copy() {
try {
await navigator.clipboard.writeText(frame.media.url);
setCopied(true);
setTimeout(() => setCopied(false), 1500);
} catch {
setCopied(false);
}
}
return (
<li className="bg-raised shadow-md">
<a href={frame.media.url} target="_blank" rel="noopener noreferrer">
<img src={frame.media.url} alt="" className="aspect-video w-full bg-tint object-cover" />
</a>
<div className="space-y-3 p-4">
<div>
<p className="font-medium text-body">At {clock(frame.seconds)}</p>
<p className="truncate text-xs" style={{ color: MUTED }} title={frame.url}>
{frame.url}
</p>
{frame.media.width && frame.media.height && (
<p className="text-xs" style={{ color: MUTED }}>
{frame.media.width} × {frame.media.height}
</p>
)}
</div>
<div className="flex flex-wrap gap-2">
<a href={frame.media.url} download className={button}>
Download
</a>
<button type="button" className={button} onClick={copy}>
{copied ? "Copied" : "Copy path"}
</button>
</div>
</div>
</li>
);
}
export default function AdminVideoFrames() {
const [url, setUrl] = useState("");
const [time, setTime] = useState("0:00");
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [frames, setFrames] = useState<Taken[]>([]);
const urlId = useId();
const timeId = useId();
const seconds = parseClock(time);
// A pasted link that carries its own time (t=83) sets the box.
function changeUrl(next: string) {
setUrl(next);
const start = startOf(next.trim());
if (start > 0) setTime(clock(start));
}
async function take(e: FormEvent) {
e.preventDefault();
if (seconds == null) return;
setBusy(true);
setError(null);
try {
const link = url.trim();
const { media } = await post("/admin/video-frame", { url: link, seconds });
setFrames((list) => [{ media, url: link, seconds }, ...list]);
} catch (err) {
setError(err instanceof ApiError ? err.message : "Couldn't take that frame.");
} finally {
setBusy(false);
}
}
return (
<div>
<div className="flex flex-wrap items-baseline gap-3">
<h1 className="text-2xl font-bold text-link">Video thumbnails</h1>
<p className="text-sm" style={{ color: MUTED }}>
Take a still from one of our YouTube or Facebook videos at any moment.
</p>
</div>
<section className="mt-6 bg-raised p-5 shadow-md">
<form onSubmit={take} className="flex flex-wrap items-end gap-3">
<div className="min-w-0 flex-1">
<label htmlFor={urlId} className="block text-sm font-medium text-body">
Video link
</label>
<input
id={urlId}
type="url"
value={url}
onChange={(e) => changeUrl(e.target.value)}
placeholder="eg. https://www.youtube.com/watch?v=…"
className={`mt-1 w-full ${input}`}
/>
</div>
<div className="w-28">
<label htmlFor={timeId} className="block text-sm font-medium text-body">
Time
</label>
<input
id={timeId}
type="text"
value={time}
onChange={(e) => setTime(e.target.value)}
placeholder="eg. 1:23"
className={`mt-1 w-full ${input}`}
/>
</div>
<button type="submit" className={primary} disabled={busy || !url.trim() || seconds == null}>
{busy ? "Taking…" : "Take frame"}
</button>
</form>
<p className="mt-2 text-xs" style={{ color: MUTED }}>
YouTube and Facebook links only, and only videos NGU owns or has permission to use. A link copied with
its time (eg. Share → Start at) fills in the time. Frames are saved to{" "}
<Link to="/admin/media" className="text-link underline">
Media
</Link>{" "}
→ Previews.
</p>
{seconds == null && <p className="mt-2 text-sm text-danger">Write the time as seconds or m:ss, eg. 83 or 1:23.</p>}
{error && <p className="mt-2 text-sm text-danger">{error}</p>}
</section>
{frames.length > 0 && (
<ul className="mt-6 grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
{frames.map((frame) => (
<Frame key={frame.media.id} frame={frame} />
))}
</ul>
)}
</div>
);
}

View file

@ -190,6 +190,12 @@ export const TOOLS_NAV = {
blurb: "Cut clips from our YouTube and Facebook videos: trimmed, reshaped for Reels, or audio only.", blurb: "Cut clips from our YouTube and Facebook videos: trimmed, reshaped for Reels, or audio only.",
minRole: "admin", minRole: "admin",
}, },
{
to: "/admin/thumbnails",
label: "Video thumbnails",
blurb: "A still from one of our YouTube or Facebook videos at any moment, saved to the media library.",
minRole: "editor",
},
{ {
to: "/admin/newsletter", to: "/admin/newsletter",
label: "Newsletter", label: "Newsletter",

View file

@ -113,7 +113,13 @@ export default function HeroStage({ hero }: { hero: Hero | null }) {
{feature === 'video' && hero?.video && ( {feature === 'video' && hero?.video && (
<div className="lg:col-span-7"> <div className="lg:col-span-7">
<VideoFrame source={video} url={hero.video.url} title={hero.video.title} captions={mediaUrl(hero.video.captions)} /> <VideoFrame
source={video}
url={hero.video.url}
title={hero.video.title}
captions={mediaUrl(hero.video.captions)}
still={mediaUrl(hero.video.still)}
/>
</div> </div>
)} )}
@ -493,18 +499,22 @@ function LiveFrame({ src, url, title }: { src: string | null; url: string; title
"metadata" fetches enough for the first frame and the length, "metadata" fetches enough for the first frame and the length,
not the whole file. An embed is a VideoPlayer: a still until not the whole file. An embed is a VideoPlayer: a still until
pressed, so the video's host sets nothing before then. A link pressed, so the video's host sets nothing before then. A link
that is neither still gets a button out to it. */ that is neither still gets a button out to it. `still` is the
editor's chosen picture (074): the embed's still, or the file's
poster; without one, YouTube's thumbnail or the first frame. */
function VideoFrame({ function VideoFrame({
source, source,
url, url,
title, title,
captions, captions,
still,
}: { }: {
source: VideoSource | null source: VideoSource | null
url: string url: string
title?: string | null title?: string | null
/** A WebVTT file's URL; only a file plays it, an embed has its own. */ /** A WebVTT file's URL; only a file plays it, an embed has its own. */
captions?: string | null captions?: string | null
still?: string | null
}) { }) {
return ( return (
<div <div
@ -520,11 +530,12 @@ function VideoFrame({
controls controls
playsInline playsInline
preload="metadata" preload="metadata"
poster={still ?? undefined}
> >
{captions && <track kind="captions" src={captions} srcLang="en" label="Captions" default />} {captions && <track kind="captions" src={captions} srcLang="en" label="Captions" default />}
</video> </video>
) : source?.kind === 'embed' ? ( ) : source?.kind === 'embed' ? (
<VideoPlayer url={url} title={title || 'Featured video'} className="h-full" /> <VideoPlayer url={url} still={still} title={title || 'Featured video'} className="h-full" />
) : ( ) : (
<div className="flex h-full w-full items-center justify-center"> <div className="flex h-full w-full items-center justify-center">
<HomeLink <HomeLink