feat(seo): imagen Open Graph generada con las fuentes del sitio
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
aa0fcc5691
commit
2d4283163d
3 files changed
+49
No files matched your search
@@ -14,3 +14,5 @@ npm run preview # sirve dist/
|
||||
|
||||
Comprobaciones: `npm run verificar:prohibidas`, `npm run verificar:metricas`,
|
||||
`node scripts/capturas.mjs <raíz> <salida> "/,/proyectos"`.
|
||||
Imagen Open Graph: `node scripts/og.mjs` regenera `public/img/og.png` con las
|
||||
fuentes del sitio.
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 42 KiB |
@@ -0,0 +1,47 @@
|
||||
// Genera public/img/og.png (1200×630) con las fuentes del sitio usando Playwright.
|
||||
// Uso: node scripts/og.mjs
|
||||
import { chromium } from 'playwright';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import path from 'node:path';
|
||||
import { mkdtempSync, writeFileSync, rmSync } from 'node:fs';
|
||||
import os from 'node:os';
|
||||
|
||||
const raiz = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const fuentes = path.join(raiz, 'public', 'fonts');
|
||||
const html = `<!doctype html><html lang="es"><head><meta charset="utf-8"><style>
|
||||
@font-face{font-family:'Fraunces';src:url('file://${fuentes}/fraunces-latin-opsz-normal.woff2') format('woff2-variations');font-weight:100 900}
|
||||
@font-face{font-family:'Instrument Sans';src:url('file://${fuentes}/instrument-sans-latin-wght-normal.woff2') format('woff2-variations');font-weight:400 700}
|
||||
@font-face{font-family:'JetBrains Mono';src:url('file://${fuentes}/jetbrains-mono-latin-wght-normal.woff2') format('woff2-variations');font-weight:100 800}
|
||||
html,body{margin:0;width:1200px;height:630px;background:#07172a;color:#fff;overflow:hidden}
|
||||
.c{padding:72px 80px;position:relative;height:630px;box-sizing:border-box}
|
||||
h1{font-family:'Fraunces';font-weight:700;font-size:92px;line-height:1;margin:0;letter-spacing:-.015em;font-variation-settings:'opsz' 144}
|
||||
h1 small{font-family:'Instrument Sans';font-weight:600;font-size:22px;letter-spacing:.2em;text-transform:uppercase;color:#8a94a3;margin-left:14px;vertical-align:middle}
|
||||
p{font-family:'Instrument Sans';font-size:34px;line-height:1.4;color:#b4bdca;max-width:900px;margin:36px 0 0}
|
||||
.d{position:absolute;left:80px;bottom:72px;font-family:'JetBrains Mono';font-size:24px;color:#7f9cff}
|
||||
svg{position:absolute;right:80px;bottom:60px}
|
||||
</style></head><body><div class="c">
|
||||
<h1>Collina<small>Systems</small></h1>
|
||||
<p>Sistemas para la operación: ventas, inventario, cobranza, flotillas, contratos, estaciones de servicio, personal.</p>
|
||||
<div class="d">collinasystems.com.mx</div>
|
||||
<svg width="300" height="120" viewBox="0 0 300 120" fill="none" stroke="#7f9cff" stroke-opacity=".7" stroke-width="2"><rect x="1" y="40" width="80" height="40" rx="5"/><rect x="110" y="20" width="80" height="80" rx="5"/><rect x="219" y="40" width="80" height="40" rx="5"/><path d="M81 60h29M190 60h29"/></svg>
|
||||
</div></body></html>`;
|
||||
|
||||
const browser = await chromium.launch();
|
||||
const page = await browser.newPage({ viewport: { width: 1200, height: 630 }, deviceScaleFactor: 1 });
|
||||
// Se abre como archivo para que las fuentes file:// carguen (desde about:blank no se permite).
|
||||
const tmp = mkdtempSync(path.join(os.tmpdir(), 'og-'));
|
||||
const archivo = path.join(tmp, 'og.html');
|
||||
writeFileSync(archivo, html);
|
||||
await page.goto('file://' + archivo, { waitUntil: 'load' });
|
||||
await page.evaluate(() =>
|
||||
Promise.all([
|
||||
document.fonts.load("700 92px 'Fraunces'"),
|
||||
document.fonts.load("600 22px 'Instrument Sans'"),
|
||||
document.fonts.load("400 34px 'Instrument Sans'"),
|
||||
document.fonts.load("400 24px 'JetBrains Mono'"),
|
||||
]).then(() => document.fonts.ready),
|
||||
);
|
||||
await page.screenshot({ path: path.join(raiz, 'public', 'img', 'og.png'), type: 'png' });
|
||||
await browser.close();
|
||||
rmSync(tmp, { recursive: true, force: true });
|
||||
console.log('public/img/og.png generado');
|
||||
Reference in new issue
Block a user