diff --git a/kit/ejemplos/noticia/ejemplo.json b/kit/ejemplos/noticia/ejemplo.json new file mode 100644 index 0000000..f9ae7c2 --- /dev/null +++ b/kit/ejemplos/noticia/ejemplo.json @@ -0,0 +1,6 @@ +{"out":"../../../_preview","prefix":"ejemplo_noticia","numbered":true, + "slides":[ + {"photo":"valencia.jpg","pos":"30% 60%","kicker":"VALENCIA · 29 OCT 2024","title":"Dos años de la DANA","sub":"Entradilla breve con el dato clave de la noticia.","credit":"Foto de ejemplo","ribbon":true}, + {"html":"
LO QUE PENSAMOS

Texto de opinión del partido sobre la noticia.

Lámina opcional: solo si la noticia necesita contexto.
"}, + {"html":"
Unidad, Fe y Destino
"} + ]} diff --git a/kit/ejemplos/noticia/render/ejemplo_noticia_1.png b/kit/ejemplos/noticia/render/ejemplo_noticia_1.png new file mode 100644 index 0000000..ddc9062 Binary files /dev/null and b/kit/ejemplos/noticia/render/ejemplo_noticia_1.png differ diff --git a/kit/ejemplos/noticia/render/ejemplo_noticia_2.png b/kit/ejemplos/noticia/render/ejemplo_noticia_2.png new file mode 100644 index 0000000..f61d2ef Binary files /dev/null and b/kit/ejemplos/noticia/render/ejemplo_noticia_2.png differ diff --git a/kit/ejemplos/noticia/render/ejemplo_noticia_3.png b/kit/ejemplos/noticia/render/ejemplo_noticia_3.png new file mode 100644 index 0000000..6d4d28f Binary files /dev/null and b/kit/ejemplos/noticia/render/ejemplo_noticia_3.png differ diff --git a/kit/ejemplos/noticia/valencia.jpg b/kit/ejemplos/noticia/valencia.jpg new file mode 100644 index 0000000..5acaee6 Binary files /dev/null and b/kit/ejemplos/noticia/valencia.jpg differ diff --git a/kit/noticia.mjs b/kit/noticia.mjs new file mode 100644 index 0000000..55ec5b2 --- /dev/null +++ b/kit/noticia.mjs @@ -0,0 +1,69 @@ +// 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 = `
+ ${sl.photo ? `
` : ''} +
PARTIDO NACIONALHISPANISTA
+ ${sl.credit ? `
${sl.credit}
` : ''} + ${sl.ribbon ? `` : ''} + ${sl.title || sl.kicker ? `
${sl.kicker ? `
${sl.kicker}
` : ''}${sl.title ? `

${sl.title}

` : ''}${sl.sub ? `
${sl.sub}
` : ''}
` : ''} + ${body} + ${spec.numbered && N > 1 ? `
${i + 1} / ${N}${i < N - 1 ? ' →' : ''}
` : ''} +
`; + await page.setContent(html, { waitUntil: 'load' }); + await page.screenshot({ path: path.join(out, `${spec.prefix}${N > 1 ? '_' + (i + 1) : ''}.png`), clip: { x: 0, y: 0, width: 1080, height: 1080 } }); +} +await browser.close();