website 1.12.0: three layouts for each page that lists something

- PAGE_VARIANTS: ministriesPage alternating/cards/list, leadershipPage grid/featured/list,
  eventsPage list/cards/months, messagesPage grid/featured/list, contactPage
  columns/map/cards. Kept in the design's variants beside the homepage sections', so each
  template recommends some and starts a new site on the first (its suggestion), PUT /design
  checks them, and a template switch moves an untouched one.
- A design saved before has none: cleanDesign gives it LEGACY_PAGE_LAYOUTS (the look until
  now), and the site draws a snapshot without them the same way, so nothing changes until a
  church picks one. Contact's map layout without a place on the map draws as two columns.
  Ministries and messages keep their #slug anchors in every layout.
- Admin: the layout at the top of a listing page in Pages, the suggestion marked; Template
  and style gets an Other pages tab with all five.
- Tests: backend (156, five new); e2e page-layouts.spec.ts (every layout in every template,
  axe at phone and desktop; 60 passed).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 10:59:59 +02:00
co-authored by Claude Opus 5.5
parent 43187513d7
commit 777b045053
18 changed files with 620 additions and 126 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@crosscode/website-frontend",
"version": "1.11.0",
"version": "1.12.0",
"private": true,
"description": "Church Website: the church's public site in its template, and the admin",
"scripts": {
@@ -31,6 +31,29 @@ export function layoutsFor(design: Design, options: DesignOptions | undefined, s
return { ordered: [...recommended, ...(ALL_VARIANTS[section] ?? []).filter((v) => !recommended.includes(v))], recommended };
}
/**
* The layouts of what the fixed pages list (backend variants.ts PAGE_VARIANTS), keyed by page kind:
* the design's key for each, its name, and each layout's name in the order the backend lists them.
* Saved on the design like the homepage's (`variants.ministriesPage`), with the template's
* suggestions first.
*/
export const PAGE_LAYOUTS: Record<string, { key: string; name: string; layouts: Record<string, string> }> = {
ministries: { key: "ministriesPage", name: "Ministries", layouts: { alternating: "Alternating photo and text", cards: "Cards", list: "List with small photos" } },
leadership: { key: "leadershipPage", name: "Leadership", layouts: { grid: "Grid of faces", featured: "Lead pastor first", list: "List with photos" } },
events: { key: "eventsPage", name: "Events", layouts: { list: "List with dates", cards: "Cards with photos", months: "By month" } },
messages: { key: "messagesPage", name: "Messages", layouts: { grid: "Grid of videos", featured: "Latest first, then a list", list: "List" } },
contact: { key: "contactPage", name: "Contact", layouts: { columns: "Two columns", map: "With map", cards: "Cards" } },
};
/** A listing page's layouts, the ones that suit the template first, and which those are. */
export function pageLayoutsFor(design: Design, options: DesignOptions | undefined, kind: string): { key: string; ordered: string[]; recommended: string[]; names: Record<string, string> } | null {
const p = PAGE_LAYOUTS[kind];
if (!p) return null;
const recommended = options?.variants[design.template]?.[p.key] ?? [];
const all = Object.keys(p.layouts);
return { key: p.key, ordered: [...recommended.filter((v) => all.includes(v)), ...all.filter((v) => !recommended.includes(v))], recommended, names: p.layouts };
}
/** The other pages' blocks' layouts, the default first (backend variants.ts BLOCK_VARIANTS). */
export const BLOCK_LAYOUTS: Record<string, { id: string; name: string }[]> = {
text: [{ id: "standard", name: "Standard" }, { id: "centred", name: "Centred" }],
@@ -4,21 +4,22 @@
* One page (§6), with its live preview on the right. Content: the home page has one of each
* homepage section, each with its layout, background, place and whether it shows (also under
* Template and style), and only the photos its layout shows; every other page is built from blocks,
* which can be added, moved, hidden and removed. Page details: its
* which can be added, moved, hidden and removed, and a page that lists something (ministries,
* events...) chooses how it lists them. Page details: its
* title, address, menu and search engine details.
*/
import Link from "next/link";
import { useParams, useRouter } from "next/navigation";
import { useMemo, useState } from "react";
import {
ArrowDown, ArrowUp, CalendarDays, ChevronDown, ChevronRight, Clock, EyeOff, Eye, FileText, Heart, Image as ImageIcon, LayoutList, Megaphone, Mic,
ArrowDown, ArrowUp, CalendarDays, ChevronDown, ChevronRight, Clock, EyeOff, Eye, FileText, Heart, Image as ImageIcon, LayoutList, LayoutTemplate, Megaphone, Mic,
Plus, Quote, Search, Settings2, Sparkles, Trash2, Type, Users, HandHeart, type LucideIcon,
} from "lucide-react";
import { api } from "@/admin/api";
import { BLOCK_FIELDS, DataForm, SECTION_FIELDS } from "@/admin/fields";
import { frameFor, type Framing } from "@/admin/framing";
import { WithPreview } from "@/admin/LivePreview";
import { BACKGROUNDS, BLOCK_LAYOUTS, blockLayout, layoutsFor, moved, TEMPLATE_NAMES, VARIANT_NAMES, withBackground, withShown, type Design, type DesignOptions, type HomeEntry } from "@/admin/layouts";
import { BACKGROUNDS, BLOCK_LAYOUTS, blockLayout, layoutsFor, moved, pageLayoutsFor, TEMPLATE_NAMES, VARIANT_NAMES, withBackground, withShown, type Design, type DesignOptions, type HomeEntry } from "@/admin/layouts";
import { ImagePicker } from "@/admin/media";
import { Btn, cx, Field, inputClass, Loading, Notice, Panel, Tabs, Title, useAction, useAdmin } from "@/admin/ui";
@@ -33,6 +34,7 @@ const LISTS: Record<string, string> = {
messages: "This page lists your messages; blocks you add show after them.",
contact: "This page shows your church's contact details and service times from your church profile.",
};
const LIST_WHAT: Record<string, string> = { ministries: "your ministries", leadership: "your team", events: "your events", messages: "your messages", contact: "your contact details and service times" };
const ICONS: Record<string, LucideIcon> = {
hero: Sparkles, serviceTimes: Clock, welcome: Heart, ministries: HandHeart, team: Users, events: CalendarDays, latestMessage: Mic, invitation: Megaphone,
text: Type, "image-text": ImageIcon, quote: Quote, cta: Megaphone,
@@ -226,6 +228,19 @@ export default function EditPage() {
</div>
) : (
<div className="space-y-3">
{(() => {
// What this page lists has its own layout, on the design (as under Template and style), saved straight away.
const p = saved && pageLayoutsFor(saved, design.data?.options, page.kind);
if (!p) return null;
return (
<Panel title="Layout" icon={LayoutTemplate} sub={`How this page lists ${LIST_WHAT[page.kind] ?? "its content"}. Those marked suit ${TEMPLATE_NAMES[saved.template] ?? "your template"} best; every one works.`}>
<select aria-label="Page layout" className={inputClass} value={saved.variants[p.key] ?? p.ordered[0]} disabled={layouts.busy} onChange={(ev) => saveDesign({ variants: { [p.key]: ev.target.value } })}>
{p.ordered.map((v) => <option key={v} value={v}>{p.names[v]}{v === p.recommended[0] ? " (suggested for this template)" : p.recommended.includes(v) ? " (suits this template)" : ""}</option>)}
</select>
{layouts.message?.tone === "error" && <div className="mt-3"><Notice tone="error">{layouts.message.text}</Notice></div>}
</Panel>
);
})()}
{LISTS[page.kind] && <Notice>{LISTS[page.kind]}</Notice>}
{page.sections.length === 0 && <p className="rounded-xl border border-dashed border-gray-300 p-6 text-center text-sm text-gray-500">Nothing on this page yet: add a block below.</p>}
{page.sections.map((s, i) => {
@@ -1,16 +1,16 @@
"use client";
/**
* Template and style (WEBSITE-1.0-PLAN §3): the template, each homepage section's layout
* (recommended first), the homepage order, and the style settings. Fonts and corners are the
* Template and style (WEBSITE-1.0-PLAN §3): the template, each homepage section's layout and each
* listing page's (recommended first), the homepage order, and the style settings. Fonts and corners are the
* church's brand style, shared with its other sites, so they're set in its church profile.
*/
import Link from "next/link";
import { useState } from "react";
import { ArrowDown, ArrowUp, Check, Eye, LayoutTemplate, ListOrdered, Palette, SlidersHorizontal } from "lucide-react";
import { ArrowDown, ArrowUp, Check, Eye, Files, LayoutTemplate, ListOrdered, Palette, SlidersHorizontal } from "lucide-react";
import { api } from "@/admin/api";
import { WithPreview } from "@/admin/LivePreview";
import { BACKGROUNDS, layoutsFor, moved, SECTION_NAMES as SECTIONS, VARIANT_NAMES, withBackground, withShown, type Design, type DesignOptions as Options } from "@/admin/layouts";
import { BACKGROUNDS, layoutsFor, moved, PAGE_LAYOUTS, pageLayoutsFor, SECTION_NAMES as SECTIONS, VARIANT_NAMES, withBackground, withShown, type Design, type DesignOptions as Options } from "@/admin/layouts";
import { Btn, cx, Field, inputClass, Loading, Notice, Panel, Tabs, Title, useAction, useAdmin } from "@/admin/ui";
const TEMPLATES = [
@@ -34,7 +34,7 @@ const STYLE = [
export default function TemplatePage() {
const { data, error, setData } = useAdmin<{ design: Design; options: Options }>("/design");
const { busy, message, run } = useAction();
const [tab, setTab] = useState<"template" | "home" | "style">("template");
const [tab, setTab] = useState<"template" | "home" | "pages" | "style">("template");
if (!data) return <Loading error={error} />;
const { design, options } = data;
const save = (patch: Partial<Design> & { template?: string }, done = "Saved. Preview to see it, then publish.") => run(async () => {
@@ -53,6 +53,7 @@ export default function TemplatePage() {
<Tabs label="Template and style" value={tab} onChange={setTab} tabs={[
{ id: "template", label: "Template", icon: LayoutTemplate },
{ id: "home", label: "Home page layout", icon: ListOrdered },
{ id: "pages", label: "Other pages", icon: Files },
{ id: "style", label: "Style", icon: SlidersHorizontal },
]} />
@@ -116,6 +117,28 @@ export default function TemplatePage() {
</Panel>
)}
{tab === "pages" && (
<Panel title="Other pages: layouts" icon={Files} sub={<>How the pages that list something show it. Every layout works in every template; the first ones listed suit {TEMPLATES.find((t) => t.id === design.template)?.name} best, and the first of those is its suggestion. Each page&apos;s own blocks show after what it lists.</>}>
<ul className="divide-y divide-gray-100">
{Object.entries(PAGE_LAYOUTS).map(([kind, { name }]) => {
const p = pageLayoutsFor(design, options, kind)!;
return (
<li key={kind} className="flex flex-wrap items-center gap-3 py-3">
<span className="w-36 font-medium">{name}</span>
<select aria-label={`${name} page layout`} className={`${inputClass} w-72`} value={design.variants[p.key] ?? p.ordered[0]} disabled={busy}
onChange={(ev) => save({ variants: { [p.key]: ev.target.value } })}>
{p.ordered.map((v) => <option key={v} value={v}>{p.names[v]}{v === p.recommended[0] ? " (suggested)" : p.recommended.includes(v) ? " (suits this template)" : ""}</option>)}
</select>
{design.variants[p.key] !== p.recommended[0] && p.recommended[0] && (
<Btn disabled={busy} onClick={() => save({ variants: { [p.key]: p.recommended[0]! } })}>Use the suggestion</Btn>
)}
</li>
);
})}
</ul>
</Panel>
)}
{tab === "style" && (
<Panel title="Style" icon={SlidersHorizontal} sub="The finishing touches, on every page.">
<div className="grid gap-4 sm:grid-cols-2">
+327 -92
View File
@@ -3,11 +3,12 @@
* leaders, events, messages, contact details), then its blocks.
*/
import { preload } from "react-dom";
import { LazyMap } from "./LazyMap";
import { MessagePlayer } from "./MessagePlayer";
import { t } from "./load";
import { cx, DateBadge, dayName, fmtDate, Img, Paragraphs } from "./parts";
import { EventLine, Sections } from "./sections";
import type { Page, Published } from "./types";
import type { Page, Published, Template } from "./types";
function PageTitle({ page, site }: { page: Page; site: Published }) {
const template = site.snapshot.design.template;
@@ -21,98 +22,332 @@ function PageTitle({ page, site }: { page: Page; site: Published }) {
);
}
function Listing({ page, site }: { page: Page; site: Published }) {
const zone = site.church?.timezone ?? "Africa/Johannesburg";
const template = site.snapshot.design.template;
switch (page.kind) {
case "ministries":
return (
<section className="cc-section">
<div className="cc-wrap space-y-14">
{site.snapshot.ministries.map((m, i) => (
<article key={m.slug} id={m.slug} className="grid scroll-mt-24 items-center gap-8 md:grid-cols-2">
<Img image={m.image} className={cx(i % 2 === 1 && "md:order-2", template === "community" && "rounded-[2rem]")} />
<div><h2 className="cc-h2">{m.name}</h2>{m.summary && <p className="cc-muted mt-3 text-lg">{m.summary}</p>}<Paragraphs text={m.body} className="mt-4" /></div>
</article>
))}
</div>
</section>
);
case "leadership":
return (
<section className="cc-section">
<div className="cc-wrap grid gap-10 sm:grid-cols-2 lg:grid-cols-3">
{site.snapshot.leaders.map((l) => (
<article key={l.name}>
<Img image={l.photo} ratio="aspect-square" className={cx((template === "heritage" || template === "community") && "rounded-full", "mx-auto max-w-[14rem]")} />
<h2 className="cc-h3 mt-4 text-center">{l.name}</h2>
{l.role && <p className="cc-muted text-center">{l.role}</p>}
<Paragraphs text={l.bio} className="mt-3 !text-base" />
</article>
))}
</div>
</section>
);
case "events":
return (
<section className="cc-section">
<div className="cc-wrap">
{site.events.length === 0 && <p className="cc-muted">Nothing on the calendar just now. Check back soon.</p>}
<ul className="divide-y divide-gray-200">
{site.events.map((e) => (
<li key={e.url + e.startsAt} className="flex gap-5 py-6">
<DateBadge iso={e.startsAt} timeZone={zone} />
<div><h2 className="cc-h3"><a href={e.url} className="no-underline hover:underline">{e.title}</a></h2><EventLine e={e} timeZone={zone} />{e.summary && <p className="mt-2">{e.summary}</p>}</div>
</li>
))}
</ul>
</div>
</section>
);
case "messages": {
// The first thumbnail is the largest thing on screen (Lighthouse's LCP): ask for it from the
// <head>, rather than once the HTML has been read. Thumbnails come from the site itself.
const thumb = site.messages[0]?.thumbnail;
if (thumb) preload(thumb, { as: "image", fetchPriority: "high" });
return (
<section className="cc-section">
<div className="cc-wrap grid gap-10 sm:grid-cols-2">
{site.messages.map((m, i) => (
<article key={m.slug} id={m.slug} className="scroll-mt-24">
<MessagePlayer title={m.title} embedUrl={m.embedUrl} thumbnail={m.thumbnail} url={m.url} source={m.source} priority={i === 0} />
{m.series && <p className="cc-eyebrow mt-4">{m.series}</p>}
<h2 className="cc-h3 mt-1">{m.title}</h2>
<p className="cc-muted text-sm">{[m.speaker, m.passage, fmtDate(m.date, zone, { day: "numeric", month: "long", year: "numeric" })].filter(Boolean).join(" · ")}</p>
</article>
))}
</div>
</section>
);
}
case "contact": {
const c = site.church;
if (!c) return null;
const a = c.contact.address;
return (
<section className="cc-section">
<div className="cc-wrap grid gap-10 md:grid-cols-2">
<div className="space-y-6">
{a && <div><h2 className="cc-h3">Address</h2><address className="not-italic">{[a.line1, a.line2, a.suburb, a.city, a.postalCode].filter(Boolean).join(", ")}</address></div>}
{c.contact.phone && <div><h2 className="cc-h3">Phone</h2><a className="cc-link" href={`tel:${c.contact.phone}`}>{c.contact.phone}</a></div>}
{c.contact.whatsapp && <div><h2 className="cc-h3">WhatsApp</h2><a className="cc-link" href={`https://wa.me/${c.contact.whatsapp.replace(/\D/g, "")}`}>{c.contact.whatsapp}</a></div>}
{c.contact.email && <div><h2 className="cc-h3">Email</h2><a className="cc-link break-all" href={`mailto:${c.contact.email}`}>{c.contact.email}</a></div>}
</div>
<div>
<h2 className="cc-h3">Service times</h2>
<ul className="mt-2 space-y-1">{c.serviceTimes.map((s, i) => <li key={i}>{dayName(s.day)} {s.time}{s.label && ` · ${s.label}`}</li>)}</ul>
</div>
</div>
</section>
);
}
default:
return null;
/**
* The layout a listing page is drawn in (backend variants.ts PAGE_VARIANTS): the design's, or the
* look it had before it had layouts (LEGACY_PAGE_LAYOUTS) for a version published back then.
*/
const LEGACY: Record<string, string> = { ministries: "alternating", leadership: "grid", events: "list", messages: "grid", contact: "columns" };
const layoutOf = (site: Published, kind: string) => site.snapshot.design.variants[`${kind}Page`] ?? LEGACY[kind];
const roundPhoto = (template: Template) => template === "heritage" || template === "community";
// ─── Ministries: Alternating · Cards · List ──────────────────────────────────────
// Each ministry keeps its own anchor (#slug): the homepage's "Find out more" links to it.
function MinistriesPage({ site, template, layout }: Props) {
const list = site.snapshot.ministries;
if (layout === "cards") {
return (
<section className="cc-section">
<ul className="cc-wrap grid gap-8 sm:grid-cols-2 lg:grid-cols-3">
{list.map((m) => (
<li key={m.slug} id={m.slug} className="cc-card flex scroll-mt-24 flex-col">
<Img image={m.image} sizes="(min-width: 1024px) 33vw, (min-width: 640px) 50vw, 100vw" className="rounded-none" />
<div className="flex-1 p-6">
<h2 className="cc-h3">{m.name}</h2>
{m.summary && <p className="cc-muted mt-2 text-lg">{m.summary}</p>}
<Paragraphs text={m.body} className="mt-3 !text-base" />
</div>
</li>
))}
</ul>
</section>
);
}
if (layout === "list") {
return (
<section className="cc-section">
<div className={cx("cc-wrap divide-y", template === "heritage" ? "max-w-4xl divide-brand-text/20" : "divide-gray-200")}>
{list.map((m) => (
<article key={m.slug} id={m.slug} className="grid scroll-mt-24 gap-6 py-10 first:pt-0 last:pb-0 sm:grid-cols-[12rem_1fr]">
<Img image={m.image} sizes="12rem" ratio="aspect-square" className={cx("max-w-[12rem]", template === "community" && "rounded-[1.5rem]")} />
<div><h2 className="cc-h2">{m.name}</h2>{m.summary && <p className="cc-muted mt-2 text-lg">{m.summary}</p>}<Paragraphs text={m.body} className="mt-4" /></div>
</article>
))}
</div>
</section>
);
}
return (
<section className="cc-section">
<div className="cc-wrap space-y-14">
{list.map((m, i) => (
<article key={m.slug} id={m.slug} className="grid scroll-mt-24 items-center gap-8 md:grid-cols-2">
<Img image={m.image} className={cx(i % 2 === 1 && "md:order-2", template === "community" && "rounded-[2rem]")} />
<div><h2 className="cc-h2">{m.name}</h2>{m.summary && <p className="cc-muted mt-3 text-lg">{m.summary}</p>}<Paragraphs text={m.body} className="mt-4" /></div>
</article>
))}
</div>
</section>
);
}
// ─── Leadership: Grid · Featured · List ──────────────────────────────────────────
type Leader = Published["snapshot"]["leaders"][number];
function LeaderCard({ l, template }: { l: Leader; template: Template }) {
return (
<article>
<Img image={l.photo} sizes="14rem" ratio="aspect-square" className={cx(roundPhoto(template) && "rounded-full", "mx-auto max-w-[14rem]")} />
<h2 className="cc-h3 mt-4 text-center">{l.name}</h2>
{l.role && <p className="cc-muted text-center">{l.role}</p>}
<Paragraphs text={l.bio} className="mt-3 !text-base" />
</article>
);
}
function LeadershipPage({ site, template, layout }: Props) {
const people = site.snapshot.leaders;
if (layout === "list") {
return (
<section className="cc-section">
<div className="cc-wrap max-w-4xl divide-y divide-gray-200">
{people.map((l) => (
<article key={l.name} className="grid gap-6 py-8 first:pt-0 last:pb-0 sm:grid-cols-[9rem_1fr]">
<Img image={l.photo} sizes="9rem" ratio="aspect-square" className={cx("max-w-[9rem]", roundPhoto(template) && "rounded-full")} />
<div><h2 className="cc-h3">{l.name}</h2>{l.role && <p className="cc-muted">{l.role}</p>}<Paragraphs text={l.bio} className="mt-3 !text-base" /></div>
</article>
))}
</div>
</section>
);
}
if (layout === "featured" && people.length > 0) {
const [lead, ...rest] = people as [Leader, ...Leader[]];
return (
<section className="cc-section">
<div className="cc-wrap">
<article className="grid items-center gap-10 md:grid-cols-[2fr_3fr]">
<Img image={lead.photo} sizes="(min-width: 768px) 40vw, 100vw" ratio="aspect-[4/5]" className={cx("mx-auto w-full max-w-sm", template === "community" && "rounded-[2rem]")} />
<div>
<h2 className="cc-h2">{lead.name}</h2>
{lead.role && <p className="cc-eyebrow mt-2">{lead.role}</p>}
<Paragraphs text={lead.bio} className="mt-5" />
</div>
</article>
{rest.length > 0 && <div className="mt-16 grid gap-10 sm:grid-cols-2 lg:grid-cols-3">{rest.map((l) => <LeaderCard key={l.name} l={l} template={template} />)}</div>}
</div>
</section>
);
}
return (
<section className="cc-section">
<div className="cc-wrap grid gap-10 sm:grid-cols-2 lg:grid-cols-3">
{people.map((l) => <LeaderCard key={l.name} l={l} template={template} />)}
</div>
</section>
);
}
// ─── Events: List · Cards · By month ─────────────────────────────────────────────
function EventsPage({ site, zone, layout }: Props) {
const list = site.events;
if (list.length === 0) return <section className="cc-section"><div className="cc-wrap"><p className="cc-muted">Nothing on the calendar just now. Check back soon.</p></div></section>;
if (layout === "cards") {
return (
<section className="cc-section">
<ul className="cc-wrap grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
{list.map((e) => (
<li key={e.url + e.startsAt} className="cc-card flex flex-col">
<div className="relative">
<Img image={e.image} sizes="(min-width: 1024px) 33vw, (min-width: 640px) 50vw, 100vw" ratio="aspect-[16/10]" className="rounded-none" />
<DateBadge iso={e.startsAt} timeZone={zone} className="absolute left-4 top-4 shadow" />
</div>
<div className="flex flex-1 flex-col p-5">
<h2 className="cc-h3"><a href={e.url} className="no-underline hover:underline">{e.title}</a></h2>
<div className="mt-2"><EventLine e={e} timeZone={zone} /></div>
{e.summary && <p className="mt-3">{e.summary}</p>}
</div>
</li>
))}
</ul>
</section>
);
}
if (layout === "months") {
const months: { name: string; events: typeof list }[] = [];
for (const e of list) {
const name = fmtDate(e.startsAt, zone, { month: "long", year: "numeric" });
if (months.at(-1)?.name === name) months.at(-1)!.events.push(e);
else months.push({ name, events: [e] });
}
return (
<section className="cc-section">
<div className="cc-wrap max-w-4xl space-y-12">
{months.map((m) => (
<div key={m.name}>
<h2 className="cc-h2 border-b-2 border-brand pb-2">{m.name}</h2>
<ul className="divide-y divide-gray-200">
{m.events.map((e) => (
<li key={e.url + e.startsAt} className="grid grid-cols-[3.5rem_1fr] gap-4 py-5">
<p className="text-center" aria-hidden="true">
<span className="font-heading cc-brand-text block text-3xl font-bold leading-none">{fmtDate(e.startsAt, zone, { day: "numeric" })}</span>
<span className="cc-eyebrow mt-1 block text-xs">{fmtDate(e.startsAt, zone, { weekday: "short" })}</span>
</p>
<div><h3 className="cc-h3"><a href={e.url} className="no-underline hover:underline">{e.title}</a></h3><EventLine e={e} timeZone={zone} />{e.summary && <p className="mt-2">{e.summary}</p>}</div>
</li>
))}
</ul>
</div>
))}
</div>
</section>
);
}
return (
<section className="cc-section">
<div className="cc-wrap">
<ul className="divide-y divide-gray-200">
{list.map((e) => (
<li key={e.url + e.startsAt} className="flex gap-5 py-6">
<DateBadge iso={e.startsAt} timeZone={zone} />
<div><h2 className="cc-h3"><a href={e.url} className="no-underline hover:underline">{e.title}</a></h2><EventLine e={e} timeZone={zone} />{e.summary && <p className="mt-2">{e.summary}</p>}</div>
</li>
))}
</ul>
</div>
</section>
);
}
// ─── Messages: Grid · Latest first · List ────────────────────────────────────────
// Each message keeps its own anchor (#slug).
type Message = Published["messages"][number];
const messageMeta = (m: Message, zone: string) => [m.speaker, m.passage, fmtDate(m.date, zone, { day: "numeric", month: "long", year: "numeric" })].filter(Boolean).join(" · ");
/** A message as a row: its thumbnail, words and a link to watch or listen where it's published. */
function MessageRow({ m, zone, first }: { m: Message; zone: string; first: boolean }) {
return (
<li id={m.slug} className="grid scroll-mt-24 items-center gap-5 py-6 sm:grid-cols-[12rem_1fr_auto]">
<div className="cc-frame aspect-video max-w-[12rem]">
{m.thumbnail
? <img src={m.thumbnail} alt="" width={320} height={180} loading={first ? "eager" : "lazy"} decoding="async" className="cc-img" />
: <div aria-hidden="true" className="h-full w-full bg-gradient-to-br from-brand/25 via-brand-tint to-accent/30" />}
</div>
<div>
{m.series && <p className="cc-eyebrow">{m.series}</p>}
<h2 className="cc-h3 mt-1">{m.title}</h2>
<p className="cc-muted text-sm">{messageMeta(m, zone)}</p>
</div>
<a href={m.url} rel="noopener" className="cc-btn justify-self-start">{m.source === "spotify" ? "Listen" : "Watch"}<span className="sr-only">: {m.title}</span></a>
</li>
);
}
function MessagesPage({ site, zone, layout }: Props) {
const list = site.messages;
// The first thumbnail is the largest thing on screen (Lighthouse's LCP): ask for it from the
// <head>, rather than once the HTML has been read. Thumbnails come from the site itself.
const thumb = list[0]?.thumbnail;
if (thumb) preload(thumb, { as: "image", fetchPriority: "high" });
if (layout === "list") {
return <section className="cc-section"><ul className="cc-wrap max-w-5xl divide-y divide-gray-200">{list.map((m, i) => <MessageRow key={m.slug} m={m} zone={zone} first={i === 0} />)}</ul></section>;
}
if (layout === "featured" && list.length > 0) {
const [latest, ...rest] = list as [Message, ...Message[]];
return (
<section className="cc-section">
<div className="cc-wrap">
<article id={latest.slug} className="scroll-mt-24">
<p className="cc-eyebrow mb-3">Latest message</p>
<MessagePlayer title={latest.title} embedUrl={latest.embedUrl} thumbnail={latest.thumbnail} url={latest.url} source={latest.source} priority />
{latest.series && <p className="cc-eyebrow mt-6">{latest.series}</p>}
<h2 className="cc-h2 mt-1">{latest.title}</h2>
<p className="cc-muted mt-2">{messageMeta(latest, zone)}</p>
</article>
{rest.length > 0 && <ul className="mt-12 divide-y divide-gray-200 border-t border-gray-200">{rest.map((m) => <MessageRow key={m.slug} m={m} zone={zone} first={false} />)}</ul>}
</div>
</section>
);
}
return (
<section className="cc-section">
<div className="cc-wrap grid gap-10 sm:grid-cols-2">
{list.map((m, i) => (
<article key={m.slug} id={m.slug} className="scroll-mt-24">
<MessagePlayer title={m.title} embedUrl={m.embedUrl} thumbnail={m.thumbnail} url={m.url} source={m.source} priority={i === 0} />
{m.series && <p className="cc-eyebrow mt-4">{m.series}</p>}
<h2 className="cc-h3 mt-1">{m.title}</h2>
<p className="cc-muted text-sm">{messageMeta(m, zone)}</p>
</article>
))}
</div>
</section>
);
}
// ─── Contact: Two columns · With map · Cards ─────────────────────────────────────
function ContactPage({ site, layout }: Props) {
const c = site.church;
if (!c) return null;
const a = c.contact.address;
const address = a ? [a.line1, a.line2, a.suburb, a.city, a.postalCode].filter(Boolean).join(", ") : null;
const directions = a && (a.geo
? `https://www.openstreetmap.org/?mlat=${a.geo.lat}&mlon=${a.geo.lng}#map=17/${a.geo.lat}/${a.geo.lng}`
: `https://www.openstreetmap.org/search?query=${encodeURIComponent([a.line1, a.suburb, a.city].filter(Boolean).join(", "))}`);
const ways = [
address && { key: "address", title: "Address", body: <><address className="not-italic">{address}</address>{layout !== "columns" && directions && <a href={directions} rel="noopener" className="cc-link mt-2 inline-block font-semibold">Get directions</a>}</> },
c.contact.phone && { key: "phone", title: "Phone", body: <a className="cc-link" href={`tel:${c.contact.phone}`}>{c.contact.phone}</a> },
c.contact.whatsapp && { key: "whatsapp", title: "WhatsApp", body: <a className="cc-link" href={`https://wa.me/${c.contact.whatsapp.replace(/\D/g, "")}`}>{c.contact.whatsapp}</a> },
c.contact.email && { key: "email", title: "Email", body: <a className="cc-link break-all" href={`mailto:${c.contact.email}`}>{c.contact.email}</a> },
].filter((w): w is { key: string; title: string; body: React.ReactElement } => !!w);
const times = (
<div>
<h2 className="cc-h3">Service times</h2>
<ul className="mt-2 space-y-1">{c.serviceTimes.map((s, i) => <li key={i}>{dayName(s.day)} {s.time}{s.label && ` · ${s.label}`}</li>)}</ul>
</div>
);
if (layout === "cards") {
return (
<section className="cc-section">
<ul className="cc-wrap grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
{ways.map((w) => <li key={w.key} className="cc-card p-6"><h2 className="cc-h3 mb-2">{w.title}</h2>{w.body}</li>)}
{c.serviceTimes.length > 0 && <li className="cc-card p-6">{times}</li>}
</ul>
</section>
);
}
const geo = a?.geo;
if (layout === "map" && geo) {
return (
<section className="cc-section">
<div className="cc-wrap grid items-stretch gap-10 md:grid-cols-2">
<div className="space-y-6">
{ways.map((w) => <div key={w.key}><h2 className="cc-h3">{w.title}</h2>{w.body}</div>)}
{times}
</div>
<LazyMap href={directions}
src={`https://www.openstreetmap.org/export/embed.html?bbox=${geo.lng - 0.006}%2C${geo.lat - 0.004}%2C${geo.lng + 0.006}%2C${geo.lat + 0.004}&layer=mapnik&marker=${geo.lat}%2C${geo.lng}`} />
</div>
</section>
);
}
// Two columns (and With map when the church's address has no place on the map yet).
return (
<section className="cc-section">
<div className="cc-wrap grid gap-10 md:grid-cols-2">
<div className="space-y-6">{ways.map((w) => <div key={w.key}><h2 className="cc-h3">{w.title}</h2>{w.body}</div>)}</div>
{times}
</div>
</section>
);
}
type Props = { site: Published; template: Template; zone: string; layout: string };
const LISTINGS: Record<string, (p: Props) => React.ReactNode> = {
ministries: MinistriesPage, leadership: LeadershipPage, events: EventsPage, messages: MessagesPage, contact: ContactPage,
};
function Listing({ page, site }: { page: Page; site: Published }) {
const L = LISTINGS[page.kind];
if (!L) return null;
return <L site={site} template={site.snapshot.design.template} zone={site.church?.timezone ?? "Africa/Johannesburg"} layout={layoutOf(site, page.kind) ?? ""} />;
}
export function PageView({ page, site }: { page: Page; site: Published }) {