website 1.11.0: layouts and backgrounds for the blocks; a video for the top of the page
- Blocks get layouts (BLOCK_VARIANTS: text standard/centred; image and text photo left, right or above; quote centred/with a line; call to action centred/banner), stored on Section.variant and checked against the type; an unknown one draws as the default, as every block looked before. The demo's image-text block id is now image-left. - Each block has its own background (Section.background, migration 20261201000000_block_background), in the published source only when set, put back by Discard and Restore, drawn as the homepage's (data-bg). - MP4 uploads up to 20 MB for the hero's Video layout: QuickTime refused, metadata boxes (udta, meta, uuid) blanked into free boxes of the same size so where it was filmed is gone and the frame offsets hold; size read from tkhd. GET /media lists mime. - Admin: a block's Layout and Background when open; the hero's Video field (only videos; photo fields only photos); the media library shows and takes videos. An upload over the limit says so instead of "That request isn't valid." - Tests: backend (152, three new); e2e for block layouts and a video upload. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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 { defaultDesign, isVariant, SECTION_BACKGROUNDS, SECTION_TYPES, switchTemplate, type SectionBackground, type SectionType, type SiteDesign } from './variants.js';
|
||||
import { blockVariant, defaultDesign, isSectionBackground, isVariant, SECTION_BACKGROUNDS, SECTION_TYPES, switchTemplate, type SectionBackground, type SectionType, type SiteDesign } from './variants.js';
|
||||
|
||||
export const SNAPSHOT_VERSION = 1;
|
||||
|
||||
@@ -34,7 +34,7 @@ export const framed = (img: Image | null, f: unknown): Image | null => {
|
||||
|
||||
type MediaRow = { id: string; filename: string; alt: string; width: number | null; height: number | null; sizes?: unknown };
|
||||
|
||||
/** `background`: a homepage section's own background (variants.ts SECTION_BACKGROUNDS), when it has one. */
|
||||
/** `background`: a homepage section's or block's own background (variants.ts SECTION_BACKGROUNDS), when it has one. */
|
||||
export type SnapshotSection = { type: string; variant: string | null; data: Record<string, unknown>; background?: SectionBackground };
|
||||
|
||||
export type SnapshotPage = {
|
||||
@@ -106,7 +106,8 @@ export type Source = {
|
||||
pages: {
|
||||
id: string; kind: string; slug: string; title: string; seoTitle: string | null; description: string | null; navLabel: string | null;
|
||||
inNav: boolean; position: number; imageId: string | null;
|
||||
sections: { id: string; type: string; variant: string | null; position: number; hidden: boolean; data: unknown }[];
|
||||
/** `background` only when a block has one, so versions published before it compare equal. */
|
||||
sections: { id: string; type: string; variant: string | null; position: number; hidden: boolean; background?: string; data: unknown }[];
|
||||
}[];
|
||||
ministries: { id: string; slug: string; name: string; summary: string | null; body: string | null; imageId: string | null; framing?: unknown; position: number }[];
|
||||
leaders: { id: string; name: string; role: string | null; bio: string | null; photoId: string | null; framing?: unknown; position: number }[];
|
||||
@@ -133,7 +134,7 @@ export function toSource(w: Awaited<ReturnType<typeof readWorkingCopy>>): Source
|
||||
pages: w.pages.map((p) => ({
|
||||
id: p.id, kind: p.kind, slug: p.slug, title: p.title, seoTitle: p.seoTitle, description: p.description, navLabel: p.navLabel, inNav: p.inNav,
|
||||
position: p.position, imageId: p.imageId,
|
||||
sections: p.sections.map((x) => ({ id: x.id, type: x.type, variant: x.variant, position: x.position, hidden: x.hidden, data: x.data })),
|
||||
sections: p.sections.map((x) => ({ id: x.id, type: x.type, variant: x.variant, position: x.position, hidden: x.hidden, ...(x.background ? { background: x.background } : {}), data: x.data })),
|
||||
})),
|
||||
ministries: w.ministries.map((m) => ({ id: m.id, slug: m.slug, name: m.name, summary: m.summary, body: m.body, imageId: m.imageId, ...withFraming(m.framing), position: m.position })),
|
||||
leaders: w.leaders.map((l) => ({ id: l.id, name: l.name, role: l.role, bio: l.bio, photoId: l.photoId, ...withFraming(l.framing), position: l.position })),
|
||||
@@ -189,7 +190,7 @@ export function snapshotFrom(source: Source, media: MediaRow[]): Snapshot {
|
||||
const data = parseSectionData(x.type, x.data);
|
||||
if (!data) continue;
|
||||
collect(data);
|
||||
sections.push({ type: x.type, variant: x.variant, data });
|
||||
sections.push({ type: x.type, variant: blockVariant(x.type, x.variant), data, ...(isSectionBackground(x.background) ? { background: x.background } : {}) });
|
||||
}
|
||||
}
|
||||
return {
|
||||
|
||||
@@ -114,6 +114,29 @@ export function headerIsTransparent(template: WebsiteTemplate, header: string, h
|
||||
export const SECTION_BACKGROUNDS = ['light', 'tint', 'accent', 'brand', 'dark'] as const;
|
||||
export type SectionBackground = (typeof SECTION_BACKGROUNDS)[number];
|
||||
|
||||
export const isSectionBackground = (v: unknown): v is SectionBackground => (SECTION_BACKGROUNDS as readonly unknown[]).includes(v);
|
||||
|
||||
/**
|
||||
* The layouts of the other pages' blocks, the default first. Stored on the block's own row
|
||||
* (`Section.variant`); like the homepage's, **an id never changes or goes away** once released,
|
||||
* and one that isn't listed (an older row's) is drawn as the default.
|
||||
*/
|
||||
export const BLOCK_VARIANTS = {
|
||||
text: ['standard', 'centred'],
|
||||
'image-text': ['image-left', 'image-right', 'image-above'],
|
||||
quote: ['centred', 'line'],
|
||||
cta: ['centred', 'banner'],
|
||||
} as const;
|
||||
|
||||
export type BlockVariantType = keyof typeof BLOCK_VARIANTS;
|
||||
|
||||
/** A block's layout as drawn: its own when it's one of its type's, else the type's default (null for an unknown type). */
|
||||
export function blockVariant(type: string, variant: string | null | undefined): string | null {
|
||||
const list = (BLOCK_VARIANTS as Record<string, readonly string[]>)[type];
|
||||
if (!list) return variant ?? null;
|
||||
return variant && list.includes(variant) ? variant : list[0]!;
|
||||
}
|
||||
|
||||
/** A homepage entry: the section, whether it shows, and its own background when it has one. */
|
||||
export type HomeEntry = { section: SectionType; hidden: boolean; background?: SectionBackground };
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ async function apply(ctx: Ctx, key: string, source: Source | null, by: Who) {
|
||||
const data = { kind: p.kind as never, slug: p.slug, title: p.title, seoTitle: p.seoTitle, description: p.description, navLabel: p.navLabel, inNav: p.inNav, position: p.position, imageId: p.imageId, archivedAt: null, ...stamp };
|
||||
await db.page.upsert({ where: { id }, create: { id, ...data }, update: data });
|
||||
await db.section.deleteMany({ where: { pageId: id } });
|
||||
for (const x of p.sections) await db.section.create({ data: { id: x.id, pageId: id, type: x.type, variant: x.variant, position: x.position, hidden: x.hidden, data: x.data as never, ...stamp } });
|
||||
for (const x of p.sections) await db.section.create({ data: { id: x.id, pageId: id, type: x.type, variant: x.variant, position: x.position, hidden: x.hidden, background: x.background ?? null, data: x.data as never, ...stamp } });
|
||||
return;
|
||||
}
|
||||
if (what === 'ministry') {
|
||||
|
||||
Reference in New Issue
Block a user