Merge branch 'main' into feat/app-scaffold

This commit is contained in:
2026-12-01 11:05:26 +02:00
18 changed files with 622 additions and 128 deletions
+21
View File
@@ -1,5 +1,26 @@
# Changelog — Church Website
## [1.12.0] — 2026-12-01
No migration (the layouts live in `SiteDesign.variants`). No new environment settings.
### Added
- **Listing page layouts** (`PAGE_VARIANTS` in `src/site/variants.ts`), three per page:
`ministriesPage` `alternating` · `cards` · `list`; `leadershipPage` `grid` · `featured` · `list`;
`eventsPage` `list` · `cards` · `months`; `messagesPage` `grid` · `featured` · `list`;
`contactPage` `columns` · `map` · `cards`. They sit beside the homepage sections' in the design
(`PUT /design { variants: { eventsPage: "months" } }`), so each template recommends some, starts
a new site on the first (its suggestion), and a template switch moves an untouched one to the
new template's suggestion. A design saved before them has none: `cleanDesign` gives it
`LEGACY_PAGE_LAYOUTS` (how the pages looked until now), so nothing changes until a church picks
one; a snapshot without them is drawn the same way. `contactPage` `map` without a place on the
map draws as `columns`.
- **Admin:** a listing page's editor (Pages) has its Layout, the template's suggestion marked; and
Template and style has an **Other pages** tab with all five.
- `e2e/page-layouts.spec.ts`: every page layout in every template answers and passes axe at phone
and desktop width (`PAGE_SHOTS=<folder>` saves screenshots).
## [1.11.0] — 2026-12-01
**Migration** `20261201000000_block_background` (adds the nullable `Section.background`; nothing
+10
View File
@@ -3,6 +3,16 @@
What each version changes for the church, in plain language (read by the Hub like Cross Events'
WHATS-NEW.md; a section shows once its version is tagged).
## 1.12.0
- **Choose how your Ministries, Leadership, Events, Messages and Contact pages look.** Each has
three layouts: ministries as alternating photo and text, cards, or a list with small photos;
your team as a grid of faces, with the lead pastor first, or a list; events as a list, cards
with photos, or grouped by month; messages as a grid of videos, the latest first then a list,
or a list; contact details in two columns, with a map, or as cards. Your template suggests one
for each page. Choose it at the top of the page in **Pages**, or all five together under
**Template and style → Other pages**. Your pages look the same as before until you choose.
## 1.11.0
- **Layouts and backgrounds for the blocks on your other pages.** Open a block in **Pages** to
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@crosscode/website-backend",
"version": "1.11.0",
"version": "1.12.0",
"description": "Church Website: the public site's content API, the admin API, publishing and uploads",
"private": true,
"type": "module",
+2 -2
View File
@@ -13,7 +13,7 @@ import { Prisma } from '../generated/prisma/client.js';
import { ApiError } from '../http.js';
import { BLOCK_SCHEMAS, isBlockType, rowFraming, SECTION_SCHEMAS } from '../site/sections.js';
import { cleanDesign } from '../site/snapshot.js';
import { BLOCK_VARIANTS, BUTTONS, IMAGE_TREATMENTS, isVariant, SECTION_BACKGROUNDS, SECTION_COLOURS, SECTION_TYPES, sectionTypeSchema, SPACINGS, switchTemplate, TEMPLATE_HEADERS, type SectionType } from '../site/variants.js';
import { BLOCK_VARIANTS, BUTTONS, IMAGE_TREATMENTS, isLayoutKey, isVariant, SECTION_BACKGROUNDS, SECTION_COLOURS, SECTION_TYPES, sectionTypeSchema, SPACINGS, switchTemplate, TEMPLATE_HEADERS, type SectionType } from '../site/variants.js';
type Who = { id: string; role: string };
@@ -76,7 +76,7 @@ export async function saveDesign(ctx: Ctx, body: unknown, by: Who) {
let moved: { what: string; from: string; to: string }[] = [];
if (patch.template && patch.template !== design.template) ({ design, changes: moved } = switchTemplate(design, patch.template));
for (const [section, variant] of Object.entries(patch.variants ?? {})) {
if (!SECTION_TYPES.includes(section as SectionType) || !isVariant(section as SectionType, variant)) throw new ApiError(400, 'VALIDATION', `"${variant}" isn't a layout for ${section}.`);
if (!isLayoutKey(section) || !isVariant(section, variant)) throw new ApiError(400, 'VALIDATION', `"${variant}" isn't a layout for ${section}.`);
(design.variants as Record<string, string>)[section] = variant;
}
if (patch.home) {
+2 -2
View File
@@ -26,7 +26,7 @@ import { demoChurch, demoParts, demoPeople } from '@crosscode/demo';
import { markRemoved, notifyLinks, syncLink, type SyncResult } from '../feed/feed.js';
import type { SectionData } from '../site/sections.js';
import { publish } from '../site/snapshot.js';
import { TEMPLATE_HEADERS, TEMPLATE_VARIANTS, SECTION_TYPES, defaultDesign, type SiteDesign } from '../site/variants.js';
import { TEMPLATE_HEADERS, TEMPLATE_VARIANTS, LAYOUT_KEYS, defaultDesign, type SiteDesign } from '../site/variants.js';
import { MAX_WIDTH, WIDTHS, processImage, type Sizes } from '../admin/media.js';
import { DEMO_SEEDS, type DemoPhotos, type DemoSeed, type ProfileSeed } from './seeds.js';
@@ -250,7 +250,7 @@ const CLASSIC: Omit<DemoSeed, 'template'> & { pastorName: string; ctaText: strin
export function seedDesign(template: WebsiteTemplate, alternate: boolean): SiteDesign {
const design = defaultDesign(template);
if (!alternate) return design;
const variants = Object.fromEntries(SECTION_TYPES.map((s) => {
const variants = Object.fromEntries(LAYOUT_KEYS.map((s) => {
const options = TEMPLATE_VARIANTS[template][s] as readonly string[];
return [s, options[1] ?? options[0]!];
})) as SiteDesign['variants'];
+5 -3
View File
@@ -11,7 +11,7 @@ import { WEBSITE_TEMPLATES, type WebsiteTemplate } from '@crosscode/contracts';
import type { Ctx } from '../context.js';
import { audit } from '../lib/audit.js';
import { parseSectionData } from './sections.js';
import { blockVariant, defaultDesign, isSectionBackground, isVariant, SECTION_BACKGROUNDS, SECTION_TYPES, switchTemplate, type SectionBackground, type SectionType, type SiteDesign } from './variants.js';
import { blockVariant, defaultDesign, isSectionBackground, isVariant, LAYOUT_KEYS, LEGACY_PAGE_LAYOUTS, PAGE_LAYOUT_KEYS, SECTION_BACKGROUNDS, SECTION_TYPES, switchTemplate, type LayoutKey, type SectionBackground, type SectionType, type SiteDesign } from './variants.js';
export const SNAPSHOT_VERSION = 1;
@@ -84,9 +84,11 @@ export function cleanDesign(saved: { template: string; variants: unknown; home:
const template: WebsiteTemplate = saved && (WEBSITE_TEMPLATES as readonly string[]).includes(saved.template) ? (saved.template as WebsiteTemplate) : 'heritage';
const base = defaultDesign(template);
if (!saved) return base;
const variants = { ...base.variants } as Record<SectionType, string>;
const variants = { ...base.variants } as Record<LayoutKey, string>;
const v = (saved.variants ?? {}) as Record<string, unknown>;
for (const s of SECTION_TYPES) if (typeof v[s] === 'string' && isVariant(s, v[s] as string)) variants[s] = v[s] as string;
// A design from before the listing pages had layouts keeps how they looked (LEGACY_PAGE_LAYOUTS).
if (!PAGE_LAYOUT_KEYS.some((k) => k in v)) Object.assign(variants, LEGACY_PAGE_LAYOUTS);
for (const s of LAYOUT_KEYS) if (typeof v[s] === 'string' && isVariant(s, v[s] as string)) variants[s] = v[s] as string;
const home = Array.isArray(saved.home)
? (saved.home as { section?: unknown; hidden?: unknown; background?: unknown }[]).filter((e) => SECTION_TYPES.includes(e?.section as SectionType)).map((e) => ({
section: e.section as SectionType,
+66 -12
View File
@@ -25,17 +25,50 @@ export const SECTION_VARIANTS = {
} as const;
export type SectionType = keyof typeof SECTION_VARIANTS;
export type Variant<S extends SectionType = SectionType> = (typeof SECTION_VARIANTS)[S][number];
export const SECTION_TYPES = Object.keys(SECTION_VARIANTS) as [SectionType, ...SectionType[]];
export const sectionTypeSchema = z.enum(SECTION_TYPES);
/** Whether `variant` is one of `section`'s ids. */
export function isVariant<S extends SectionType>(section: S, variant: string): variant is Variant<S> {
return (SECTION_VARIANTS[section] as readonly string[]).includes(variant);
/**
* The layouts of what a fixed page lists (WEBSITE-1.0-PLAN §6: ministries, leaders, events,
* messages, contact details), keyed `<page kind>Page` so they sit beside the homepage sections' in
* the design (`variants.ministriesPage = "cards"`). Like those, every template draws every one, a
* template recommends some and starts with the first, and **an id never changes or goes away**.
*/
export const PAGE_VARIANTS = {
ministriesPage: ['alternating', 'cards', 'list'],
leadershipPage: ['grid', 'featured', 'list'],
eventsPage: ['list', 'cards', 'months'],
messagesPage: ['grid', 'featured', 'list'],
contactPage: ['columns', 'map', 'cards'],
} as const;
export type PageLayoutKey = keyof typeof PAGE_VARIANTS;
export const PAGE_LAYOUT_KEYS = Object.keys(PAGE_VARIANTS) as [PageLayoutKey, ...PageLayoutKey[]];
/**
* What each listing page looked like before it had layouts (Website 1.11 and earlier). A design
* saved then has no page layouts; it keeps this look rather than taking the template's suggestion
* on its next publish, so nothing changes until the church picks one.
*/
export const LEGACY_PAGE_LAYOUTS: { [K in PageLayoutKey]: (typeof PAGE_VARIANTS)[K][number] } = {
ministriesPage: 'alternating', leadershipPage: 'grid', eventsPage: 'list', messagesPage: 'grid', contactPage: 'columns',
};
/** Everything with a layout in the design: the homepage sections and the listing pages. */
const LAYOUTS = { ...SECTION_VARIANTS, ...PAGE_VARIANTS };
export type LayoutKey = keyof typeof LAYOUTS;
export const LAYOUT_KEYS = [...SECTION_TYPES, ...PAGE_LAYOUT_KEYS] as [LayoutKey, ...LayoutKey[]];
export type Variant<S extends LayoutKey = LayoutKey> = (typeof LAYOUTS)[S][number];
export const isLayoutKey = (k: string): k is LayoutKey => (LAYOUT_KEYS as readonly string[]).includes(k);
/** Whether `variant` is one of `section`'s (or a listing page's) ids. */
export function isVariant<S extends LayoutKey>(section: S, variant: string): variant is Variant<S> {
return (LAYOUTS[section] as readonly string[]).includes(variant);
}
/** Per section: the default first, then the other recommended variants. */
type Recommendations = { [S in SectionType]: readonly [Variant<S>, ...Variant<S>[]] };
/** Per section and listing page: the default first, then the other recommended variants. */
type Recommendations = { [S in LayoutKey]: readonly [Variant<S>, ...Variant<S>[]] };
export const TEMPLATE_VARIANTS: Record<WebsiteTemplate, Recommendations> = {
heritage: {
@@ -47,6 +80,11 @@ export const TEMPLATE_VARIANTS: Record<WebsiteTemplate, Recommendations> = {
events: ['list', 'calendar'],
latestMessage: ['card', 'video'],
invitation: ['centred', 'banner'],
ministriesPage: ['list', 'alternating'],
leadershipPage: ['featured', 'grid'],
eventsPage: ['list', 'months'],
messagesPage: ['featured', 'grid'],
contactPage: ['columns', 'map'],
},
bold: {
hero: ['video', 'photo', 'split'],
@@ -57,6 +95,11 @@ export const TEMPLATE_VARIANTS: Record<WebsiteTemplate, Recommendations> = {
events: ['cards', 'calendar'],
latestMessage: ['video', 'card'],
invitation: ['image', 'banner'],
ministriesPage: ['alternating', 'cards'],
leadershipPage: ['grid', 'featured'],
eventsPage: ['cards', 'list'],
messagesPage: ['featured', 'grid'],
contactPage: ['map', 'cards'],
},
community: {
hero: ['collage', 'photo', 'split'],
@@ -67,6 +110,11 @@ export const TEMPLATE_VARIANTS: Record<WebsiteTemplate, Recommendations> = {
events: ['cards', 'calendar'],
latestMessage: ['card', 'video'],
invitation: ['banner', 'image'],
ministriesPage: ['cards', 'alternating'],
leadershipPage: ['grid', 'featured'],
eventsPage: ['cards', 'months'],
messagesPage: ['grid', 'featured'],
contactPage: ['cards', 'map'],
},
clean: {
hero: ['text', 'split', 'photo'],
@@ -77,14 +125,19 @@ export const TEMPLATE_VARIANTS: Record<WebsiteTemplate, Recommendations> = {
events: ['list', 'calendar'],
latestMessage: ['compact', 'card'],
invitation: ['centred', 'banner'],
ministriesPage: ['list', 'cards'],
leadershipPage: ['list', 'grid'],
eventsPage: ['list', 'months'],
messagesPage: ['list', 'grid'],
contactPage: ['columns', 'cards'],
},
};
export function defaultVariant<S extends SectionType>(template: WebsiteTemplate, section: S): Variant<S> {
export function defaultVariant<S extends LayoutKey>(template: WebsiteTemplate, section: S): Variant<S> {
return (TEMPLATE_VARIANTS[template][section] as readonly Variant<S>[])[0]!;
}
export function isRecommended(template: WebsiteTemplate, section: SectionType, variant: string): boolean {
export function isRecommended(template: WebsiteTemplate, section: LayoutKey, variant: string): boolean {
return (TEMPLATE_VARIANTS[template][section] as readonly string[]).includes(variant);
}
@@ -179,14 +232,15 @@ const STYLE_KEYS = ['sectionColour', 'spacing', 'buttons', 'images', 'header'] a
/** The site's design: what a template switch changes. Content is never part of it. */
export type SiteDesign = {
template: WebsiteTemplate;
variants: { [S in SectionType]: Variant<S> };
/** The homepage sections' layouts and the listing pages' (PAGE_VARIANTS). */
variants: { [S in LayoutKey]: Variant<S> };
home: HomeEntry[];
style: SiteStyle;
};
/** A fresh site on `template`: every default. */
export function defaultDesign(template: WebsiteTemplate): SiteDesign {
const variants = Object.fromEntries(SECTION_TYPES.map((s) => [s, defaultVariant(template, s)])) as SiteDesign['variants'];
const variants = Object.fromEntries(LAYOUT_KEYS.map((s) => [s, defaultVariant(template, s)])) as SiteDesign['variants'];
const { suggestedCorners: _c, ...style } = TEMPLATE_STYLE[template];
return { template, variants, home: TEMPLATE_HOME_ORDER[template].map((e) => ({ ...e })), style };
}
@@ -207,8 +261,8 @@ export function switchTemplate(current: SiteDesign, to: WebsiteTemplate): { desi
const target = defaultDesign(to);
const changes: DesignChange[] = [{ what: 'template', from, to }];
const variants = { ...current.variants } as Record<SectionType, string>;
for (const s of SECTION_TYPES) {
const variants = { ...current.variants } as Record<LayoutKey, string>;
for (const s of LAYOUT_KEYS) {
const next = target.variants[s];
if (current.variants[s] === defaultVariant(from, s) && next !== current.variants[s]) {
changes.push({ what: `${s}.variant`, from: current.variants[s], to: next });
+4
View File
@@ -121,6 +121,10 @@ describe('editing, publishing, discarding, restoring (§4)', () => {
assert.equal(r.body.design.variants.hero, 'video', 'moved to Bold\'s default');
assert.ok(r.body.moved.some((m: { what: string }) => m.what === 'hero.variant'));
assert.equal((await as.put('/design', { variants: { hero: 'spinning' } })).status, 400);
const pages = await as.put('/design', { variants: { messagesPage: 'list' } });
assert.equal(pages.status, 200, 'a listing page has a layout too');
assert.equal(pages.body.design.variants.messagesPage, 'list');
assert.equal((await as.put('/design', { variants: { messagesPage: 'months' } })).status, 400, "an events layout isn't a messages one");
assert.equal((await as.put('/design', { style: { header: 'centred' } })).status, 400, 'a Heritage header on Bold');
});
+39 -1
View File
@@ -2,7 +2,7 @@ import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { WEBSITE_TEMPLATES } from '@crosscode/contracts';
import {
SECTION_TYPES, SECTION_VARIANTS, TEMPLATE_HEADERS, TEMPLATE_HOME_ORDER, TEMPLATE_STYLE, TEMPLATE_VARIANTS,
LEGACY_PAGE_LAYOUTS, PAGE_LAYOUT_KEYS, PAGE_VARIANTS, SECTION_TYPES, SECTION_VARIANTS, TEMPLATE_HEADERS, TEMPLATE_HOME_ORDER, TEMPLATE_STYLE, TEMPLATE_VARIANTS,
defaultDesign, defaultVariant, headerIsTransparent, isRecommended, isVariant, switchTemplate,
} from '../src/site/variants.js';
import { cleanDesign } from '../src/site/snapshot.js';
@@ -103,6 +103,44 @@ describe('switching template', () => {
});
});
describe('listing page layouts', () => {
it('has at least three layouts for each listing page, and every template suggests real ones', () => {
assert.deepEqual(PAGE_LAYOUT_KEYS, ['ministriesPage', 'leadershipPage', 'eventsPage', 'messagesPage', 'contactPage']);
for (const k of PAGE_LAYOUT_KEYS) assert.ok(PAGE_VARIANTS[k].length >= 3, k);
for (const t of WEBSITE_TEMPLATES) {
for (const k of PAGE_LAYOUT_KEYS) {
const rec = TEMPLATE_VARIANTS[t][k] as readonly string[];
assert.ok(rec.length >= 2, `${t}.${k}`);
assert.equal(new Set(rec).size, rec.length, `${t}.${k} repeats`);
for (const v of rec) assert.ok(isVariant(k, v), `${t}.${k}: ${v}`);
}
}
});
it("starts a new site on the template's suggestion", () => {
assert.equal(defaultDesign('community').variants.ministriesPage, 'cards');
assert.equal(defaultDesign('bold').variants.contactPage, 'map');
assert.equal(defaultDesign('clean').variants.messagesPage, 'list');
});
it('keeps the look a design had before page layouts, until the church picks one', () => {
const before = cleanDesign({ template: 'community', variants: { hero: 'photo' }, home: [], style: {} });
assert.deepEqual(PAGE_LAYOUT_KEYS.map((k) => before.variants[k]), PAGE_LAYOUT_KEYS.map((k) => LEGACY_PAGE_LAYOUTS[k]));
const picked = cleanDesign({ template: 'community', variants: { eventsPage: 'months' }, home: [], style: {} });
assert.equal(picked.variants.eventsPage, 'months');
assert.equal(picked.variants.ministriesPage, 'cards', 'the rest take the suggestion');
assert.equal(cleanDesign({ template: 'clean', variants: { eventsPage: 'nope' }, home: [], style: {} }).variants.eventsPage, 'list');
});
it('moves with a template switch when untouched, and stays when chosen', () => {
const start = defaultDesign('heritage');
start.variants.eventsPage = 'cards';
const { design } = switchTemplate(start, 'community');
assert.equal(design.variants.eventsPage, 'cards');
assert.equal(design.variants.ministriesPage, 'cards', "moved from Heritage's list to Community's cards");
});
});
describe("a section's own background", () => {
it('stays with its section through a template switch, whether the order moves or not', () => {
const start = defaultDesign('heritage');
+52
View File
@@ -0,0 +1,52 @@
/**
* Every listing page layout in every template (backend variants.ts PAGE_VARIANTS): the demo
* church's Ministries, Leadership, Events, Messages and Contact pages, one layout at a time. Each
* page answers, shows what it lists, keeps the anchors the homepage links to, and axe finds no
* violations (WCAG 2.2 AA) at phone and desktop width.
*
* PAGE_SHOTS=<folder> also saves a full-page screenshot of each, to look through by eye.
*/
import AxeBuilder from "@axe-core/playwright";
import { expect, test } from "@playwright/test";
import { PAGE_LAYOUT_KEYS, PAGE_VARIANTS, TEMPLATE_VARIANTS } from "../backend/src/site/variants.js";
const BACKEND = "http://127.0.0.1:5310";
const TEMPLATES = Object.keys(TEMPLATE_VARIANTS) as (keyof typeof TEMPLATE_VARIANTS)[];
const WIDTHS = [["phone", { width: 390, height: 844 }], ["desktop", { width: 1366, height: 900 }]] as const;
const SHOTS = process.env.PAGE_SHOTS;
/** The demo's page for each layout key, and something it must show. */
const PAGES: Record<(typeof PAGE_LAYOUT_KEYS)[number], { path: string; shows: string }> = {
ministriesPage: { path: "/ministries", shows: "main [id] h2" },
leadershipPage: { path: "/leadership", shows: "main article h2" },
eventsPage: { path: "/events", shows: 'main a[href]:not([href^="#"])' },
messagesPage: { path: "/messages", shows: "main [id] h2" },
contactPage: { path: "/contact", shows: 'main a[href^="mailto:"]' },
};
for (const template of TEMPLATES) {
test.describe(`${template} page layouts`, () => {
test.beforeAll(async ({ request }) => {
expect((await request.post(`${BACKEND}/test/demo?template=${template}`)).ok()).toBeTruthy();
});
for (const key of PAGE_LAYOUT_KEYS) {
for (const layout of PAGE_VARIANTS[key]) {
test(`${key}: ${layout}`, async ({ page }) => {
const res = await page.request.post(`${BACKEND}/test/design`, { data: { variants: { [key]: layout } } });
expect(res.ok()).toBeTruthy();
const { path, shows } = PAGES[key];
for (const [name, size] of WIDTHS) {
await page.setViewportSize(size);
expect((await page.goto(path))?.status()).toBe(200);
await expect(page.locator("html")).toHaveAttribute("data-template", template);
await expect(page.locator(shows).first()).toBeVisible();
const axe = await new AxeBuilder({ page }).withTags(["wcag2a", "wcag2aa", "wcag21aa", "wcag22aa"]).analyze();
expect(axe.violations.map((v) => `${v.id} (${v.nodes.length}) ${v.nodes[0]?.target}`), name).toEqual([]);
if (SHOTS) await page.screenshot({ path: `${SHOTS}/${template}-${key}-${layout}-${name}.png`, fullPage: true });
}
});
}
}
});
}
+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 }) {