Files
ipal-kit/reference/src/seed/lib.ts
T
Radosław SmolińskiandClaude Opus 5.5 8adac41f92 Reference site: Example Studio on ipal-kit (reference/), index for agents, CI job
reference/ is one complete client site on the plugin (made-up company, pl/en,
MongoDB, every library block and template, token standard light/dark, forms,
consent, SEO/GEO, enforced CSP, 2FA, base + demo seeds, Coolify runbook,
smoke tests). It uses the plugin as file:.. (injected) and is not shipped.

- docs/agent/reference-site/INDEX.md (generated by scripts/reference-index.mjs,
  kept current by test/referenceIndex.test.ts)
- AGENT.md section and pointers in ipal-site, ipal-setup, ipal-reference,
  ipal-upgrade, ipal-block; release steps in PROGRAMISTA §8.1b
- CI: reference (fast) on every push, reference-full on main; doctor steps
  wired, commented until ipal-doctor ships

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-29 15:17:11 +01:00

34 lines
1.9 KiB
TypeScript

/** 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 } },
})