diff --git a/.github/workflows/deploy-dataops-v1.yml b/.github/workflows/deploy-dataops-v1.yml index eb1904b4..a3468200 100644 --- a/.github/workflows/deploy-dataops-v1.yml +++ b/.github/workflows/deploy-dataops-v1.yml @@ -227,12 +227,16 @@ jobs: default_key="$(awk '/BannerTemplateBundleKey:/{found=1} found && /Default:/{print $2; exit}' infra/template.full.yaml)" : "${current_key:=$default_key}" aws s3 cp "s3://$knowledge_bucket/$current_key" "$RUNNER_TEMP/current-bundle.json" - if ! node -e "const b = JSON.parse(require('fs').readFileSync(process.argv[1], 'utf8')); process.exit(b.assets?.assetLogo ? 0 : 1)" "$RUNNER_TEMP/current-bundle.json"; then - aws s3 cp "s3://$knowledge_bucket/$default_key" "$RUNNER_TEMP/current-bundle.json" - fi npm --prefix "$RUNNER_TEMP/tsx" install --no-save tsx >/dev/null + # Single source of the cover designs: the Figma frames in Banner Generator at a pinned commit. + figma_revision="$(tr -d '[:space:]' < infra/banner-generator-revision)" + git init -q "$RUNNER_TEMP/banner-generator" + git -C "$RUNNER_TEMP/banner-generator" fetch -q --depth 1 https://github.com/AI-Shipping-Labs/banner-generator.git "$figma_revision" + git -C "$RUNNER_TEMP/banner-generator" checkout -q FETCH_HEAD bundle_key="$(node --import "$RUNNER_TEMP/tsx/node_modules/tsx/dist/loader.mjs" backend/scripts/build-banner-bundle.ts \ --current "$RUNNER_TEMP/current-bundle.json" \ + --figma-dir "$RUNNER_TEMP/banner-generator/banner_generator/templates/dtc-event" \ + --figma-revision "$figma_revision" \ --out-dir "$RUNNER_TEMP/banner-bundle")" if ! aws s3 ls "s3://$knowledge_bucket/$bundle_key" >/dev/null 2>&1; then aws s3 cp "$RUNNER_TEMP/banner-bundle/$bundle_key" "s3://$knowledge_bucket/$bundle_key" --content-type application/json diff --git a/backend/e2e/banner-podcast-layout.spec.ts b/backend/e2e/banner-podcast-layout.spec.ts deleted file mode 100644 index 0a92c560..00000000 --- a/backend/e2e/banner-podcast-layout.spec.ts +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Regression: one-speaker podcast covers rendered a huge gap between title and photo, - * pushed the portrait to the bottom with the name pill against the edge, and carried - * neither date/time nor the DataTalks.Club logo. This renders the composed HTML in a - * real browser at the real canvas size and asserts layout geometry. - */ -import { test, expect } from '@playwright/test'; -import { composeBanner, type BannerJob } from '../src/banners/model'; -import { podcastOneSpeakerTemplate } from '../src/banners/podcastLayout'; - -const svg = (body: string, w = 600, h = 200) => `data:image/svg+xml;utf8,${encodeURIComponent(`${body}`)}`; -const assets = { - assetFont: '', - assetTexture: svg('', 8, 8), - assetLogo: svg(''), -}; -const portrait = svg('', 800, 800); -const titles = { - short: 'Agents', - madhu: 'From Ad-Hoc SQL to AI Agents', - long: 'Shipping Reliable LLMs and the Rise of AI Engineering: What Changes When Agents Query Live Data Every Day', -}; - -function job(layout: 'square' | 'landscape', title: string): BannerJob { - return { - id: 'j', bundleKey: 'k', cardId: 'c', title, state: 'queued', createdBy: 'u', createdAt: '', updatedAt: '', - input: { eventType: 'podcast', layout, speakers: [{ personId: 'p', portraitFileId: 'f' }], revision: 'r' }, - speakers: [{ personId: 'p', portraitFileId: 'f', name: 'Madhu Gurramkonda', personVersion: 1, checksum: 'sha256:x' }], - schedule: { date: 'Tue, 24 November 2026', time: '17:00 CET' }, - }; -} - -for (const layout of ['square', 'landscape'] as const) { - for (const [kind, title] of Object.entries(titles)) { - test(`${layout} podcast cover (${kind} title) keeps every element inside the canvas`, async ({ page }) => { - const template = podcastOneSpeakerTemplate(layout); - await page.setViewportSize({ width: template.width, height: template.height }); - await page.setContent(composeBanner(template, job(layout, title), [portrait], assets)); - const box = (selector: string) => page.locator(selector).evaluate(el => { - const r = el.getBoundingClientRect(); - return { left: r.left, top: r.top, right: r.right, bottom: r.bottom, width: r.width, height: r.height }; - }); - const { width: W, height: H } = template; - const edge = 40; - for (const selector of ['.name', '.portrait', '.title', '.when', '.logo', '.badge']) { - const b = await box(selector); - expect(b.width, `${selector} rendered`).toBeGreaterThan(20); - expect(b.left, `${selector} left`).toBeGreaterThanOrEqual(edge); - expect(b.top, `${selector} top`).toBeGreaterThanOrEqual(edge); - expect(b.right, `${selector} right`).toBeLessThanOrEqual(W - edge); - expect(b.bottom, `${selector} bottom`).toBeLessThanOrEqual(H - edge); - } - await expect(page.locator('.when')).toContainText('24 November 2026'); - await expect(page.locator('.when')).toContainText('17:00'); - expect(await page.locator('.logo').evaluate((img: HTMLImageElement) => img.complete && img.naturalWidth > 0)).toBe(true); - expect(await page.evaluate(() => document.documentElement.scrollHeight)).toBeLessThanOrEqual(H); - const [name, portraitBox, titleBox] = [await box('.name'), await box('.portrait'), await box('.title')]; - expect(name.height).toBeLessThan(260); // name wraps at most two lines - if (layout === 'square') { - // Gap between title text and photo is just the date line, never a void. - expect(portraitBox.top - titleBox.bottom).toBeLessThan(H * 0.2); - expect(portraitBox.width).toBeGreaterThan(H * 0.3); // photo is not squeezed - expect(portraitBox.top).toBeLessThan(H * 0.75); // not pushed to the bottom - } else { - expect(titleBox.right).toBeLessThanOrEqual(portraitBox.left); - expect(portraitBox.width).toBeGreaterThan(H * 0.5); - } - }); - } -} diff --git a/backend/scripts/build-banner-bundle.ts b/backend/scripts/build-banner-bundle.ts index 7e8e40b4..8c0823df 100644 --- a/backend/scripts/build-banner-bundle.ts +++ b/backend/scripts/build-banner-bundle.ts @@ -1,39 +1,37 @@ /** - * Build the next private banner template bundle from the current one: replaces the - * one-speaker podcast covers with the flow layout in src/banners/podcastLayout.ts and - * ensures the DataTalks.Club logo asset is embedded. Writes the content-addressed bundle - * to --out-dir and prints its key. + * Build the next private banner template bundle from the current one: every event cover + * that has a Figma frame (Banner Generator `dtc-event`, Figma node 3613:146) is replaced + * by that frame, exactly as designed (no date line, no logo). Combinations Figma has no + * frame for (e.g. three speakers) keep the current bundle's template. Writes the + * content-addressed bundle to --out-dir and prints its key. * - * tsx scripts/build-banner-bundle.ts --current bundle.json [--logo logo.svg] --out-dir DIR + * tsx scripts/build-banner-bundle.ts --current bundle.json --figma-dir DIR/banner_generator/templates/dtc-event \ + * --figma-revision SHA --out-dir DIR */ import { createHash } from 'node:crypto'; import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'; import { join } from 'node:path'; import type { BannerBundle } from '../src/banners/model'; -import { podcastOneSpeakerTemplate } from '../src/banners/podcastLayout'; +import { loadFigmaSource } from '../src/banners/figmaCover'; -const optionalArg = (name: string) => { const i = process.argv.indexOf(`--${name}`); return i >= 0 && process.argv[i + 1] ? process.argv[i + 1] : undefined; }; -const arg = (name: string) => { const v = optionalArg(name); if (!v) throw new Error(`--${name} is required`); return v; }; +const arg = (name: string) => { const i = process.argv.indexOf(`--${name}`); if (i < 0 || !process.argv[i + 1]) throw new Error(`--${name} is required`); return process.argv[i + 1]; }; const bundle = JSON.parse(readFileSync(arg('current'), 'utf8')) as BannerBundle; -const logoPath = optionalArg('logo'); -const assetLogo = logoPath ? `data:image/svg+xml;base64,${readFileSync(logoPath).toString('base64')}` : bundle.assets?.assetLogo; -if (!assetLogo) throw new Error('--logo is required when current bundle has no assets.assetLogo'); -const replaced = new Set(); -const templates = bundle.templates.map(t => { - if (t.eventType === 'podcast' && t.speakerCount === 1 && !t.sponsorTreatment) { replaced.add(t.layout); return podcastOneSpeakerTemplate(t.layout); } - return t; -}); -if (replaced.size !== 2) throw new Error('Current bundle has no one-speaker podcast square+landscape templates to replace'); -const baseRevision = bundle.sourceRevision.replace(/;podcast-flow-layout-v2$/, ''); +const figma = loadFigmaSource(arg('figma-dir')); +const revision = arg('figma-revision'); +if (!/^[a-f0-9]{40}$/.test(revision)) throw new Error('--figma-revision must be a full commit SHA of AI-Shipping-Labs/banner-generator'); +const key = (t: { eventType: string; layout: string; speakerCount: number; sponsorTreatment?: string }) => `${t.eventType}/${t.layout}/${t.speakerCount}/${t.sponsorTreatment || ''}`; +const figmaKeys = new Set(figma.templates.map(key)); +const kept = bundle.templates.filter(t => !figmaKeys.has(key(t))); const next: BannerBundle = { ...bundle, - sourceRevision: `${baseRevision};podcast-flow-layout-v2`, - assets: { ...bundle.assets, assetLogo }, - templates, + sourceRevision: `banner-generator:${revision};figma-3613-146`, + assets: { ...bundle.assets, ...figma.assets }, + fontAdvances: figma.advances, + templates: [...figma.templates, ...kept], }; const bytes = Buffer.from(JSON.stringify(next)); const hash = createHash('sha256').update(bytes).digest('hex'); -const key = `banner-templates/${hash}/bundle.json`; +const out = `banner-templates/${hash}/bundle.json`; mkdirSync(join(arg('out-dir'), 'banner-templates', hash), { recursive: true }); -writeFileSync(join(arg('out-dir'), key), bytes); -console.log(key); +writeFileSync(join(arg('out-dir'), out), bytes); +console.log(out); diff --git a/backend/src/banners/figmaCover.ts b/backend/src/banners/figmaCover.ts new file mode 100644 index 00000000..4f3e3874 --- /dev/null +++ b/backend/src/banners/figmaCover.ts @@ -0,0 +1,126 @@ +/** + * Figma event-banner covers (Banner Generator `dtc-event`, Figma node 3613:146). + * + * The templates are the exported Figma frames; this module only fills their slots: + * balanced title wrapping into the frame's fixed line count, name splitting, and the + * hugging name/label pills. It mirrors banner_generator/event_cover.py in the Banner + * Generator repo (single source of the design); keep the two in sync. + */ +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; +import type { BannerTemplate, FigmaCoverSpec } from './model'; + +export type FigmaManifestEntry = FigmaCoverSpec & { + template: string; eventType: string; layout: 'square' | 'landscape'; width: number; height: number; sponsorLogo: boolean; +}; +export class CoverFitError extends Error { constructor(message: string) { super(message); this.name = 'CoverFitError'; } } +export type Advances = Record; + +const MIN_SCALE = 0.55, SCALE_STEP = 0.96, WIDTH_SLACK = 1.04, HUG_LIMIT = 1.6; + +export function textWidth(text: string, size: number, advances: Advances): number { + let total = 0; + for (const ch of text) total += advances[ch] ?? 0.6; + return total * size; +} +function greedy(words: string[], size: number, limit: number, advances: Advances): string[] { + const out: string[] = []; + let line = ''; + for (const word of words) { + const candidate = `${line} ${word}`.trim(); + if (line && textWidth(candidate, size, advances) > limit) { out.push(line); line = word; } else line = candidate; + } + out.push(line); + return out; +} +export function wrapTitle(title: string, lines: number, size: number, maxWidth: number, advances: Advances): { lines: string[]; size: number } { + const words = title.split(/\s+/).filter(Boolean); + if (!words.length) throw new CoverFitError('Title is empty'); + for (let scale = 1; scale >= MIN_SCALE - 1e-9; scale *= SCALE_STEP) { + const current = size * scale; + let out = greedy(words, current, maxWidth, advances); + if (out.length <= lines && out.every(l => textWidth(l, current, advances) <= maxWidth)) { + let low = Math.max(...words.map(w => textWidth(w, current, advances))), high = maxWidth; + for (let i = 0; i < 30; i++) { const mid = (low + high) / 2; if (greedy(words, current, mid, advances).length <= out.length) high = mid; else low = mid; } + out = greedy(words, current, high, advances); + return { lines: [...out, ...Array(lines - out.length).fill('')], size: Math.round(current * 100) / 100 }; + } + } + throw new CoverFitError('Title does not fit the template lines'); +} +function splitName(name: string, lines: number, size: number, advances: Advances): string[] { + const words = name.split(/\s+/).filter(Boolean); + if (lines === 1 || words.length === 1) return [words.join(' '), ...Array(lines - 1).fill('')]; + let best = 1, bestWidth = Infinity; + for (let i = 1; i < words.length; i++) { + const width = Math.max(textWidth(words.slice(0, i).join(' '), size, advances), textWidth(words.slice(i).join(' '), size, advances)); + if (width < bestWidth) { best = i; bestWidth = width; } + } + return [words.slice(0, best).join(' '), words.slice(best).join(' ')]; +} +const num = (value: number) => String(Math.round(value * 100) / 100); + +/** Slot values (unescaped, keyed like the template slots) for one cover. */ +export function fitCover(entry: FigmaCoverSpec, advances: Advances, title: string, names: string[], label?: string): Record { + if (names.length !== entry.speakers.length) throw new CoverFitError('Speaker count does not match the template'); + const data: Record = {}; + const spec = entry.title; + const wrapped = wrapTitle(title, spec.keys.length, spec.fontSize, Math.round(spec.widestExampleLine * WIDTH_SLACK), advances); + spec.keys.forEach((key, i) => { data[key] = wrapped.lines[i]; }); + data.title_font_size = String(Math.round(wrapped.size * 100) / 100); + const labelText = label ?? entry.label.default; + const pill = entry.label.pill; + const wanted = textWidth(labelText, entry.label.fontSize, advances) + 2 * pill.textPad; + data[entry.label.key] = labelText; + data.label_pill_width = num(wanted > pill.pillWidth + 3 ? wanted : pill.pillWidth); + entry.speakers.forEach((speaker, i) => { + const parts = splitName(names[i], speaker.nameKeys.length, speaker.fontSize, advances); + speaker.nameKeys.forEach((key, j) => { data[key] = parts[j]; }); + const widest = Math.max(...parts.map(p => textWidth(p, speaker.fontSize, advances))); + if (speaker.pill.hug) { + const width = widest + 2 * speaker.pill.textPad; + if (width > speaker.pill.pillWidth * HUG_LIMIT) throw new CoverFitError('Speaker name is too long for the name pill'); + data[`speaker${i + 1}_pill_width`] = num(width); + data[`speaker${i + 1}_pill_x`] = num(speaker.pill.centerX - width / 2); + } else if (widest > speaker.pill.pillWidth * 0.92) throw new CoverFitError('Speaker name is too long for the name pill'); + }); + return data; +} + +/** Convert a Banner Generator `dtc-event` template into a self-contained bundle template. */ +export function figmaBundleTemplate(entry: FigmaManifestEntry, html: string): BannerTemplate { + const converted = html + .replace(//, '') + .replace(/\.\.\/assets\/texture\.png/g, '{{assetTexture}}') + .replace(/\.\.\/assets\/icon-workshop\.png/g, '{{assetIcon}}') + .replace(/\$\{(\w+)\}/g, '{{$1}}'); + return { + id: `figma-${entry.template}`, eventType: entry.eventType as BannerTemplate['eventType'], layout: entry.layout, + speakerCount: entry.speakers.length, width: entry.width, height: entry.height, html: converted, + ...(entry.sponsorLogo ? { sponsorTreatment: 'approved-logo' as const } : {}), + figma: { title: entry.title, label: entry.label, speakers: entry.speakers }, + }; +} + +export type FigmaSource = { entries: FigmaManifestEntry[]; templates: BannerTemplate[]; advances: Advances; assets: Record }; +/** Read a checkout of banner_generator/templates/dtc-event. Frames without a DataOps event type (open-source spotlight) are skipped. */ +export function loadFigmaSource(dir: string): FigmaSource { + const entries = (JSON.parse(readFileSync(join(dir, 'manifest.json'), 'utf8')) as FigmaManifestEntry[]).filter(e => ['workshop', 'webinar', 'podcast'].includes(e.eventType)); + const templates = entries.map(e => figmaBundleTemplate(e, readFileSync(join(dir, e.template, 'template.html'), 'utf8'))); + const seen = new Set(); + for (const t of templates) { + const key = `${t.eventType}/${t.layout}/${t.speakerCount}/${t.sponsorTreatment || ''}`; + if (seen.has(key)) throw new Error(`Two Figma frames map to the same DataOps template: ${key}`); + seen.add(key); + } + const data = (file: string, type: string) => `data:${type};base64,${readFileSync(join(dir, 'assets', file)).toString('base64')}`; + return { + entries, templates, + advances: JSON.parse(readFileSync(join(dir, 'font-metrics.json'), 'utf8')).advance, + assets: { + assetFont: readFileSync(join(dir, 'assets', 'ubuntu.css'), 'utf8'), + assetTexture: data('texture.png', 'image/png'), + assetIcon: data('icon-workshop.png', 'image/png'), + }, + }; +} diff --git a/backend/src/banners/model.ts b/backend/src/banners/model.ts index b87269f5..2b34b834 100644 --- a/backend/src/banners/model.ts +++ b/backend/src/banners/model.ts @@ -1,5 +1,6 @@ import { createHash } from 'node:crypto'; import type { Card } from '../types'; +import { fitCover } from './figmaCover'; export type BannerInput = { eventType: 'workshop' | 'webinar' | 'podcast'; @@ -22,12 +23,21 @@ export type BannerJob = { schedule?: BannerSchedule; }; export type BannerSchedule = { date?: string; time?: string }; +/** Slot spec of a Figma frame from Banner Generator's `dtc-event/manifest.json` (see figmaCover.ts). */ +export type FigmaPill = { pillWidth: number; pillX: number; textPad: number; hug?: boolean; centerX?: number }; +export type FigmaCoverSpec = { + title: { keys: string[]; fontSize: number; widestExampleLine: number }; + label: { key: string; default: string; fontSize: number; pill: FigmaPill }; + speakers: { nameKeys: string[]; fontSize: number; portrait: string; pill: Required }[]; +}; export type BannerTemplate = { id: string; eventType: BannerInput['eventType']; layout: BannerInput['layout']; speakerCount: number; width: number; height: number; html: string; sponsorTreatment?: 'approved-logo'; + /** Present on templates imported from the Figma event banners: text is fitted into the frame's fixed slots. */ + figma?: FigmaCoverSpec; }; -export type BannerBundle = { schema: 'dataops.banner-templates.v1'; sourceRevision: string; assets?: Record; templates: BannerTemplate[] }; +export type BannerBundle = { schema: 'dataops.banner-templates.v1'; sourceRevision: string; assets?: Record; fontAdvances?: Record; templates: BannerTemplate[] }; export class BannerInputError extends Error {} export function parseBannerInput(value: unknown): BannerInput { const data = value as Partial | null; @@ -78,7 +88,7 @@ export function portraitContentType(bytes: Buffer): string { export function escapeHtml(value: string): string { return value.replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]!); } -export function composeBanner(template: BannerTemplate, job: BannerJob, portraits: string[], assets: Record = {}, sponsorLogo?: string): string { +export function composeBanner(template: BannerTemplate, job: BannerJob, portraits: string[], assets: Record = {}, sponsorLogo?: string, fontAdvances: Record = {}): string { const titleArea = job.input.layout === 'landscape' ? (job.speakers.length === 3 ? 2120 * 390 : 1260 * 810) : 1800 * 600; const values: Record = { ...Object.fromEntries(Object.entries(assets).filter(([key]) => /^asset[A-Za-z]+$/.test(key))), @@ -89,9 +99,15 @@ export function composeBanner(template: BannerTemplate, job: BannerJob, portrait eventWhen: escapeHtml([job.schedule?.date, job.schedule?.time].filter(Boolean).join(' · ')), titleFontSize: String(Math.min(150, Math.floor(Math.sqrt(titleArea / (Math.max(job.title.length, 20) * 0.72))))), }; - if (sponsorLogo) values.sponsorLogo = sponsorLogo; - job.speakers.forEach((s, i) => { values[`speaker${i + 1}Name`] = escapeHtml(s.name); values[`speaker${i + 1}Portrait`] = portraits[i]; }); - const html = template.html.replace(/\{\{([a-zA-Z0-9]+)\}\}/g, (_, key: string) => { + if (sponsorLogo) { values.sponsorLogo = sponsorLogo; values.sponsor_logo = sponsorLogo; } + job.speakers.forEach((s, i) => { values[`speaker${i + 1}Name`] = escapeHtml(s.name); values[`speaker${i + 1}Portrait`] = portraits[i]; values[`speaker${i + 1}_portrait`] = portraits[i]; }); + if (template.figma) { + // Figma frames fix the line count and pill sizes: fit the card's text into them (no date line, no logo: not in the design). + const override = job.input.eventLabel ? (template.figma.label.default === template.figma.label.default.toUpperCase() ? job.input.eventLabel.toUpperCase() : job.input.eventLabel) : undefined; + const fitted = fitCover(template.figma, fontAdvances, job.title, job.speakers.map(s => s.name), override); + for (const [key, value] of Object.entries(fitted)) values[key] = escapeHtml(value); + } + const html = template.html.replace(/\{\{([a-zA-Z0-9_]+)\}\}/g, (_, key: string) => { if (!(key in values)) throw new Error('Unknown banner template field'); return values[key]; }); diff --git a/backend/src/banners/podcastLayout.ts b/backend/src/banners/podcastLayout.ts deleted file mode 100644 index f668e4e7..00000000 --- a/backend/src/banners/podcastLayout.ts +++ /dev/null @@ -1,60 +0,0 @@ -import type { BannerTemplate } from './model'; - -/** - * One-speaker podcast covers (square 2000x2000, landscape 2400x1350). - * - * Flow layout, not absolute coordinates: the earlier template pinned the title at a - * fixed top and the portrait at a fixed y, so a one- or two-line title left a huge - * empty gap and the portrait + name pill sat against the bottom edge. Here the title - * block sizes to its text and the portrait takes whatever height remains, so the gap - * is only the date line, and every element is inside the canvas by construction. - * Fields: title, titleFontSize, eventLabel, eventWhen (date · time), speaker1Name, - * speaker1Portrait, assetFont, assetTexture, assetLogo. - */ -const MIC = ''; - -const BASE_CSS = `*{box-sizing:border-box}html,body{margin:0;overflow:hidden} -body{background:white url('{{assetTexture}}') repeat;font-family:Ubuntu,sans-serif;color:#285d9d;font-weight:700} -.canvas{display:flex}.badge{display:flex;align-items:center;gap:34px}.mic{width:150px;height:150px} -.badge span{font-size:72px;line-height:1.2;padding:20px 26px;background:#285d9d;color:white;border-radius:25px;text-transform:uppercase} -.logo{height:110px;width:auto;display:block} -.title{font-size:{{titleFontSize}}px;line-height:1.14;overflow-wrap:break-word;margin:0} -.when{font-size:64px;line-height:1.2;color:#285d9d;white-space:nowrap} -.when:empty{display:none} -.stage{display:flex;flex-direction:column;align-items:center;min-height:0} -.portrait{flex:1 1 0;min-height:0;aspect-ratio:1/1;border:9px solid #285d9d;border-radius:50%;object-fit:cover;background:white} -.name{position:relative;margin-top:-78px;max-width:100%;background:#285d9d;color:white;border-radius:25px;padding:16px 60px;font-size:68px;line-height:1.12;text-align:center;overflow-wrap:break-word}`; - -const SQUARE_CSS = `html,body{width:2000px;height:2000px} -.canvas{flex-direction:column;width:2000px;height:2000px;padding:110px 140px 120px} -.head{display:flex;align-items:center;justify-content:space-between} -.title{margin-top:60px;text-align:center} -.when{margin-top:36px;text-align:center} -.stage{flex:1 1 0;margin-top:40px}`; - -const LANDSCAPE_CSS = `html,body{width:2400px;height:1350px} -.canvas{flex-direction:row;width:2400px;height:1350px;padding:110px 140px 100px;gap:80px} -.left{flex:1 1 0;min-width:0;display:flex;flex-direction:column} -.title{flex:1 1 0;min-height:0;display:flex;align-items:center;overflow:hidden} -.foot{display:flex;align-items:center;justify-content:space-between;gap:40px} -.stage{flex:0 0 820px;align-self:center}.stage .portrait{flex:none;width:100%}`; - -function podcastOneSpeakerHtml(layout: 'square' | 'landscape'): string { - const css = BASE_CSS + (layout === 'square' ? SQUARE_CSS : LANDSCAPE_CSS); - const person = '
{{speaker1Name}}
'; - const badge = `
${MIC}{{eventLabel}}
`; - const logo = ''; - const when = '
{{eventWhen}}
'; - const body = layout === 'square' - ? `
${badge}${logo}
{{title}}
${when}${person}
` - : `
${badge}
{{title}}
${when}${logo}
${person}
`; - return `${body}`; -} - -export function podcastOneSpeakerTemplate(layout: 'square' | 'landscape'): BannerTemplate { - return { - id: `dtc-podcast-${layout}-1-v2`, eventType: 'podcast', layout, speakerCount: 1, - width: layout === 'square' ? 2000 : 2400, height: layout === 'square' ? 2000 : 1350, - html: podcastOneSpeakerHtml(layout), - }; -} diff --git a/backend/src/banners/service.ts b/backend/src/banners/service.ts index 194ef678..942d2cc5 100644 --- a/backend/src/banners/service.ts +++ b/backend/src/banners/service.ts @@ -19,6 +19,7 @@ export function bannerFailureCode(error: unknown, stage: string): string { if (error instanceof BannerFailure) return error.code; const name = (error as { name?: string })?.name; if (name === 'CodeArtifactUserPendingException' || name === 'ResourceNotReadyException') return 'renderer-cold-activating'; + if (name === 'CoverFitError') return 'title-or-name-does-not-fit-template'; if (name === 'AccessDeniedException' || name === 'AccessDenied') return `${stage}-access-denied`; if (name === 'TooManyRequestsException' || name === 'TimeoutError' || name === 'ServiceException') return `${stage}-temporarily-unavailable`; return `${stage}-failed`; @@ -95,7 +96,7 @@ export async function renderBannerJob(client: DynamoDBDocumentClient, id: string if (bundle.schema !== 'dataops.banner-templates.v1' || !bundle.sourceRevision) throw new BannerFailure('invalid-template-bundle'); const template = bundle.templates.find(t => t.eventType === job.input.eventType && t.layout === job.input.layout && t.speakerCount === job.speakers.length && t.sponsorTreatment === job.input.sponsorTreatment); if (!template || template.width < 1 || template.height < 1 || template.width > 4000 || template.height > 4000) throw new BannerFailure('unsupported-template'); - if (job.input.eventLabel && !template.html.includes('{{eventLabel}}')) throw new BannerFailure('unsupported-event-label'); + if (job.input.eventLabel && !(template.html.includes('{{eventLabel}}') || template.html.includes('{{label}}'))) throw new BannerFailure('unsupported-event-label'); stage = 'portrait'; const portraits: string[] = []; for (const speaker of job.speakers) { @@ -114,7 +115,7 @@ export async function renderBannerJob(client: DynamoDBDocumentClient, id: string if (checksum(bytes) !== job.sponsorLogo.checksum) throw new BannerFailure('sponsor-logo-checksum-mismatch'); logoData = `data:${portraitContentType(bytes)};base64,${bytes.toString('base64')}`; } - const html = composeBanner(template, job, portraits, bundle.assets, logoData); + const html = composeBanner(template, job, portraits, bundle.assets, logoData, bundle.fontAdvances); const prefix = `cards/${job.cardId}/banners/${id}`; const inputKey = `${prefix}/input.html`; const outputKey = `${prefix}/banner.png`; diff --git a/backend/tests/figma-cover.test.ts b/backend/tests/figma-cover.test.ts new file mode 100644 index 00000000..da3bcaa5 --- /dev/null +++ b/backend/tests/figma-cover.test.ts @@ -0,0 +1,44 @@ +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { join } from 'node:path'; +import { loadFigmaSource, fitCover, wrapTitle, CoverFitError } from '../src/banners/figmaCover'; +import { composeBanner, type BannerJob } from '../src/banners/model'; + +const source = loadFigmaSource(join(__dirname, 'fixtures/figma-cover')); +const [template] = source.templates; +const job = (title: string, name: string, label?: 'Live Q&A'): BannerJob => ({ + id: 'j', bundleKey: 'k', cardId: 'c', title, state: 'queued', createdBy: 'u', createdAt: '', updatedAt: '', + input: { eventType: 'podcast', layout: 'square', speakers: [{ personId: 'p', portraitFileId: 'f' }], revision: 'r', ...(label ? { eventLabel: label } : {}) }, + speakers: [{ personId: 'p', portraitFileId: 'f', name, personVersion: 1, checksum: 'sha256:x' }], + schedule: { date: 'Mon, 30 November 2026', time: '17:00 CET' }, +}); + +test('Figma podcast square keeps the Figma design: PODCAST pill, mic, centred title, name pill, no date line, no logo', () => { + assert.equal(template.id, 'figma-podcast-1-speaker-luma'); + const html = composeBanner(template, job('From HR Reports to People Analytics with AI', 'Sofiia Hordiienko'), ['data:image/png;base64,AAAA'], source.assets, undefined, source.advances); + assert.ok(!/\{\{|\$\{/.test(html)); + assert.match(html, /viewBox="982 1008 2000 2000"/); + assert.match(html, /font-size="150"/); + assert.match(html, />PODCASTSofiiaHordiienkoFrom HR Reports { + const entry = template.figma!; + const adv = source.advances; + const short = wrapTitle('From HR Reports to People Analytics with AI', 3, 150, 1690, adv); + assert.equal(short.size, 150); + assert.ok(short.lines.every(Boolean)); + const long = wrapTitle('Shipping Reliable LLMs and the Rise of AI Engineering: What Changes When Agents Query Live Data', 3, 150, 1690, adv); + assert.ok(long.size < 150); + assert.throws(() => fitCover(entry, adv, 'word '.repeat(200), ['A B']), CoverFitError); +}); + +test('Live Q&A override keeps the label inside a pill that is never narrower than the Figma pill', () => { + const html = composeBanner(template, job('A title', 'Ann Lee', 'Live Q&A'), ['data:image/png;base64,AAAA'], source.assets, undefined, source.advances); + assert.match(html, /LIVE Q&A/); + assert.ok(Number(/= 422); +}); diff --git a/backend/tests/fixtures/figma-cover/assets/icon-workshop.png b/backend/tests/fixtures/figma-cover/assets/icon-workshop.png new file mode 100644 index 00000000..c1b0730e --- /dev/null +++ b/backend/tests/fixtures/figma-cover/assets/icon-workshop.png @@ -0,0 +1 @@ +x \ No newline at end of file diff --git a/backend/tests/fixtures/figma-cover/assets/texture.png b/backend/tests/fixtures/figma-cover/assets/texture.png new file mode 100644 index 00000000..c1b0730e --- /dev/null +++ b/backend/tests/fixtures/figma-cover/assets/texture.png @@ -0,0 +1 @@ +x \ No newline at end of file diff --git a/backend/tests/fixtures/figma-cover/assets/ubuntu.css b/backend/tests/fixtures/figma-cover/assets/ubuntu.css new file mode 100644 index 00000000..c1845c2f --- /dev/null +++ b/backend/tests/fixtures/figma-cover/assets/ubuntu.css @@ -0,0 +1 @@ +@font-face{font-family:Ubuntu} \ No newline at end of file diff --git a/backend/tests/fixtures/figma-cover/font-metrics.json b/backend/tests/fixtures/figma-cover/font-metrics.json new file mode 100644 index 00000000..4d5a28bc --- /dev/null +++ b/backend/tests/fixtures/figma-cover/font-metrics.json @@ -0,0 +1,209 @@ +{ +"font": "Ubuntu Bold", +"advance": { +" ": 0.237, +"!": 0.2833, +"\"": 0.449, +"#": 0.6887, +"$": 0.564, +"%": 0.8988, +"&": 0.6923, +"'": 0.2455, +"(": 0.3458, +")": 0.3458, +"*": 0.4953, +"+": 0.564, +",": 0.246, +"-": 0.3272, +".": 0.246, +"/": 0.4198, +"0": 0.564, +"1": 0.564, +"2": 0.564, +"3": 0.564, +"4": 0.564, +"5": 0.564, +"6": 0.564, +"7": 0.564, +"8": 0.564, +"9": 0.564, +":": 0.246, +";": 0.246, +"<": 0.564, +"=": 0.564, +">": 0.564, +"?": 0.4385, +"@": 0.9665, +"A": 0.7033, +"B": 0.6627, +"C": 0.6392, +"D": 0.7292, +"E": 0.5948, +"F": 0.562, +"G": 0.6923, +"H": 0.7248, +"I": 0.301, +"J": 0.5198, +"K": 0.6653, +"L": 0.5495, +"M": 0.89, +"N": 0.7455, +"O": 0.7865, +"P": 0.6325, +"Q": 0.7865, +"R": 0.6562, +"S": 0.5675, +"T": 0.5995, +"U": 0.701, +"V": 0.7003, +"W": 0.942, +"X": 0.6603, +"Y": 0.6405, +"Z": 0.599, +"[": 0.3575, +"\\": 0.4198, +"]": 0.3575, +"^": 0.564, +"_": 0.4978, +"`": 0.306, +"a": 0.5433, +"b": 0.5992, +"c": 0.4913, +"d": 0.5992, +"e": 0.576, +"f": 0.4118, +"g": 0.5893, +"h": 0.5845, +"i": 0.2775, +"j": 0.2775, +"k": 0.5605, +"l": 0.3025, +"m": 0.8622, +"n": 0.5845, +"o": 0.6015, +"p": 0.5992, +"q": 0.5992, +"r": 0.4113, +"s": 0.4723, +"t": 0.4313, +"u": 0.5845, +"v": 0.5345, +"w": 0.782, +"x": 0.5417, +"y": 0.5308, +"z": 0.49, +"{": 0.3595, +"|": 0.3088, +"}": 0.3595, +"~": 0.564, +"À": 0.7033, +"Á": 0.7033, +"Â": 0.7033, +"Ã": 0.7033, +"Ä": 0.7033, +"Å": 0.7033, +"Æ": 0.9765, +"Ç": 0.6392, +"È": 0.5948, +"É": 0.5948, +"Ê": 0.5948, +"Ë": 0.5948, +"Ì": 0.301, +"Í": 0.301, +"Î": 0.301, +"Ï": 0.301, +"Ñ": 0.7455, +"Ò": 0.7865, +"Ó": 0.7865, +"Ô": 0.7865, +"Õ": 0.7865, +"Ö": 0.7865, +"Ø": 0.7865, +"Ù": 0.701, +"Ú": 0.701, +"Û": 0.701, +"Ü": 0.701, +"Ý": 0.6405, +"ß": 0.645, +"à": 0.5433, +"á": 0.5433, +"â": 0.5433, +"ã": 0.5433, +"ä": 0.5433, +"å": 0.5433, +"æ": 0.8695, +"ç": 0.4913, +"è": 0.576, +"é": 0.576, +"ê": 0.576, +"ë": 0.576, +"ì": 0.2775, +"í": 0.2775, +"î": 0.2775, +"ï": 0.2775, +"ñ": 0.5845, +"ò": 0.6015, +"ó": 0.6015, +"ô": 0.6015, +"õ": 0.6015, +"ö": 0.6015, +"ø": 0.6015, +"ù": 0.5845, +"ú": 0.5845, +"û": 0.5845, +"ü": 0.5845, +"ý": 0.5308, +"ÿ": 0.5308, +"Ā": 0.7033, +"ā": 0.5433, +"Ć": 0.6392, +"ć": 0.4913, +"Č": 0.6392, +"č": 0.4913, +"Đ": 0.741, +"đ": 0.601, +"Ē": 0.5948, +"ē": 0.576, +"Ę": 0.5948, +"ę": 0.576, +"Ě": 0.5948, +"ě": 0.576, +"Ğ": 0.6923, +"ğ": 0.5893, +"İ": 0.301, +"ı": 0.2775, +"Ł": 0.5767, +"ł": 0.3397, +"Ń": 0.7455, +"ń": 0.5845, +"Ō": 0.7865, +"ō": 0.6015, +"Œ": 0.9955, +"œ": 0.9385, +"Ř": 0.6562, +"ř": 0.4113, +"Ś": 0.5675, +"ś": 0.4723, +"Ş": 0.5675, +"ş": 0.4723, +"Š": 0.5675, +"š": 0.4723, +"Ū": 0.701, +"ū": 0.5845, +"Ź": 0.599, +"ź": 0.49, +"Ż": 0.599, +"ż": 0.49, +"Ž": 0.599, +"ž": 0.49, +"–": 0.499, +"—": 0.999, +"‘": 0.24, +"’": 0.24, +"“": 0.4402, +"”": 0.4402, +"…": 0.999, +"·": 0.246, +"•": 0.363 +} +} \ No newline at end of file diff --git a/backend/tests/fixtures/figma-cover/manifest.json b/backend/tests/fixtures/figma-cover/manifest.json new file mode 100644 index 00000000..a28f796b --- /dev/null +++ b/backend/tests/fixtures/figma-cover/manifest.json @@ -0,0 +1,50 @@ +[ + { + "template": "podcast-1-speaker-luma", + "sourceFrame": "Podcast - 1 speaker (Luma)", + "figmaNode": "3613:146", + "eventType": "podcast", + "layout": "square", + "width": 2000, + "height": 2000, + "speakerCount": 1, + "sponsorLogo": false, + "label": { + "key": "label", + "default": "PODCAST", + "fontSize": 80.0, + "pill": { + "pillWidth": 422.0, + "pillX": 1272.0, + "textPad": 20.45 + } + }, + "title": { + "keys": [ + "title_line_1", + "title_line_2", + "title_line_3" + ], + "fontSize": 150.0, + "align": "center", + "widestExampleLine": 1624 + }, + "speakers": [ + { + "nameKeys": [ + "speaker1_name_line_1", + "speaker1_name_line_2" + ], + "fontSize": 85.0, + "portrait": "speaker1_portrait", + "pill": { + "pillWidth": 960.0, + "pillX": 1483.0, + "textPad": 189.35, + "hug": false, + "centerX": 1959.09 + } + } + ] + } +] \ No newline at end of file diff --git a/backend/tests/fixtures/figma-cover/podcast-1-speaker-luma/template.html b/backend/tests/fixtures/figma-cover/podcast-1-speaker-luma/template.html new file mode 100644 index 00000000..5eec3699 --- /dev/null +++ b/backend/tests/fixtures/figma-cover/podcast-1-speaker-luma/template.html @@ -0,0 +1,45 @@ + + + + + + + + + + + + +${label} + + + +${title_line_1}${title_line_2}${title_line_3} + + + + + + + + + + + + + + +${speaker1_name_line_1}${speaker1_name_line_2} + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/card-banners.md b/docs/card-banners.md index f8747e5b..8516a972 100644 --- a/docs/card-banners.md +++ b/docs/card-banners.md @@ -78,6 +78,23 @@ and attachment failure. Provider payloads and signed URLs are excluded from durable errors. A renderer cold-activation failure can be retried with the same request after activation completes. -## One-speaker podcast layout +## Design source: the Figma frames -The one-speaker podcast covers are generated from `backend/src/banners/podcastLayout.ts` (flow layout: the title sizes to its text and the portrait takes the remaining height, so a short title cannot leave a gap or push the name pill off the canvas). During deployment, `deploy-dataops-v1.yml` runs `backend/scripts/build-banner-bundle.ts` to rewrite those two templates with `assetLogo` into a content-addressed bundle, uploads it to the knowledge bucket if missing, and passes `BannerTemplateBundleKey` to CloudFormation. `backend/e2e/banner-podcast-layout.spec.ts` renders both sizes in Chromium and asserts geometry. +Cover designs have a single source: the exported Figma frames of *Templates -> Event Banners* +(node 3613:146) in Banner Generator, `banner_generator/templates/dtc-event/` (see its +`manifest.json`). Do not author layouts in DataOps. `infra/banner-generator-revision` pins the +Banner Generator commit; `deploy-dataops-v1.yml` checks it out and runs +`backend/scripts/build-banner-bundle.ts`, which replaces every bundle template that has a Figma frame +(event type x layout x speaker count x sponsored) with that frame and keeps the current bundle's +template for combinations Figma has no frame for (for example three speakers). The content-addressed +bundle is uploaded to the knowledge bucket if missing and passed as `BannerTemplateBundleKey`. + +Figma fixes the line count of title and names, so `composeBanner` fits the Card text into the frame +(`backend/src/banners/figmaCover.ts`, mirror of Banner Generator `event_cover.py`): balanced wrapping of +the title into the frame's lines at the Figma font size (shrinks to at most 55% only for long titles), +name split over two lines where the frame has two, hugging name pills and the label pill sized to +the text. A title or name that cannot fit fails the job with `title-or-name-does-not-fit-template`. +The Figma designs contain no date line and no DataTalks.Club logo outside the frames that draw one +themselves; `eventDate`/`eventTime`/`eventWhen` stay available to templates but Figma frames do not use them. +To change a design, change it in Figma, re-import into Banner Generator +(`scripts/import_figma_event_banners.py`), then bump `infra/banner-generator-revision`. diff --git a/infra/banner-generator-revision b/infra/banner-generator-revision new file mode 100644 index 00000000..32fc4cce --- /dev/null +++ b/infra/banner-generator-revision @@ -0,0 +1 @@ +b466d5aa770d1886c9abf18037cc17e28305f020