Files
crosscode-platform/apps/website/frontend/src/site/sections/index.tsx
T
joshuaandClaude Opus 5.5 5ed7201efa feat(website): the four templates and the public site
Heritage, Bold, Community and Clean drawing all 26 section variants
with their headers, homepage order and style settings; colours made
safe (WCAG AA) by the backend; fonts and corners from the shared brand
style. Publishing into numbered versions, the content API with live
messages and events and the church profile from Accounts, uploads,
every page kind, simple event pages, Coming soon, 404, sitemap, SEO
basics and the church's JSON-LD. The demo church (npm run demo) and
Playwright e2e: every template's pages pass axe and the SEO checks.
website.sh builds packages/seo. Decision 17 (first Owner) recorded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 10:59:03 +02:00

479 lines
22 KiB
TypeScript

/**
* The homepage sections after the hero (WEBSITE-1.0-PLAN §3), each in its variants. Templates
* restyle the same markup through globals.css (cc-* classes) and the `t()` choices here.
*/
import { MessagePlayer } from "../MessagePlayer";
import { media, str, t } from "../load";
import { Button, cx, DateBadge, dayName, fmtDate, fmtTime, Img, Paragraphs, SectionHeading, type ButtonData } from "../parts";
import type { SectionProps, SiteEvent } from "../types";
import { Hero } from "./Hero";
const Section = ({ children, className, id }: { children: React.ReactNode; className?: string; id?: string }) => (
<section id={id} className={cx("cc-section", className)}>{children}</section>
);
const tz = (p: SectionProps) => p.site.church?.timezone ?? "Africa/Johannesburg";
// ─── Service times and location: Panel · Inline strip · With map ─────────────────
function addressLines(p: SectionProps): string[] {
const a = p.site.church?.contact.address;
return a ? [a.line1, a.line2, [a.suburb, a.city].filter(Boolean).join(", ")].filter((x): x is string => !!x) : [];
}
function directions(p: SectionProps): string | null {
const a = p.site.church?.contact.address;
if (!a) return null;
return 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(", "))}`;
}
function Times({ p, className }: { p: SectionProps; className?: string }) {
const times = p.site.church?.serviceTimes ?? [];
if (!times.length) return <p className="cc-muted">Service times are coming soon.</p>;
return (
<ul className={cx("space-y-3", className)}>
{times.map((s, i) => (
<li key={i} className="flex flex-wrap items-baseline gap-x-3">
<span className="font-heading text-2xl font-semibold tabular-nums">{s.time}</span>
<span>{dayName(s.day)}{s.label && <> · {s.label}</>}</span>
{s.note && <span className="cc-muted w-full text-sm">{s.note}</span>}
</li>
))}
</ul>
);
}
function ServiceTimes(p: SectionProps) {
const d = p.section.data as { heading: string | null; note: string | null };
const lines = addressLines(p);
const dir = directions(p);
const heading = d.heading ?? "Service times";
if (p.section.variant === "strip") {
const sundays = (p.site.church?.serviceTimes ?? []).filter((s) => s.day === "sunday").map((s) => s.time);
return (
<section className={cx("cc-section cc-own-bg !py-6", t(p.template, { bold: "cc-dark bg-brand text-brand-on", clean: "border-y border-gray-200", heritage: "bg-brand-tint", community: "bg-brand-tint" }))}>
<div className="cc-wrap flex flex-col items-start gap-3 sm:flex-row sm:items-center sm:justify-between">
<p className="text-lg"><strong className="font-heading">{heading}:</strong> {sundays.length ? `Sundays ${sundays.join(" & ")}` : "see below"}{lines[0] && <> · {lines.join(", ")}</>}</p>
{dir && <a href={dir} rel="noopener" className="cc-link shrink-0 whitespace-nowrap font-semibold underline underline-offset-4">Get directions</a>}
</div>
</section>
);
}
const panel = (
<div className={cx("p-8", t(p.template, { heritage: "border-4 border-double border-brand-text/40 text-center", bold: "bg-gray-950 text-white", community: "cc-card", clean: "border-l-4 border-accent" }))}>
<h2 className="cc-h2 mb-6">{heading}</h2>
<Times p={p} className={p.template === "heritage" ? "inline-block text-left" : ""} />
{d.note && <p className="cc-muted mt-6">{d.note}</p>}
{lines.length > 0 && (
<address className="mt-6 not-italic">
{lines.map((l) => <span key={l} className="block">{l}</span>)}
{dir && <a href={dir} rel="noopener" className="cc-link mt-2 inline-block font-semibold">Get directions</a>}
</address>
)}
</div>
);
if (p.section.variant === "map") {
const geo = p.site.church?.contact.address?.geo;
return (
<Section>
<div className="cc-wrap grid items-stretch gap-8 md:grid-cols-2">
{panel}
{geo ? (
<div className="cc-frame min-h-[18rem]">
{/* OpenStreetMap, loaded only when scrolled to (no Google, no cookies). */}
<iframe title="Map" loading="lazy" className="h-full min-h-[18rem] w-full border-0"
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>
) : <Img image={null} ratio="min-h-[18rem]" />}
</div>
</Section>
);
}
return <Section><div className="cc-wrap"><div className={cx(p.template === "heritage" ? "mx-auto max-w-xl" : "max-w-2xl")}>{panel}</div></div></Section>;
}
// ─── Welcome: Text · Image and text · With pastor's photo and quote ────────────────
function Welcome(p: SectionProps) {
const d = p.section.data as { heading: string | null; mission: string | null; body: string; imageId: string | null; pastor: { name: string; role: string | null; quote: string | null; photoId: string | null } | null };
const centred = p.template === "heritage";
const words = (
<div className={cx(centred && "text-center")}>
{d.mission && <p className="cc-eyebrow mb-4">{d.mission}</p>}
{d.heading && <h2 className="cc-h2 mb-6">{d.heading}</h2>}
<Paragraphs text={d.body} />
</div>
);
if (p.section.variant === "pastor" && d.pastor) {
const photo = media(p.site, d.pastor.photoId);
return (
<Section>
<div className="cc-wrap grid items-center gap-10 md:grid-cols-[2fr_3fr]">
<figure className={cx(centred && "text-center")}>
<Img image={photo} ratio="aspect-[4/5]" className={cx(p.template === "community" && "rounded-[2rem]", centred && "mx-auto max-w-xs")} />
{d.pastor.quote && <blockquote className="font-heading mt-6 text-xl italic">“{d.pastor.quote}”</blockquote>}
<figcaption className="cc-muted mt-3">{d.pastor.name}{d.pastor.role && <>, {d.pastor.role}</>}</figcaption>
</figure>
{words}
</div>
</Section>
);
}
if (p.section.variant === "image-text") {
return (
<Section>
<div className={cx("grid items-center gap-10 md:grid-cols-2", p.template === "bold" ? "px-0 md:gap-0" : "cc-wrap")}>
<Img image={media(p.site, d.imageId)} ratio={p.template === "bold" ? "aspect-square md:aspect-auto md:h-full md:min-h-[28rem]" : "aspect-[4/3]"} className={cx(p.template === "community" && "rounded-[2rem]", p.template === "bold" && "rounded-none")} />
<div className={cx(p.template === "bold" && "px-6 py-10 sm:px-12")}>{words}</div>
</div>
</Section>
);
}
return <Section><div className="cc-wrap"><div className="cc-text">{words}</div></div></Section>;
}
// ─── Ministries: Cards · List · Alternating bands ───────────────────────────────
function Ministries(p: SectionProps) {
const d = p.section.data as { heading: string | null; intro: string | null };
const list = p.site.snapshot.ministries;
if (!list.length) return null;
const page = p.site.snapshot.pages.find((x) => x.kind === "ministries");
const href = (slug: string) => (page ? `${page.path}#${slug}` : `#${slug}`);
const head = <SectionHeading heading={d.heading ?? "Ministries"} intro={d.intro} centred={p.template === "heritage"} />;
if (p.section.variant === "bands") {
return (
<Section className="!pb-0">
<div className="cc-wrap">{head}</div>
<div className={cx(p.template === "bold" ? "" : "cc-wrap space-y-10")}>
{list.map((m, i) => (
<div key={m.slug} className={cx("grid items-center md:grid-cols-2", p.template === "bold" ? "" : "gap-8")}>
<Img image={m.image} ratio={p.template === "bold" ? "aspect-[4/3]" : "aspect-[16/10]"} className={cx(i % 2 === 1 && "md:order-2", p.template === "bold" && "rounded-none", p.template === "community" && "rounded-[2rem]")} />
<div className={cx(p.template === "bold" && "px-6 py-10 sm:px-12")}>
<h3 className="cc-h3 mb-2">{m.name}</h3>
{m.summary && <p className="cc-muted text-lg">{m.summary}</p>}
<a href={href(m.slug)} className="cc-link mt-4 inline-block font-semibold">Find out more</a>
</div>
</div>
))}
</div>
<div className="pb-[var(--cc-section-y)]" />
</Section>
);
}
if (p.section.variant === "list") {
return (
<Section>
<div className="cc-wrap">
{head}
<ul className={cx("divide-y", p.template === "heritage" ? "mx-auto max-w-2xl divide-brand-text/20" : "divide-gray-200")}>
{list.map((m) => (
<li key={m.slug} className="flex flex-col gap-1 py-5 sm:flex-row sm:items-baseline sm:justify-between">
<a href={href(m.slug)} className="cc-h3 no-underline hover:underline">{m.name}</a>
{m.summary && <span className="cc-muted sm:max-w-md sm:text-right">{m.summary}</span>}
</li>
))}
</ul>
</div>
</Section>
);
}
return (
<Section>
<div className="cc-wrap">
{head}
<ul className={cx("grid gap-6", list.length > 3 ? "sm:grid-cols-2 lg:grid-cols-4" : "sm:grid-cols-3")}>
{list.map((m) => (
<li key={m.slug} className="cc-card flex flex-col">
<Img image={m.image} ratio="aspect-[4/3]" className="rounded-none" />
<div className="flex flex-1 flex-col p-5">
<h3 className="cc-h3">{m.name}</h3>
{m.summary && <p className={cx("mt-2 flex-1", p.template === "bold" ? "text-white/80" : "cc-muted")}>{m.summary}</p>}
<a href={href(m.slug)} className={cx("mt-4 font-semibold", p.template === "bold" ? "text-white underline" : "cc-link")}>Find out more<span className="sr-only"> about {m.name}</span></a>
</div>
</li>
))}
</ul>
</div>
</Section>
);
}
// ─── Team: Faces grid · List · Featured ─────────────────────────────────────────
function Team(p: SectionProps) {
const d = p.section.data as { heading: string | null; intro: string | null };
const people = p.site.snapshot.leaders;
if (!people.length) return null;
const head = <SectionHeading heading={d.heading ?? "Our team"} intro={d.intro} centred={p.template !== "clean"} />;
const face = (l: (typeof people)[number], big = false) => (
<figure key={l.name} className="text-center">
<Img image={l.photo} ratio={p.template === "bold" ? "aspect-[3/4]" : "aspect-square"}
className={cx(p.template === "heritage" || p.template === "community" ? "rounded-full" : "", big ? "mx-auto max-w-xs" : "mx-auto max-w-[12rem]")} />
<figcaption className="mt-4">
<span className={cx("block font-heading font-semibold", big ? "text-2xl" : "text-lg")}>{l.name}</span>
{l.role && <span className="cc-muted block">{l.role}</span>}
</figcaption>
</figure>
);
if (p.section.variant === "list") {
return (
<Section>
<div className="cc-wrap">
{head}
<ul className="mx-auto max-w-2xl divide-y divide-gray-200">
{people.map((l) => <li key={l.name} className="flex justify-between gap-4 py-4"><span className="font-semibold">{l.name}</span><span className="cc-muted">{l.role}</span></li>)}
</ul>
</div>
</Section>
);
}
if (p.section.variant === "featured") {
const [lead, ...rest] = people;
return (
<Section>
<div className="cc-wrap">
{head}
{face(lead!, true)}
{rest.length > 0 && <div className="mt-12 grid grid-cols-2 gap-8 sm:grid-cols-3">{rest.map((l) => face(l))}</div>}
</div>
</Section>
);
}
return <Section><div className="cc-wrap">{head}<div className="grid grid-cols-2 gap-8 sm:grid-cols-4">{people.map((l) => face(l))}</div></div></Section>;
}
// ─── Upcoming events: Cards · List · Calendar strip ─────────────────────────────
export function EventLine({ e, timeZone }: { e: SiteEvent; timeZone: string }) {
const when = e.allDay ? fmtDate(e.startsAt, timeZone, { weekday: "long", day: "numeric", month: "long" }) : `${fmtDate(e.startsAt, timeZone, { weekday: "long", day: "numeric", month: "long" })}, ${fmtTime(e.startsAt, timeZone)}`;
return (
<>
<time dateTime={e.startsAt} className="cc-muted block text-sm">{when}</time>
{e.location && <span className="cc-muted block text-sm">{e.location}</span>}
{e.registration && e.registration.status === "open" && <span className="cc-eyebrow mt-1 block text-xs">Register on our Events site</span>}
</>
);
}
function Events(p: SectionProps) {
const d = p.section.data as { heading: string | null; count: number };
const list = p.site.events.slice(0, d.count ?? 3);
const zone = tz(p);
const page = p.site.snapshot.pages.find((x) => x.kind === "events");
const head = <SectionHeading heading={d.heading ?? "Coming up"} centred={p.template === "heritage"} />;
const more = page && <p className={cx("mt-8", p.template === "heritage" && "text-center")}><a href={page.path} className="cc-link font-semibold">All events</a></p>;
if (!list.length) {
return <Section><div className="cc-wrap">{head}<p className="cc-muted">Nothing on the calendar just now. Check back soon.</p></div></Section>;
}
if (p.section.variant === "cards") {
return (
<Section>
<div className="cc-wrap">
{head}
<ul className="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} 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">
<h3 className="cc-h3"><a href={e.url} className="no-underline hover:underline">{e.title}</a></h3>
<div className="mt-2"><EventLine e={e} timeZone={zone} /></div>
</div>
</li>
))}
</ul>
{more}
</div>
</Section>
);
}
if (p.section.variant === "calendar") {
return (
<Section>
<div className="cc-wrap">
{head}
<ol className="flex snap-x gap-4 overflow-x-auto pb-4">
{list.map((e) => (
<li key={e.url + e.startsAt} className="cc-card w-64 shrink-0 snap-start p-5">
<p className="font-heading text-4xl font-bold text-brand-text">{fmtDate(e.startsAt, zone, { day: "numeric" })}</p>
<p className="cc-eyebrow">{fmtDate(e.startsAt, zone, { month: "long", weekday: "short" })}</p>
<h3 className="cc-h3 mt-3"><a href={e.url} className="no-underline hover:underline">{e.title}</a></h3>
{!e.allDay && <p className="cc-muted text-sm">{fmtTime(e.startsAt, zone)}</p>}
</li>
))}
</ol>
{more}
</div>
</Section>
);
}
return (
<Section>
<div className="cc-wrap">
{head}
<ul className={cx("divide-y divide-gray-200", p.template === "heritage" && "mx-auto max-w-2xl")}>
{list.map((e) => (
<li key={e.url + e.startsAt} className="flex gap-5 py-5">
<DateBadge iso={e.startsAt} timeZone={zone} />
<div><h3 className="cc-h3"><a href={e.url} className="no-underline hover:underline">{e.title}</a></h3><EventLine e={e} timeZone={zone} /></div>
</li>
))}
</ul>
{more}
</div>
</Section>
);
}
// ─── Latest message: Large video · Card · Compact ───────────────────────────────
function LatestMessage(p: SectionProps) {
const d = p.section.data as { heading: string | null };
const m = p.site.messages[0];
if (!m) return null;
const zone = tz(p);
const page = p.site.snapshot.pages.find((x) => x.kind === "messages");
const meta = [m.speaker, m.passage, fmtDate(m.date, zone, { day: "numeric", month: "long", year: "numeric" })].filter(Boolean).join(" · ");
const head = <SectionHeading eyebrow={d.heading ?? "Latest message"} heading={null} centred={p.template === "heritage"} />;
const words = (
<div>
{m.series && <p className="cc-eyebrow mb-2">{m.series}</p>}
<h3 className="cc-h2">{m.title}</h3>
<p className="cc-muted mt-3">{meta}</p>
{page && <a href={page.path} className="cc-link mt-5 inline-block font-semibold">All messages</a>}
</div>
);
if (p.section.variant === "compact") {
return (
<Section>
<div className="cc-wrap">
<div className="flex flex-col gap-4 border-y border-gray-200 py-6 sm:flex-row sm:items-center sm:justify-between">
<div><p className="cc-eyebrow">{d.heading ?? "Latest message"}</p><p className="font-heading text-xl font-semibold">{m.title}</p><p className="cc-muted text-sm">{meta}</p></div>
<a href={m.url} rel="noopener" className="cc-btn">{m.source === "spotify" ? "Listen" : "Watch"}</a>
</div>
</div>
</Section>
);
}
if (p.section.variant === "video") {
return (
<Section className={cx(p.template === "bold" && "cc-own-bg cc-dark bg-gray-950 text-white")}>
<div className="cc-wrap">
{head}
<MessagePlayer title={m.title} embedUrl={m.embedUrl} thumbnail={m.thumbnail} url={m.url} source={m.source} />
<div className={cx("mt-8", p.template === "heritage" && "text-center")}>{words}</div>
</div>
</Section>
);
}
return (
<Section>
<div className="cc-wrap">
{head}
<div className="cc-card grid items-center gap-0 md:grid-cols-2">
<MessagePlayer title={m.title} embedUrl={m.embedUrl} thumbnail={m.thumbnail} url={m.url} source={m.source} className="rounded-none" />
<div className="p-8">{words}</div>
</div>
</div>
</Section>
);
}
// ─── Invitation: Banner · Centred · Image background ────────────────────────────
function Invitation(p: SectionProps) {
const d = p.section.data as { heading: string; text: string | null; button: ButtonData; imageId: string | null };
if (p.section.variant === "image") {
const img = media(p.site, d.imageId);
return (
<section className="cc-section cc-own-bg cc-dark relative isolate overflow-hidden bg-gray-900 text-white">
{img && <img src={img.url} alt="" className="cc-img absolute inset-0 -z-10" loading="lazy" />}
<div className="absolute inset-0 -z-10 bg-black/60" aria-hidden="true" />
<div className="cc-wrap py-10 text-center">
<h2 className="cc-h2">{d.heading}</h2>
{d.text && <p className="mx-auto mt-4 max-w-2xl text-lg text-white/90">{d.text}</p>}
<div className="cc-on-dark mt-8"><Button button={d.button} /></div>
</div>
</section>
);
}
if (p.section.variant === "banner") {
return (
<section className="cc-section cc-own-bg cc-dark bg-brand text-brand-on">
<div className="cc-wrap flex flex-col items-start gap-6 md:flex-row md:items-center md:justify-between">
<div><h2 className="cc-h2">{d.heading}</h2>{d.text && <p className="mt-3 max-w-2xl text-lg opacity-90">{d.text}</p>}</div>
<div className="cc-on-dark shrink-0"><Button button={d.button} /></div>
</div>
</section>
);
}
return (
<Section>
<div className="cc-wrap text-center">
<h2 className="cc-h2">{d.heading}</h2>
{d.text && <p className="cc-muted mx-auto mt-4 max-w-2xl text-lg">{d.text}</p>}
<div className="mt-8"><Button button={d.button} /></div>
</div>
</Section>
);
}
// ─── Blocks on the other pages ──────────────────────────────────────────────────
function TextBlock(p: SectionProps) {
const d = p.section.data as { heading: string | null; body: string };
return <Section><div className="cc-wrap"><div className="cc-text">{d.heading && <h2 className="cc-h2 mb-6">{d.heading}</h2>}<Paragraphs text={d.body} /></div></div></Section>;
}
function ImageTextBlock(p: SectionProps) {
const d = p.section.data as { heading: string | null; body: string; imageId: string | null; button: ButtonData };
return (
<Section>
<div className="cc-wrap grid items-center gap-10 md:grid-cols-2">
<Img image={media(p.site, d.imageId)} className={cx(p.template === "community" && "rounded-[2rem]")} />
<div>{d.heading && <h2 className="cc-h2 mb-6">{d.heading}</h2>}<Paragraphs text={d.body} /><div className="mt-6"><Button button={d.button} /></div></div>
</div>
</Section>
);
}
function QuoteBlock(p: SectionProps) {
const d = p.section.data as { quote: string; by: string | null };
return (
<Section>
<figure className="cc-wrap text-center">
<blockquote className="font-heading mx-auto max-w-3xl text-2xl leading-snug sm:text-3xl">“{d.quote}”</blockquote>
{str(d.by) && <figcaption className="cc-muted mt-4">{d.by}</figcaption>}
</figure>
</Section>
);
}
function CtaBlock(p: SectionProps) {
return <Invitation {...p} section={{ ...p.section, variant: "centred", data: { ...p.section.data, imageId: null } }} />;
}
const SECTIONS: Record<string, (p: SectionProps) => React.ReactNode> = {
hero: Hero, serviceTimes: ServiceTimes, welcome: Welcome, ministries: Ministries, team: Team, events: Events, latestMessage: LatestMessage, invitation: Invitation,
text: TextBlock, "image-text": ImageTextBlock, quote: QuoteBlock, cta: CtaBlock,
};
export function Sections({ site, sections }: { site: SectionProps["site"]; sections: SectionProps["section"][] }) {
const template = site.snapshot.design.template;
return (
<>
{sections.map((section, i) => {
const S = SECTIONS[section.type];
return S ? <S key={`${section.type}-${i}`} section={section} site={site} template={template} first={i === 0} /> : null;
})}
</>
);
}