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 = { arches: [0, 1, 2, 3].map((i) => ``).join(''), blocks: [0, 1, 2, 3, 4].map((i) => ``).join(''), stairs: [0, 1, 2, 3, 4, 5].map((i) => ``).join(''), windows: Array.from({ length: 15 }, (_, i) => ``).join(''), } return `${shapes[shape]}` } export async function seedMedia(payload: Payload): Promise> { const ids: Record = {} 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 }