Replace the front page with an admin-driven home
The home page is rebuilt from scratch and configured from a new Front page tab in the admin, backed by migration 017 and served by GET /api/front-page. Hero: brand, photos (crossfading slideshow with progress and pause) or livestream (YouTube/Facebook/Vimeo embed with a LIVE badge), switched by hand. After it, bands the admin can reorder, retitle or hide: a countdown to the next event (series-aware), the National Retreats carousel, a numbers band (typed in or counted from the database), a horizontal rail of featured timeline entries, and a "Find your way in" pathfinder replacing the old connect section. The CRUD engine gains a `singleton` flag: the entity has one row, made by its migration, and create and delete are refused. The list screen opens that row and the editor drops the slug, back link and delete. shapeSeries moves to shape.js so /front-page can share it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b4b013209b
commit
6a69084de2
25 changed files with 2299 additions and 494 deletions
6
src/lib/adminSchema.d.ts
vendored
6
src/lib/adminSchema.d.ts
vendored
|
|
@ -94,6 +94,9 @@ export type EntitySpec = {
|
|||
idLabel: string;
|
||||
/** "auto": the table assigns the id, so the form shows it rather than asking. */
|
||||
idKind?: "auto";
|
||||
/** The one id a singleton entity has. The list opens it directly,
|
||||
* and the editor offers no slug, back link or delete. */
|
||||
singleton?: string;
|
||||
/** Field(s) the slug is composed from. Absent when idKind is "auto". */
|
||||
slugFrom?: string | string[];
|
||||
titleFrom?: string;
|
||||
|
|
@ -108,7 +111,8 @@ export type AdminEntityKey =
|
|||
| "people"
|
||||
| "teams"
|
||||
| "awards"
|
||||
| "timeline";
|
||||
| "timeline"
|
||||
| "front_page";
|
||||
|
||||
/* Indexed by route param as often as by name, so any other string
|
||||
reads as possibly missing. */
|
||||
|
|
|
|||
|
|
@ -941,7 +941,201 @@ const timeline = {
|
|||
],
|
||||
};
|
||||
|
||||
export const ADMIN_ENTITIES = { organizations, events, people, teams, awards, timeline };
|
||||
/* ── Front page ──────────────────────────────────────────────────
|
||||
|
||||
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.
|
||||
|
||||
Section keys and stat sources are the CHECK lists in migration
|
||||
017. The labels here are what the admin reads; the values are
|
||||
what the page and the API key on. */
|
||||
|
||||
const FRONT_PAGE_SECTIONS = [
|
||||
["countdown", "Countdown to the next event"],
|
||||
["retreats", "National Retreats carousel"],
|
||||
["stats", "Numbers"],
|
||||
["timeline", "Featured timeline"],
|
||||
["connect", "Find your way in"],
|
||||
];
|
||||
|
||||
const STAT_SOURCES = [
|
||||
["manual", "Typed in — shows Value"],
|
||||
["years_since", "Years since — Value is the year"],
|
||||
["regions", "Count: published regions"],
|
||||
["chapters", "Count: published chapters"],
|
||||
["partners", "Count: published partners"],
|
||||
["events_held", "Count: past events"],
|
||||
["retreats_held", "Count: past retreats"],
|
||||
["people", "Count: published people"],
|
||||
["awards_given", "Count: public awards given"],
|
||||
];
|
||||
|
||||
const frontPage = {
|
||||
key: "front_page",
|
||||
label: "Front page",
|
||||
singular: "front page",
|
||||
idLabel: "Page",
|
||||
singleton: "home",
|
||||
|
||||
list: { columns: [], filters: [] },
|
||||
|
||||
groups: [
|
||||
{
|
||||
legend: "Hero",
|
||||
note: "The first thing a visitor sees. Blank buttons don't render.",
|
||||
fields: [
|
||||
{
|
||||
path: "hero_mode",
|
||||
label: "Mode",
|
||||
widget: "select",
|
||||
options: [
|
||||
["brand", "Brand — animated colour, no media"],
|
||||
["photos", "Photos — cycles through the photos below"],
|
||||
["livestream", "Livestream — embeds the stream with a LIVE badge"],
|
||||
],
|
||||
blankLabel: "— brand —",
|
||||
help: "Switch to Livestream when you go live, and back when you're done",
|
||||
},
|
||||
{ path: "eyebrow", label: "Eyebrow", help: "Small line above the headline" },
|
||||
{ path: "headline", label: "Headline", full: true },
|
||||
{ path: "subhead", label: "Subhead", widget: "textarea", full: true },
|
||||
{ path: "primary_label", label: "Main button label" },
|
||||
{ path: "primary_url", label: "Main button link", help: "/retreats, #connect or a full URL" },
|
||||
{ path: "secondary_label", label: "Second button label" },
|
||||
{ path: "secondary_url", label: "Second button link" },
|
||||
],
|
||||
},
|
||||
{
|
||||
legend: "Photos and livestream",
|
||||
fields: [
|
||||
{
|
||||
path: "slide_seconds",
|
||||
label: "Seconds per photo",
|
||||
widget: "number",
|
||||
help: "Photos mode. 3 to 60",
|
||||
},
|
||||
{
|
||||
path: "livestream_url",
|
||||
label: "Livestream link",
|
||||
full: true,
|
||||
help: "A YouTube, Facebook or Vimeo link, or any embed URL",
|
||||
},
|
||||
{ path: "livestream_title", label: "Livestream title", full: true },
|
||||
],
|
||||
},
|
||||
{
|
||||
legend: "Countdown",
|
||||
fields: [
|
||||
{
|
||||
path: "countdown_event_id",
|
||||
label: "Count down to",
|
||||
widget: "select",
|
||||
optionsFrom: "events",
|
||||
blankLabel: "— the next upcoming event —",
|
||||
help: "Leave blank almost always. A pinned event that's over falls back to the next one",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
children: [
|
||||
{
|
||||
key: "sections",
|
||||
label: "Page sections",
|
||||
note: "Drag to reorder. Each section can appear once; leave one out to drop it.",
|
||||
addLabel: "Add section",
|
||||
title: (row) =>
|
||||
FRONT_PAGE_SECTIONS.find(([key]) => key === row.section)?.[1] ?? "New section",
|
||||
blank: { section: "", title: "", blurb: "" },
|
||||
fields: [
|
||||
{
|
||||
path: "section",
|
||||
label: "Section",
|
||||
widget: "select",
|
||||
options: FRONT_PAGE_SECTIONS,
|
||||
required: true,
|
||||
},
|
||||
{ path: "title", label: "Heading", help: "Blank for the section's own" },
|
||||
{ path: "blurb", label: "Blurb", full: true },
|
||||
{ path: "is_hidden", label: "Hidden", widget: "checkbox", help: "Hide for now" },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: "slides",
|
||||
label: "Hero photos",
|
||||
note: "Shown in Photos mode, in this order.",
|
||||
addLabel: "Add photo",
|
||||
title: (row) => row.caption || row.media || "New photo",
|
||||
blank: { media: "", alt: "", caption: "" },
|
||||
fields: [
|
||||
{ path: "media", label: "Photo", required: true, help: "Filename in public/front-page/, or a URL" },
|
||||
{ path: "alt", label: "Description", help: "For screen readers" },
|
||||
{ path: "caption", label: "Caption", full: true },
|
||||
{ path: "link_url", label: "Link", help: "Optional; makes the caption a link" },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: "stats",
|
||||
label: "Numbers",
|
||||
note: "Counts update themselves. A typed-in number with no value is left out.",
|
||||
addLabel: "Add number",
|
||||
title: (row) => row.label || "New number",
|
||||
blank: { label: "", source: "", value: "" },
|
||||
fields: [
|
||||
{ path: "label", label: "Label", required: true },
|
||||
{
|
||||
path: "source",
|
||||
label: "Where it comes from",
|
||||
widget: "select",
|
||||
options: STAT_SOURCES,
|
||||
blankLabel: "— typed in —",
|
||||
},
|
||||
{ path: "value", label: "Value", help: "Typed in: the number. Years since: the year" },
|
||||
{ path: "suffix", label: "Suffix", help: "+, k, % …" },
|
||||
{ path: "note", label: "Note", full: true },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: "paths",
|
||||
label: "Find your way in",
|
||||
note: "Each path is a choice a visitor can pick; its actions appear when they do.",
|
||||
addLabel: "Add path",
|
||||
title: (row) => [row.icon, row.label].filter(Boolean).join(" ") || "New path",
|
||||
blank: { label: "", icon: "", blurb: "" },
|
||||
fields: [
|
||||
{ path: "label", label: "Label", required: true, help: "Attend, Serve…" },
|
||||
{ path: "icon", label: "Icon", help: "One emoji" },
|
||||
{ path: "blurb", label: "Blurb", full: true },
|
||||
],
|
||||
children: [
|
||||
{
|
||||
key: "actions",
|
||||
label: "Actions",
|
||||
addLabel: "Add action",
|
||||
title: (row) => row.label || "New action",
|
||||
blank: { label: "", url: "" },
|
||||
fields: [
|
||||
{ path: "label", label: "Label", required: true },
|
||||
{ path: "url", label: "Link", required: true },
|
||||
{ path: "description", label: "Description", full: true },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const ADMIN_ENTITIES = {
|
||||
organizations,
|
||||
events,
|
||||
people,
|
||||
teams,
|
||||
awards,
|
||||
timeline,
|
||||
front_page: frontPage,
|
||||
};
|
||||
|
||||
export function slugify(value) {
|
||||
return String(value ?? "")
|
||||
|
|
|
|||
62
src/lib/embeds.ts
Normal file
62
src/lib/embeds.ts
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
EMBEDS
|
||||
|
||||
Turns the link an admin pastes into the URL an <iframe> can
|
||||
load. People paste the page they're looking at — a YouTube watch
|
||||
or live link, a Facebook video, a Vimeo page — not the embed
|
||||
form, so those are recognised and rewritten. Anything else that
|
||||
is https is assumed to already be an embed URL and passed
|
||||
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.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
function youtubeId(url: URL): string | null {
|
||||
const host = url.hostname.replace(/^www\.|^m\./, '')
|
||||
if (host === 'youtu.be') return url.pathname.slice(1) || null
|
||||
if (host !== 'youtube.com' && host !== 'youtube-nocookie.com') return null
|
||||
|
||||
const v = url.searchParams.get('v')
|
||||
if (v) return v
|
||||
|
||||
// /live/ID, /embed/ID, /shorts/ID
|
||||
const match = url.pathname.match(/^\/(?:live|embed|shorts)\/([\w-]+)/)
|
||||
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 {
|
||||
if (!raw) return null
|
||||
|
||||
let url: URL
|
||||
try {
|
||||
url = new URL(raw.trim())
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
if (url.protocol !== 'https:') return null
|
||||
|
||||
const yt = youtubeId(url)
|
||||
if (yt) {
|
||||
return `https://www.youtube-nocookie.com/embed/${encodeURIComponent(yt)}?autoplay=1&mute=1&playsinline=1`
|
||||
}
|
||||
|
||||
const host = url.hostname.replace(/^www\./, '')
|
||||
|
||||
if (host === 'vimeo.com') {
|
||||
const id = url.pathname.match(/^\/(?:event\/)?(\d+)/)?.[1]
|
||||
if (id) {
|
||||
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`
|
||||
}
|
||||
}
|
||||
|
||||
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`
|
||||
}
|
||||
|
||||
return url.href
|
||||
}
|
||||
|
|
@ -31,6 +31,10 @@ export const orgLogo = inDir('/org-logos') // ⚠ guess
|
|||
export const teamLogo = inDir('/team-logos') // ⚠ guess
|
||||
export const awardLogo = inDir('/award-logos') // ⚠ guess
|
||||
|
||||
/* front_page_slides.media — the home page hero's photos. New with
|
||||
the Front page editor, which names the directory in its help. */
|
||||
export const heroPhoto = 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
|
||||
|
|
|
|||
89
src/lib/useFrontPage.ts
Normal file
89
src/lib/useFrontPage.ts
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
FRONT PAGE DATA
|
||||
|
||||
GET /front-page, as routes/home.js shapes it: the hero, the
|
||||
visible sections in order, counted stats, paths with actions,
|
||||
and the countdown's event. Edited in the admin under Front page.
|
||||
|
||||
No fallback content. If the request fails the page says so — a
|
||||
plausible default home page would hide a broken server behind
|
||||
something that looks fine.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useRecord, type Resource } from './useRecord.ts'
|
||||
import type { EventSeries } from './eventSeries.ts'
|
||||
|
||||
export type HeroMode = 'brand' | 'photos' | 'livestream'
|
||||
|
||||
/** The CHECK list on front_page_sections.section. */
|
||||
export type FrontPageSectionKey = 'countdown' | 'retreats' | 'stats' | 'timeline' | 'connect'
|
||||
|
||||
export type HeroButton = { label: string; url: string }
|
||||
|
||||
export type HeroSlide = {
|
||||
media: string
|
||||
alt?: string | null
|
||||
caption?: string | null
|
||||
link_url?: string | null
|
||||
}
|
||||
|
||||
export type Hero = {
|
||||
mode: HeroMode
|
||||
eyebrow?: string | null
|
||||
headline: string
|
||||
subhead?: string | null
|
||||
primary: HeroButton | null
|
||||
secondary: HeroButton | null
|
||||
slide_seconds: number
|
||||
slides: HeroSlide[]
|
||||
livestream: { url: string; title?: string | null } | null
|
||||
}
|
||||
|
||||
export type FrontPageSection = {
|
||||
section: FrontPageSectionKey
|
||||
/** Null → the section's own heading. */
|
||||
title?: string | null
|
||||
blurb?: string | null
|
||||
}
|
||||
|
||||
export type FrontPageStat = {
|
||||
label: string
|
||||
/** Already counted or typed; never null — the API drops those. */
|
||||
value: string
|
||||
suffix?: string | null
|
||||
note?: string | null
|
||||
}
|
||||
|
||||
export type PathAction = { label: string; description?: string | null; url: string }
|
||||
|
||||
export type FrontPagePath = {
|
||||
label: string
|
||||
icon?: string | null
|
||||
blurb?: string | null
|
||||
actions: PathAction[]
|
||||
}
|
||||
|
||||
export type CountdownEvent = {
|
||||
id: string
|
||||
title: string
|
||||
theme?: string | null
|
||||
starts_on?: string | null
|
||||
ends_on?: string | null
|
||||
date_label?: string | null
|
||||
location_label?: string | null
|
||||
is_online: boolean
|
||||
color?: string | null
|
||||
event_logo?: string | null
|
||||
series: EventSeries | null
|
||||
}
|
||||
|
||||
export type FrontPage = {
|
||||
hero: Hero
|
||||
sections: FrontPageSection[]
|
||||
stats: FrontPageStat[]
|
||||
paths: FrontPagePath[]
|
||||
countdown: CountdownEvent | null
|
||||
}
|
||||
|
||||
export const useFrontPage = (): Resource<FrontPage> =>
|
||||
useRecord<FrontPage>('/front-page', 'front_page')
|
||||
Loading…
Add table
Add a link
Reference in a new issue