Files
ipal-kit/reference/src/seed/media.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

68 lines
5.3 KiB
TypeScript

import type { Payload } from 'payload'
import sharp from 'sharp'
import type { L } from './lib'
/**
* Placeholder images, generated (no stock photos, no licences, nothing real): soft architectural shapes in the
* brand palette. Each is created once, matched by file name, and returned as a name → media id map.
*/
const IMAGES: { alt: L; hue: number; name: string; shape: 'arches' | 'blocks' | 'stairs' | 'windows' }[] = [
{ alt: { en: 'Abstract illustration: arches in sage green', pl: 'Abstrakcyjna ilustracja: łuki w odcieniach szałwii' }, hue: 160, name: 'arches', shape: 'arches' },
{ alt: { en: 'Abstract illustration: a stair of terracotta blocks', pl: 'Abstrakcyjna ilustracja: schody z terakotowych brył' }, hue: 50, name: 'stairs', shape: 'stairs' },
{ alt: { en: 'Abstract illustration: a façade with windows', pl: 'Abstrakcyjna ilustracja: elewacja z oknami' }, hue: 200, name: 'facade', shape: 'windows' },
{ alt: { en: 'Abstract illustration: stacked volumes', pl: 'Abstrakcyjna ilustracja: piętrzące się bryły' }, hue: 120, name: 'volumes', shape: 'blocks' },
{ alt: { en: 'Abstract illustration: a quiet interior in warm light', pl: 'Abstrakcyjna ilustracja: spokojne wnętrze w ciepłym świetle' }, hue: 70, name: 'interior', shape: 'arches' },
{ alt: { en: 'Abstract illustration: a courtyard seen from above', pl: 'Abstrakcyjna ilustracja: dziedziniec z góry' }, hue: 180, name: 'courtyard', shape: 'blocks' },
{ alt: { en: 'Abstract illustration: a timber pavilion', pl: 'Abstrakcyjna ilustracja: drewniany pawilon' }, hue: 40, name: 'pavilion', shape: 'stairs' },
{ alt: { en: 'Abstract illustration: a reading room', pl: 'Abstrakcyjna ilustracja: czytelnia' }, hue: 220, name: 'library', shape: 'windows' },
{ alt: { en: 'Portrait placeholder: Anna', pl: 'Portret zastępczy: Anna' }, hue: 150, name: 'person-anna', shape: 'arches' },
{ alt: { en: 'Portrait placeholder: Tomasz', pl: 'Portret zastępczy: Tomasz' }, hue: 30, name: 'person-tomasz', shape: 'arches' },
{ alt: { en: 'Portrait placeholder: Julia', pl: 'Portret zastępczy: Julia' }, hue: 260, name: 'person-julia', shape: 'arches' },
{ alt: { en: 'Logo placeholder: North Bank', pl: 'Logo zastępcze: North Bank' }, hue: 210, name: 'logo-north', shape: 'blocks' },
{ alt: { en: 'Logo placeholder: Oak & Co', pl: 'Logo zastępcze: Oak & Co' }, hue: 90, name: 'logo-oak', shape: 'blocks' },
{ alt: { en: 'Logo placeholder: Vistula Homes', pl: 'Logo zastępcze: Vistula Homes' }, hue: 190, name: 'logo-vistula', shape: 'blocks' },
{ alt: { en: 'Logo placeholder: Rynek Hotel', pl: 'Logo zastępcze: Rynek Hotel' }, hue: 20, name: 'logo-rynek', shape: 'blocks' },
{ alt: { en: 'Example Studio logo', pl: 'Logo Example Studio' }, hue: 160, name: 'logo-example-studio', shape: 'blocks' },
{ alt: { en: 'Example Studio icon', pl: 'Ikona Example Studio' }, hue: 160, name: 'icon-example-studio', shape: 'arches' },
]
function svg(shape: string, hue: number, w: number, h: number) {
// hsl, not oklch: sharp's SVG renderer (librsvg) does not read oklch() and paints it black
const c = (l: number, ch = 0.06) => `hsl(${hue} ${Math.round(ch * 500)}% ${Math.round(l * 100)}%)`
const shapes: Record<string, string> = {
arches: [0, 1, 2, 3].map((i) => `<path d="M${120 + i * 260} ${h} V${h * 0.45} a110 110 0 0 1 220 0 V${h}Z" fill="${c(0.55 + i * 0.08)}"/>`).join(''),
blocks: [0, 1, 2, 3, 4].map((i) => `<rect x="${80 + i * 210}" y="${h * (0.25 + (i % 3) * 0.12)}" width="180" height="${h}" fill="${c(0.5 + i * 0.07)}"/>`).join(''),
stairs: [0, 1, 2, 3, 4, 5].map((i) => `<rect x="${60 + i * 180}" y="${h * (0.75 - i * 0.1)}" width="190" height="${h}" fill="${c(0.48 + i * 0.06, 0.09)}"/>`).join(''),
windows: Array.from({ length: 15 }, (_, i) => `<rect x="${140 + (i % 5) * 200}" y="${110 + Math.floor(i / 5) * 230}" width="120" height="170" rx="60" fill="${c(0.92, 0.02)}"/>`).join(''),
}
return `<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" viewBox="0 0 ${w} ${h}"><rect width="100%" height="100%" fill="${c(0.88, 0.03)}"/>${shapes[shape]}</svg>`
}
export async function seedMedia(payload: Payload): Promise<Record<string, string>> {
const ids: Record<string, string> = {}
for (const image of IMAGES) {
const filename = `${image.name}.webp`
const found = await payload.find({ collection: 'media', limit: 1, where: { filename: { equals: filename } } })
if (found.docs[0]) {
ids[image.name] = String(found.docs[0].id)
continue
}
const portrait = image.name.startsWith('person-')
const [w, h] = portrait ? [800, 1000] : image.name.startsWith('icon-') ? [512, 512] : image.name.startsWith('logo-') ? [1200, 480] : [1600, 1000]
const data = await sharp(Buffer.from(svg(image.shape, image.hue, 1200, 900))).resize(w, h, { fit: 'cover' }).webp({ quality: 78 }).toBuffer()
const doc = await payload.create({
collection: 'media',
context: { disableRevalidate: true },
data: { alt: image.alt.pl },
file: { data, mimetype: 'image/webp', name: filename, size: data.length },
locale: 'pl',
})
await payload.update({ id: doc.id, collection: 'media', context: { disableRevalidate: true }, data: { alt: image.alt.en }, locale: 'en' })
ids[image.name] = String(doc.id)
console.log(`[seed] create media ${filename}`)
}
return ids
}