mirror of
https://github.com/CasberryIndia/Physics-Notebook.git
synced 2026-12-04 04:58:17 +00:00
Use Playwright + HTML template to render og-image at 1200x628 using the vendored woff2 fonts and exact CSS tokens from common.css: - Font: DM Serif Display (matches site heading font exactly) - Mono: JetBrains Mono for tagline - BG: #F8F6F2, text: #121212, accent: #2A45B6, red: #CC2936 - Right panel: 5 concentric orbital rings, red pendulum arc + bob, muted blue sine wave, subtle dot grid - Left panel: atom SVG icon, two-line serif title, tagline, url badge - JPEG: 85KB | PNG: 80KB | 1200x628 (Twitter 2:1 compliant) - Add scripts/render-og-image.js + scripts/og-image-template.html so the image can be regenerated at any time
32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
// Renders og-image.html at 1200x628 and saves to assets/og-image.{png,jpg}
|
|
const { chromium } = require('playwright');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
|
|
(async () => {
|
|
const browser = await chromium.launch();
|
|
const page = await browser.newPage();
|
|
|
|
await page.setViewportSize({ width: 1200, height: 628 });
|
|
|
|
const htmlPath = path.resolve(__dirname, 'og-image-template.html');
|
|
await page.goto('file://' + htmlPath, { waitUntil: 'networkidle' });
|
|
|
|
// Wait for fonts to fully load
|
|
await page.waitForFunction(() => document.fonts.ready);
|
|
await page.waitForTimeout(400);
|
|
|
|
const pngPath = path.resolve(__dirname, '../assets/og-image.png');
|
|
const jpgPath = path.resolve(__dirname, '../assets/og-image.jpg');
|
|
|
|
await page.screenshot({ path: pngPath, type: 'png', fullPage: false });
|
|
await page.screenshot({ path: jpgPath, type: 'jpeg', quality: 94, fullPage: false });
|
|
|
|
await browser.close();
|
|
|
|
const pngKB = Math.round(fs.statSync(pngPath).size / 1024);
|
|
const jpgKB = Math.round(fs.statSync(jpgPath).size / 1024);
|
|
console.log(`PNG: ${pngKB} KB | JPEG: ${jpgKB} KB`);
|
|
console.log('Done — og-image.png and og-image.jpg written.');
|
|
})();
|