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:
@@ -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) {
|
||||
|
||||
@@ -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'];
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user