Skip to content

Commit 97e82ba

Browse files
committed
website: the link previews and the icon in the site's look
The cards and the icon were drawn in the cover's burgundy and serif, which the site no longer uses. They are now set in the site's dark ink with Inter, the author and edition in plain case with the edition in navy, and the icon's "C++" in Inter over the cover's rings, faint, with C++26's dashed in navy. The cover keeps its cloth and foil. render.mjs --cards redraws only the cards and the icon from the web copies of the cover, and CHROME points it at a browser other than the one playwright-core installed.
1 parent 172984f commit 97e82ba

5 files changed

Lines changed: 39 additions & 25 deletions

File tree

‎assets/cover/render.mjs‎

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@
1616
// website/src/modern-cpp/assets/og-{en,zh}.png link previews
1717
// website/src/modern-cpp/assets/{favicon,apple-touch-icon}.png the icon
1818
//
19+
// The link previews and the icon are set apart from the cover, in the
20+
// site's look: the ink of its dark theme, Inter, and navy for one accent.
21+
// The cover keeps its cloth and foil.
22+
//
1923
// Run from the repository root with playwright-core available:
2024
//
2125
// npm i --no-save playwright-core && npx playwright-core install chromium
22-
// node assets/cover/render.mjs
26+
// node assets/cover/render.mjs everything
27+
// node assets/cover/render.mjs --cards only the link previews and the icon,
28+
// from the cover-{en,zh}-web.jpg there
2329
//
24-
// (PLAYWRIGHT_CORE=/path/to/playwright-core/index.mjs points at another copy.)
30+
// (PLAYWRIGHT_CORE=/path/to/playwright-core/index.mjs points at another copy,
31+
// and CHROME=/path/to/chrome at a browser other than the one it installed.)
2532

2633
import { mkdirSync, readFileSync } from 'node:fs';
2734
import { dirname, join } from 'node:path';
@@ -168,6 +175,10 @@ window.coverReady = false;
168175
</script>`;
169176

170177
const FONTS = `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@500&family=Source+Serif+4:opsz,wght@8..60,600&family=Noto+Serif+SC:wght@600&display=block">`;
178+
// The site's dark theme, for the link previews and the icon.
179+
const SITE = { bg: '#161616', lift: '#232323', text: '#ececec', secondary: '#b4b4b4', muted: '#9a9a9a', navy: '#9bb0e4' };
180+
const CARD_FONTS = `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Noto+Sans+SC:wght@400;500;600&display=block">`;
181+
const SANS = `Inter, "Noto Sans SC", "PingFang SC", sans-serif`;
171182
const FIELD = `background:
172183
radial-gradient(560px 460px at ${CX}px ${BASE}px, rgba(255, 214, 196, 0.11), transparent 70%),
173184
linear-gradient(172deg, #8a323d 0%, #74272f 42%, #521a22 100%);`;
@@ -213,42 +224,42 @@ function coverPage(t) {
213224
</div>${SILHOUETTE}</body></html>`;
214225
}
215226

216-
// A link preview: the cover beside the title, 1200 × 630.
227+
// A link preview: the cover beside the title, 1200 × 630, on the site's ink.
217228
function ogPage(t, coverUrl) {
218-
return `<!doctype html><html lang="${t.lang}"><head><meta charset="utf-8">${FONTS}<style>
229+
return `<!doctype html><html lang="${t.lang}"><head><meta charset="utf-8">${CARD_FONTS}<style>
219230
html, body { margin: 0; }
220231
.card { width: 1200px; height: 630px; display: flex; align-items: center; gap: 72px; padding: 0 96px; box-sizing: border-box;
221-
background: radial-gradient(900px 600px at 20% 30%, #7a2a34, #4a161d 75%); color: ${CREAM}; font-family: Inter, "PingFang SC", sans-serif; }
222-
img { width: 330px; height: auto; border-radius: 4px; box-shadow: 0 0 0 1px rgba(255,255,255,0.06), 0 30px 60px -10px rgba(0,0,0,0.55); }
223-
h1 { margin: 0; font: 600 76px/1.02 "Source Serif 4", "Noto Serif SC", serif; letter-spacing: -0.02em; }
224-
.sub { margin: 22px 0 0; font-size: 30px; opacity: 0.86; }
225-
.meta { margin: 46px 0 0; font-size: 17px; font-weight: 600; letter-spacing: 0.2em; text-transform: uppercase; }
226-
.meta span { color: ${GOLD}; }
227-
.url { margin: 10px 0 0; font-size: 22px; opacity: 0.6; }
228-
:lang(zh-CN) h1 { font-size: 80px; line-height: 1.12; letter-spacing: 0.01em; }
229-
:lang(zh-CN) .meta { letter-spacing: 0.12em; }
232+
background: radial-gradient(900px 600px at 20% 30%, ${SITE.lift}, ${SITE.bg} 75%); color: ${SITE.text}; font-family: ${SANS}; }
233+
img { width: 330px; height: auto; border-radius: 4px; box-shadow: 0 0 0 1px rgba(255,255,255,0.06), 0 30px 60px -10px rgba(0,0,0,0.6); }
234+
h1 { margin: 0; font: 600 72px/1.06 ${SANS}; letter-spacing: -0.025em; }
235+
.sub { margin: 22px 0 0; font-size: 30px; color: ${SITE.secondary}; }
236+
.meta { margin: 46px 0 0; font-size: 24px; font-weight: 500; color: ${SITE.secondary}; }
237+
.meta span { color: ${SITE.navy}; }
238+
.url { margin: 12px 0 0; font-size: 22px; color: ${SITE.muted}; }
239+
:lang(zh-CN) h1 { font-size: 76px; line-height: 1.14; letter-spacing: 0.02em; }
230240
</style></head><body><div class="card">
231241
<img src="${coverUrl}" alt="">
232242
<div><h1>${t.title}</h1><p class="sub">${t.sub}</p><p class="meta">${t.author} · <span>${t.edition}</span></p><p class="url">${t.url}</p></div>
233243
</div></body></html>`;
234244
}
235245

236-
// The icon: the cover's field and rings behind a serif "C++".
246+
// The icon: "C++" in Inter on the site's ink, with the cover's rings behind
247+
// it, faint, and the outermost, C++26's, dashed in navy.
237248
function iconPage() {
238249
const rings = [44, 70, 96, 122, 148].map((r, i) =>
239-
`<path d="M${18 + r},180A${r},${r} 0 0 0 ${18 - r},180" stroke="${i === 4 ? GOLD : CREAM}" stroke-opacity="${i === 4 ? 0.9 : 0.3}" stroke-width="3"${i === 4 ? ' stroke-dasharray="3 9" stroke-linecap="round"' : ''}/>`).join('');
240-
return `<!doctype html><html><head><meta charset="utf-8">${FONTS}<style>
250+
`<path d="M${18 + r},180A${r},${r} 0 0 0 ${18 - r},180" stroke="${i === 4 ? SITE.navy : SITE.text}" stroke-opacity="${i === 4 ? 0.9 : 0.16}" stroke-width="3"${i === 4 ? ' stroke-dasharray="3 9" stroke-linecap="round"' : ''}/>`).join('');
251+
return `<!doctype html><html><head><meta charset="utf-8">${CARD_FONTS}<style>
241252
html, body { margin: 0; }
242-
.icon { position: relative; width: 180px; height: 180px; overflow: hidden; ${FIELD.replace(`${CX}px ${BASE}px`, '18px 180px')} }
253+
.icon { position: relative; width: 180px; height: 180px; overflow: hidden; background: ${SITE.bg}; }
243254
svg { position: absolute; inset: 0; }
244-
b { position: absolute; inset: 0; display: grid; place-items: center; padding-bottom: 8px;
245-
font: 600 76px/1 "Source Serif 4", serif; letter-spacing: -0.03em; color: ${CREAM}; }
255+
b { position: absolute; inset: 0; display: grid; place-items: center; padding-bottom: 6px;
256+
font: 600 80px/1 ${SANS}; letter-spacing: -0.04em; color: #f5f5f5; }
246257
</style></head><body><div class="icon">
247258
<svg viewBox="0 0 180 180" width="180" height="180" fill="none">${rings}</svg><b>C++</b>
248259
</div></body></html>`;
249260
}
250261

251-
const browser = await chromium.launch();
262+
const browser = await chromium.launch(process.env.CHROME ? { executablePath: process.env.CHROME } : {});
252263
async function shoot(html, { width, height, scale, out, type = 'png', quality }) {
253264
const page = await browser.newPage({ viewport: { width, height }, deviceScaleFactor: scale });
254265
await page.setContent(html, { waitUntil: 'networkidle' });
@@ -260,12 +271,15 @@ async function shoot(html, { width, height, scale, out, type = 'png', quality })
260271
console.log('wrote', out.replace(ROOT + '/', ''));
261272
}
262273

274+
const cardsOnly = process.argv.includes('--cards');
263275
for (const ed of ['en', 'zh']) {
264-
const html = coverPage(TEXT[ed]);
265-
const full = join(ROOT, 'assets', `cover-${ed}.png`);
266-
await shoot(html, { width: W, height: H, scale: 3, out: full });
267-
await shoot(html, { width: W, height: H, scale: 720 / W, out: join(SITE_ASSETS, `cover-${ed}-web.jpg`), type: 'jpeg', quality: 88 });
268-
await shoot(html, { width: W, height: H, scale: 100 / W, out: join(SITE_ASSETS, `cover-${ed}-logo.png`) });
276+
if (!cardsOnly) {
277+
const html = coverPage(TEXT[ed]);
278+
const full = join(ROOT, 'assets', `cover-${ed}.png`);
279+
await shoot(html, { width: W, height: H, scale: 3, out: full });
280+
await shoot(html, { width: W, height: H, scale: 720 / W, out: join(SITE_ASSETS, `cover-${ed}-web.jpg`), type: 'jpeg', quality: 88 });
281+
await shoot(html, { width: W, height: H, scale: 100 / W, out: join(SITE_ASSETS, `cover-${ed}-logo.png`) });
282+
}
269283
const web = 'data:image/jpeg;base64,' + readFileSync(join(SITE_ASSETS, `cover-${ed}-web.jpg`)).toString('base64');
270284
await shoot(ogPage(TEXT[ed], web), { width: 1200, height: 630, scale: 1, out: join(SITE_ASSETS, `og-${ed}.png`) });
271285
}
-21.3 KB
Loading
-639 Bytes
Loading
-126 KB
Loading
-125 KB
Loading

0 commit comments

Comments
 (0)