Voxley / website · voxley.si / tools / render-social-card.js
| 1 | // With Chrome and Playwright installed, run: node tools/render-social-card.js |
| 2 | // Copy the reviewed social-card.png from Expand into the site when publishing it. |
| 3 | const fs = require('node:fs'); |
| 4 | const path = require('node:path'); |
| 5 | const { pathToFileURL } = require('node:url'); |
| 6 | const { chromium } = require('playwright'); |
| 7 | |
| 8 | const expand = '/Volumes/Expand'; |
| 9 | const output = path.join(expand, 'Codex Media', 'Voxley', 'Website Art'); |
| 10 | |
| 11 | async function renderSocialCard() { |
| 12 | if (!fs.existsSync(expand) || fs.statSync(expand).dev === fs.statSync(path.dirname(expand)).dev) { |
| 13 | throw new Error('Mount Expand before rendering the Voxley social card.'); |
| 14 | } |
| 15 | |
| 16 | const temporary = path.join(output, 'tmp'); |
| 17 | fs.mkdirSync(temporary, { recursive: true }); |
| 18 | process.env.TMPDIR = temporary; |
| 19 | |
| 20 | const browser = await chromium.launch({ channel: 'chrome' }); |
| 21 | try { |
| 22 | const page = await browser.newPage({ viewport: { width: 1200, height: 630 }, deviceScaleFactor: 1 }); |
| 23 | await page.goto(pathToFileURL(path.join(__dirname, 'social-card.html')).href); |
| 24 | await page.evaluate(() => document.fonts.ready); |
| 25 | const card = path.join(output, 'social-card.png'); |
| 26 | await page.screenshot({ path: card }); |
| 27 | console.log(card); |
| 28 | } finally { |
| 29 | await browser.close(); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | renderSocialCard().catch(error => { |
| 34 | console.error(error.message); |
| 35 | process.exitCode = 1; |
| 36 | }); |