feat(paginas): fase 4, Ingeniería, Firma, Contacto y Currículum con PDF
- Colecciones equipo, firma (método y trayectoria) e ingenieria (reglas y prácticas) con esquema zod; Firma, Ingeniería y Currículum leen los mismos datos - Componentes Equipo, Metodo y Trayectoria compartidos - Contacto con datos como texto seleccionable (SITIO.sedes) - Currículum empresarial en /curriculum con estilos de impresión - scripts/cv-pdf.mjs: exporta el currículum a PDF A4 con Playwright - Listas de datos sin desbordar en 320 px Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
c72ddb73e7
commit
7fda61dc15
21 files changed
+799
-2
No files matched your search
@@ -0,0 +1,58 @@
|
||||
// Exporta /curriculum a PDF con Playwright. Requiere `npm run build` previo.
|
||||
// Sirve dist/ con un servidor estático propio (sin dependencias) y escribe el
|
||||
// PDF en dist/curriculum/collina-systems-curriculum.pdf y en salida/.
|
||||
// Uso: node scripts/cv-pdf.mjs
|
||||
import { chromium } from 'playwright';
|
||||
import http from 'node:http';
|
||||
import { createReadStream, existsSync, mkdirSync, statSync, copyFileSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const raiz = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const dist = path.join(raiz, 'dist');
|
||||
if (!existsSync(path.join(dist, 'curriculum', 'index.html'))) {
|
||||
console.error('No existe dist/curriculum/index.html. Ejecuta `npm run build` primero.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const TIPOS = { '.html': 'text/html; charset=utf-8', '.css': 'text/css', '.js': 'text/javascript', '.woff2': 'font/woff2', '.svg': 'image/svg+xml', '.png': 'image/png', '.json': 'application/json' };
|
||||
const servidor = http.createServer((req, res) => {
|
||||
let ruta = decodeURIComponent(new URL(req.url, 'http://x').pathname);
|
||||
let archivo = path.join(dist, ruta);
|
||||
if (existsSync(archivo) && statSync(archivo).isDirectory()) archivo = path.join(archivo, 'index.html');
|
||||
if (!archivo.startsWith(dist) || !existsSync(archivo)) {
|
||||
res.writeHead(404).end();
|
||||
return;
|
||||
}
|
||||
res.writeHead(200, { 'content-type': TIPOS[path.extname(archivo)] ?? 'application/octet-stream' });
|
||||
createReadStream(archivo).pipe(res);
|
||||
});
|
||||
await new Promise((r) => servidor.listen(0, '127.0.0.1', r));
|
||||
const puerto = servidor.address().port;
|
||||
|
||||
const browser = await chromium.launch();
|
||||
try {
|
||||
const page = await browser.newPage();
|
||||
await page.emulateMedia({ media: 'print', colorScheme: 'light' });
|
||||
await page.goto(`http://127.0.0.1:${puerto}/curriculum/`, { waitUntil: 'networkidle' });
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
const salidaDist = path.join(dist, 'curriculum', 'collina-systems-curriculum.pdf');
|
||||
await page.pdf({
|
||||
path: salidaDist,
|
||||
format: 'A4',
|
||||
printBackground: true,
|
||||
preferCSSPageSize: true,
|
||||
displayHeaderFooter: true,
|
||||
headerTemplate: '<span></span>',
|
||||
footerTemplate:
|
||||
'<div style="width:100%;font-size:8px;color:#777;padding:0 14mm;display:flex;justify-content:space-between;font-family:Helvetica,Arial,sans-serif"><span>Collina Systems · Currículum empresarial</span><span><span class="pageNumber"></span> / <span class="totalPages"></span></span></div>',
|
||||
margin: { top: '16mm', bottom: '18mm', left: '14mm', right: '14mm' },
|
||||
});
|
||||
mkdirSync(path.join(raiz, 'salida'), { recursive: true });
|
||||
const copia = path.join(raiz, 'salida', 'collina-systems-curriculum.pdf');
|
||||
copyFileSync(salidaDist, copia);
|
||||
console.log(`PDF generado:\n ${salidaDist}\n ${copia}`);
|
||||
} finally {
|
||||
await browser.close();
|
||||
servidor.close();
|
||||
}
|
||||
Reference in new issue
Block a user