Branchwell

Skillfarm / website · skillfarm.ai / scripts / make-assets.mjs

Raw 3.8 KB on 154cbccf923a68550a73e85d66bba0b0fb8f1943
1// Renders the raster brand assets (favicon.ico, touch icon, social card) from the SVG artwork.
2// Needs a local dev server for the hero scene: npm run dev, then node scripts/make-assets.mjs
3import { readFileSync, writeFileSync } from 'node:fs';
4import { createRequire } from 'node:module';
5
6// Playwright is expected to be installed globally (or run `npm i -D playwright` first).
7const { chromium } = createRequire(import.meta.url)('playwright');
8
9const BASE = process.env.BASE_URL ?? 'http://127.0.0.1:8787';
10const root = new URL('..', import.meta.url).pathname;
11const favicon = readFileSync(`${root}public/favicon.svg`, 'utf8');
12const font = (f) => `data:font/woff2;base64,${readFileSync(`${root}public/fonts/${f}`).toString('base64')}`;
13const home = await (await fetch(BASE + '/')).text();
14const scene = home.match(/<svg class="hero-art"[\s\S]*?<\/svg>/)[0].replace('rx="28"', 'rx="0"');
15
16const browser = await chromium.launch();
17const shot = async (html, width, height, file, omitBackground = false) => {
18 const page = await browser.newPage({ viewport: { width, height }, deviceScaleFactor: 1 });
19 await page.setContent(html);
20 await page.evaluate(() => document.fonts.ready);
21 const buf = await page.screenshot({ omitBackground });
22 if (file) writeFileSync(`${root}public/${file}`, buf);
23 await page.close();
24 return buf;
25};
26
27// The touch icon is full bleed (the OS rounds it), so it drops the corner radius and the edge line.
28const squareIcon = favicon.replace('rx="116"', 'rx="0"').replace(/<rect id="edge"[^>]*\/>/, '');
29const iconPage = (size, square) =>
30 `<body style="margin:0;background:${square ? '#5A8A4A' : 'transparent'}"><div style="width:${size}px;height:${size}px">${square ? squareIcon : favicon}</div></body>`;
31await shot(iconPage(180, true), 180, 180, 'img/apple-touch-icon.png');
32await shot(iconPage(512, false), 512, 512, 'img/icon-512.png', true);
33
34// favicon.ico holding one 32px PNG.
35const png32 = await shot(iconPage(32, false), 32, 32, null, true);
36const head = Buffer.alloc(22);
37head.writeUInt16LE(0, 0); head.writeUInt16LE(1, 2); head.writeUInt16LE(1, 4);
38head.writeUInt8(32, 6); head.writeUInt8(32, 7); head.writeUInt8(0, 8); head.writeUInt8(0, 9);
39head.writeUInt16LE(1, 10); head.writeUInt16LE(32, 12); head.writeUInt32LE(png32.length, 14); head.writeUInt32LE(22, 18);
40writeFileSync(`${root}public/favicon.ico`, Buffer.concat([head, png32]));
41
42await shot(
43 `<style>
44 @font-face{font-family:Fraunces;src:url(${font('fraunces-latin-soft-normal.woff2')});font-weight:100 900}
45 @font-face{font-family:Fraunces;font-style:italic;src:url(${font('fraunces-latin-soft-italic.woff2')});font-weight:100 900}
46 @font-face{font-family:Figtree;src:url(${font('figtree-latin-wght-normal.woff2')});font-weight:300 900}
47 body{margin:0;width:1200px;height:630px;background:#F6EFD9;display:grid;grid-template-columns:1fr 560px;font-family:Figtree;color:#3A1F0F;overflow:hidden}
48 .copy{padding:64px 0 64px 72px;display:flex;flex-direction:column;justify-content:center}
49 .brand{display:flex;align-items:center;gap:16px;font:700 44px Fraunces;font-variation-settings:'SOFT' 100;letter-spacing:-.02em;margin-bottom:44px}
50 h1{font:650 86px/0.98 Fraunces;font-variation-settings:'SOFT' 100;letter-spacing:-.02em;margin:0 0 28px}
51 h1 em{color:#5A8A4A;font-weight:500}
52 p{font-size:29px;line-height:1.35;color:#6B5140;margin:0;max-width:520px}
53 .art{display:flex;align-items:center;padding-right:56px}
54 .art svg{width:100%;height:auto;border-radius:32px}
55 </style>
56 <div class="copy">
57 <div class="brand"><div style="width:64px;height:64px;display:flex">${favicon}</div>Skillfarm</div>
58 <h1>Where agent skills <em>grow</em>.</h1>
59 <p>A free community for sharing SKILL.md skills. Earn Seeds, climb the tiers.</p>
60 </div>
61 <div class="art">${scene}</div>`,
62 1200, 630, 'img/og.png',
63);
64await browser.close();
65console.log('assets written');