Backend (Express + Prisma, ES modules, as Accounts): /api/health and /api/v1/site/status (Coming soon until the first publish), the content model and its first migration, and the confirmed section variants per template (WEBSITE-1.0-PLAN §3, decision 16) with the template switch rules, with tests. Frontend (Next.js 16): Coming soon page, admin placeholder, robots.txt. env.template.json, PM2 example, CHANGELOG and WHATS-NEW. Root workspaces and lint updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
203 lines
9.3 KiB
TypeScript
203 lines
9.3 KiB
TypeScript
/**
|
|
* Section variants per template (docs/WEBSITE-1.0-PLAN.md §3, "Section variants per template",
|
|
* decision 16, confirmed 2026-11-25).
|
|
*
|
|
* Every template draws every variant, so nothing is ever unavailable and a template switch never
|
|
* needs a fallback. A template only sets which variant each section starts with, which ones it
|
|
* recommends, its header options, its homepage order and its style defaults.
|
|
*
|
|
* The ids are stored on each section (`hero.variant = "photo"`), so **an id never changes or goes
|
|
* away** once released, like the font pairing ids in `@crosscode/contracts`.
|
|
*/
|
|
import { z } from 'zod';
|
|
import type { Corners, WebsiteTemplate } from '@crosscode/contracts';
|
|
|
|
/** The homepage section types and their variant ids. */
|
|
export const SECTION_VARIANTS = {
|
|
hero: ['photo', 'video', 'collage', 'split', 'text'],
|
|
serviceTimes: ['panel', 'strip', 'map'],
|
|
welcome: ['text', 'image-text', 'pastor'],
|
|
ministries: ['cards', 'list', 'bands'],
|
|
team: ['faces', 'list', 'featured'],
|
|
events: ['cards', 'list', 'calendar'],
|
|
latestMessage: ['video', 'card', 'compact'],
|
|
invitation: ['banner', 'centred', 'image'],
|
|
} 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);
|
|
}
|
|
|
|
/** Per section: the default first, then the other recommended variants. */
|
|
type Recommendations = { [S in SectionType]: readonly [Variant<S>, ...Variant<S>[]] };
|
|
|
|
export const TEMPLATE_VARIANTS: Record<WebsiteTemplate, Recommendations> = {
|
|
heritage: {
|
|
hero: ['photo', 'split', 'text'],
|
|
serviceTimes: ['panel', 'map'],
|
|
welcome: ['pastor', 'text'],
|
|
ministries: ['list', 'cards'],
|
|
team: ['featured', 'faces'],
|
|
events: ['list', 'calendar'],
|
|
latestMessage: ['card', 'video'],
|
|
invitation: ['centred', 'banner'],
|
|
},
|
|
bold: {
|
|
hero: ['video', 'photo', 'split'],
|
|
serviceTimes: ['strip', 'map'],
|
|
welcome: ['image-text', 'pastor'],
|
|
ministries: ['bands', 'cards'],
|
|
team: ['faces', 'featured'],
|
|
events: ['cards', 'calendar'],
|
|
latestMessage: ['video', 'card'],
|
|
invitation: ['image', 'banner'],
|
|
},
|
|
community: {
|
|
hero: ['collage', 'photo', 'split'],
|
|
serviceTimes: ['map', 'panel'],
|
|
welcome: ['pastor', 'image-text'],
|
|
ministries: ['cards', 'bands'],
|
|
team: ['faces', 'featured'],
|
|
events: ['cards', 'calendar'],
|
|
latestMessage: ['card', 'video'],
|
|
invitation: ['banner', 'image'],
|
|
},
|
|
clean: {
|
|
hero: ['text', 'split', 'photo'],
|
|
serviceTimes: ['strip', 'panel'],
|
|
welcome: ['text', 'image-text'],
|
|
ministries: ['list', 'cards'],
|
|
team: ['list', 'faces'],
|
|
events: ['list', 'calendar'],
|
|
latestMessage: ['compact', 'card'],
|
|
invitation: ['centred', 'banner'],
|
|
},
|
|
};
|
|
|
|
export function defaultVariant<S extends SectionType>(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 {
|
|
return (TEMPLATE_VARIANTS[template][section] as readonly string[]).includes(variant);
|
|
}
|
|
|
|
/** The "Header" style setting: each template's options, default first. */
|
|
export const TEMPLATE_HEADERS = {
|
|
heritage: ['centred', 'centred-top-bar'],
|
|
bold: ['transparent', 'solid'],
|
|
community: ['logo-left-button', 'logo-left-tinted'],
|
|
clean: ['small', 'small-menu'],
|
|
} as const satisfies Record<WebsiteTemplate, readonly [string, ...string[]]>;
|
|
|
|
/**
|
|
* The transparent header only sits over a photo, video or collage hero; on any other first section
|
|
* it's drawn solid, so it never puts white text on white.
|
|
*/
|
|
export function headerIsTransparent(template: WebsiteTemplate, header: string, heroVariant: Variant<'hero'> | null): boolean {
|
|
return template === 'bold' && header === 'transparent' && heroVariant !== null && ['photo', 'video', 'collage'].includes(heroVariant);
|
|
}
|
|
|
|
/** A homepage entry: the section and whether it shows. */
|
|
export type HomeEntry = { section: SectionType; hidden: boolean };
|
|
|
|
const order = (shown: SectionType[], hidden: SectionType[] = []): HomeEntry[] => [
|
|
...shown.map((section) => ({ section, hidden: false })),
|
|
...hidden.map((section) => ({ section, hidden: true })),
|
|
];
|
|
|
|
/** The default homepage order (the church can reorder, hide and show). Every section is listed once. */
|
|
export const TEMPLATE_HOME_ORDER: Record<WebsiteTemplate, HomeEntry[]> = {
|
|
heritage: order(['hero', 'serviceTimes', 'welcome', 'latestMessage', 'ministries', 'team', 'events', 'invitation']),
|
|
bold: order(['hero', 'serviceTimes', 'welcome', 'events', 'latestMessage', 'ministries', 'invitation'], ['team']),
|
|
community: order(['hero', 'welcome', 'serviceTimes', 'ministries', 'team', 'events', 'latestMessage', 'invitation']),
|
|
clean: order(['hero', 'serviceTimes', 'welcome', 'events', 'latestMessage', 'invitation'], ['ministries', 'team']),
|
|
};
|
|
|
|
/** The Website-only style settings (§3, "Style settings"). Fonts and corners are the church's, shared. */
|
|
export const SECTION_COLOURS = ['light', 'tinted', 'mixed'] as const;
|
|
export const SPACINGS = ['airy', 'compact'] as const;
|
|
export const BUTTONS = ['solid', 'outline', 'pill'] as const;
|
|
export const IMAGE_TREATMENTS = ['natural', 'mono', 'duotone'] as const;
|
|
|
|
export type SiteStyle = {
|
|
sectionColour: (typeof SECTION_COLOURS)[number];
|
|
spacing: (typeof SPACINGS)[number];
|
|
buttons: (typeof BUTTONS)[number];
|
|
images: (typeof IMAGE_TREATMENTS)[number];
|
|
header: string;
|
|
};
|
|
|
|
export const TEMPLATE_STYLE: Record<WebsiteTemplate, SiteStyle & { suggestedCorners: Corners }> = {
|
|
heritage: { sectionColour: 'light', spacing: 'airy', buttons: 'outline', images: 'natural', header: 'centred', suggestedCorners: 'sharp' },
|
|
bold: { sectionColour: 'mixed', spacing: 'compact', buttons: 'solid', images: 'natural', header: 'transparent', suggestedCorners: 'sharp' },
|
|
community: { sectionColour: 'tinted', spacing: 'airy', buttons: 'pill', images: 'natural', header: 'logo-left-button', suggestedCorners: 'round' },
|
|
clean: { sectionColour: 'light', spacing: 'airy', buttons: 'outline', images: 'natural', header: 'small', suggestedCorners: 'soft' },
|
|
};
|
|
|
|
const STYLE_KEYS = ['sectionColour', 'spacing', 'buttons', 'images', 'header'] as const;
|
|
|
|
/** 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> };
|
|
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 { suggestedCorners: _c, ...style } = TEMPLATE_STYLE[template];
|
|
return { template, variants, home: TEMPLATE_HOME_ORDER[template].map((e) => ({ ...e })), style };
|
|
}
|
|
|
|
export type DesignChange = { what: string; from: string; to: string };
|
|
|
|
const sameOrder = (a: HomeEntry[], b: HomeEntry[]) =>
|
|
a.length === b.length && a.every((e, i) => e.section === b[i]!.section && e.hidden === b[i]!.hidden);
|
|
|
|
/**
|
|
* Switching template (§3, "Switching template"): anything still on the old template's default
|
|
* moves to the new template's default; anything the church chose stays. Returns the new design and
|
|
* what moved, for the Publish screen ("Hero: Collage → Text only, Clean's default").
|
|
*/
|
|
export function switchTemplate(current: SiteDesign, to: WebsiteTemplate): { design: SiteDesign; changes: DesignChange[] } {
|
|
if (current.template === to) return { design: current, changes: [] };
|
|
const from = current.template;
|
|
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 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 });
|
|
variants[s] = next;
|
|
}
|
|
}
|
|
|
|
const homeUntouched = sameOrder(current.home, TEMPLATE_HOME_ORDER[from]);
|
|
const home = homeUntouched ? target.home : current.home.map((e) => ({ ...e }));
|
|
if (homeUntouched && !sameOrder(current.home, target.home)) changes.push({ what: 'home', from: `${from} order`, to: `${to} order` });
|
|
|
|
const style = { ...current.style };
|
|
const oldStyle = TEMPLATE_STYLE[from];
|
|
for (const k of STYLE_KEYS) {
|
|
// A header from the old template's options means nothing in the new one, so it always moves.
|
|
const untouched = current.style[k] === oldStyle[k] || (k === 'header' && !(TEMPLATE_HEADERS[to] as readonly string[]).includes(current.style.header));
|
|
if (untouched && current.style[k] !== target.style[k]) {
|
|
changes.push({ what: `style.${k}`, from: current.style[k], to: target.style[k] });
|
|
(style as Record<string, string>)[k] = target.style[k];
|
|
}
|
|
}
|
|
|
|
return { design: { template: to, variants: variants as SiteDesign['variants'], home, style }, changes };
|
|
}
|