// PNH · formato de NOTICIAS: foto a sangre, banda de cabecera granate y titular sobre degradado. // Uso: node noticia.mjs spec.json // spec = { out: "dir", prefix: "nombre", numbered: true, // slides: [ { photo: "ruta.jpg", pos: "50% 40%", kicker: "JEREZ · 30 OCT", title: "Titular", // sub: "Entradilla opcional", credit: "Foto: Diario de Jerez", ribbon: false, html: "" } ] } // Una lámina sin photo usa fondo granate liso (para el cierre con logo o texto). import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; import { chromium } from 'playwright-core'; const K = path.dirname(fileURLToPath(import.meta.url)); const specPath = process.argv[2]; const spec = JSON.parse(fs.readFileSync(specPath, 'utf8')); const asset = f => fs.readFileSync(path.join(K, 'assets', f)).toString('base64'); const font = f => fs.readFileSync(path.join(K, 'node_modules/@fontsource', f)).toString('base64'); const HORSE = 'data:image/png;base64,' + asset('horse.png'); const LOGO = 'data:image/png;base64,' + asset('logo_full_hd.png'); const img = p => { const f = path.isAbsolute(p) ? p : path.resolve(path.dirname(specPath), p); const ext = path.extname(f).slice(1).toLowerCase().replace('jpg', 'jpeg'); return `data:image/${ext};base64,` + fs.readFileSync(f).toString('base64'); }; const css = ` @font-face{font-family:Cinzel;font-weight:700;src:url(data:font/woff2;base64,${font('cinzel/files/cinzel-latin-700-normal.woff2')})} @font-face{font-family:Cinzel;font-weight:900;src:url(data:font/woff2;base64,${font('cinzel/files/cinzel-latin-900-normal.woff2')})} @font-face{font-family:Garamond;font-weight:500;src:url(data:font/woff2;base64,${font('eb-garamond/files/eb-garamond-latin-500-normal.woff2')})} @font-face{font-family:Garamond;font-style:italic;font-weight:500;src:url(data:font/woff2;base64,${font('eb-garamond/files/eb-garamond-latin-500-italic.woff2')})} html,body{margin:0;background:#2a0508} .s{position:relative;width:1080px;height:1080px;overflow:hidden;color:#FBF3E4;background:radial-gradient(circle at 50% 45%,#6a0a14,#3a0207)} .ph{position:absolute;left:0;right:0;top:150px;bottom:0;background-size:cover} .fade{position:absolute;left:0;right:0;bottom:0;height:560px;background:linear-gradient(to top,rgba(20,0,3,.96) 0%,rgba(40,2,6,.82) 45%,rgba(40,2,6,0) 100%)} .band{position:absolute;left:0;right:0;top:0;height:150px;background:linear-gradient(#5a0610,#3d0309);box-shadow:0 6px 18px rgba(0,0,0,.55)} .band:after{content:'';position:absolute;left:0;right:0;bottom:0;height:5px;background:#D9A63A;box-shadow:0 -9px 0 -6px #D9A63A} .hd{position:absolute;left:0;right:0;top:44px;display:flex;justify-content:center;align-items:center;gap:34px;font-family:Cinzel;font-weight:700;font-size:34px;letter-spacing:5px;color:#F2C64B} .hd img{height:62px} .cap{position:absolute;left:70px;right:70px;bottom:70px;display:flex;flex-direction:column;gap:18px} .kick{font-family:Cinzel;font-weight:700;font-size:24px;letter-spacing:6px;color:#D9A63A} .kick:before{content:'';display:inline-block;width:46px;height:3px;background:#A10F2B;vertical-align:middle;margin-right:16px} h1{margin:0;font-family:Cinzel;font-weight:900;font-size:62px;line-height:1.06;color:#FBF3E4;text-shadow:0 3px 14px rgba(0,0,0,.7);text-wrap:balance} h1 b{color:#F2C64B} .sub{font-family:Garamond;font-size:34px;line-height:1.3;color:#FBF3E4;text-shadow:0 2px 8px rgba(0,0,0,.8)} .sub b{color:#F2C64B;font-weight:500} .cred{position:absolute;right:22px;top:162px;font-family:Garamond;font-style:italic;font-size:20px;color:#FBF3E4;opacity:.85;text-shadow:0 1px 4px #000;writing-mode:vertical-rl;transform:rotate(180deg);transform-origin:center} .num{position:absolute;right:70px;bottom:30px;font-family:Cinzel;font-weight:700;font-size:20px;letter-spacing:3px;color:#D9A63A} .ribbon{position:absolute;right:60px;top:200px;width:150px} `; const browser = await chromium.launch({ executablePath: '/opt/pw-browsers/chromium', args: ['--no-sandbox'] }); const page = await browser.newPage({ viewport: { width: 1080, height: 1080 } }); const out = path.resolve(path.dirname(specPath), spec.out || '.'); fs.mkdirSync(out, { recursive: true }); const N = spec.slides.length; for (const [i, sl] of spec.slides.entries()) { const body = (sl.html || '').replaceAll('{{LOGO}}', LOGO).replaceAll('{{HORSE}}', HORSE); const html = `