/** Seed value helpers — every text written once, both languages side by side (docs/seeding.md). */ export type L = { en: string; pl: string } export const tx = (pl: string, en: string): L => ({ en, pl }) const textNode = (t: string) => ({ type: 'text', detail: 0, format: 0, mode: 'normal', style: '', text: t, version: 1 }) const paragraph = (t: string) => ({ type: 'paragraph', children: [textNode(t)], direction: 'ltr', format: '', indent: 0, textFormat: 0, version: 1 }) const heading = (t: string, tag: 'h2' | 'h3') => ({ type: 'heading', children: [textNode(t)], direction: 'ltr', format: '', indent: 0, tag, version: 1 }) const root = (children: unknown[]) => ({ root: { type: 'root', children, direction: 'ltr', format: '', indent: 0, version: 1 } }) /** Rich text from paragraphs; a line starting with "## " is an h2, "### " an h3. One value per locale. */ export function rich(pl: string[], en: string[]) { const doc = (lines: string[]) => root(lines.map((l) => (l.startsWith('### ') ? heading(l.slice(4), 'h3') : l.startsWith('## ') ? heading(l.slice(3), 'h2') : paragraph(l)))) return { en: doc(en), pl: doc(pl) } } /** Plain text (blank-line paragraphs, single newlines as line breaks) → rich text, as form-builder messages expect. */ export function richMessage(text: string) { return root( text.split(/\n{2,}/).map((para) => ({ ...paragraph(''), children: para.split('\n').flatMap((line, i) => [...(i ? [{ type: 'linebreak', version: 1 }] : []), textNode(line)]), })), ) } export const header = (heading: L, intro?: L, eyebrow?: L) => ({ ...(eyebrow ? { eyebrow } : {}), heading, ...(intro ? { intro } : {}) }) /** A button / link to a page by its default-locale (pl) slug. */ export const pageLink = (label: L, slug: string, appearance: 'link' | 'primary' | 'secondary' = 'primary') => ({ link: { type: 'internal', appearance, label, page: { $page: slug } }, })