The look follows UI8's SimpleList landing kit: a near-black canvas, one typeface (Outfit, the launcher's own), white pill buttons, large cards. The top shows three stills side by side instead of one phone in a card: the home screen's edge, the list scrubbed to F (in front, with the icon's sweep on its rim) and quick launch, each with a one-sentence caption. Under 700 px the list has a row to itself. Motion: an entrance when the page shows (the headline word by word, the phones rising, the thumb coming down and the wave going out), sections that rise into place when scrolled to, a bar that turns to glass, light that follows the scroll position and the pointer. None of it for reduced motion, and nothing is hidden without JavaScript. The footer credits NOMNOM Inc., with an egg on the name, and no longer carries the version line. The head has a title and description of search length, the link-preview tags with the card's size, and a SoftwareApplication record. The card, assets/og.jpg, is remade from the site by flexera/website/make-og.mjs. og:image is still relative: the site's address was not known, and README.md says where it goes. The page said version 1.0.0; it says 1.0.2. On a phone, the story's text is no longer dimmed and three tap targets are 44 px. flexera/website/make-production.mjs copies what the page loads into WEBSITE/PRODUCTION, the folder to upload; docker-compose.yml and nginx.conf serve that folder. Checked in Chrome over its DevTools port, in real time: 360 to 1440 px wide, touch on the playground, reduced motion, print, no JavaScript, and the production folder over HTTP and in the nginx container. Not checked on a real phone or in another browser. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
99 lines
5.5 KiB
JavaScript
99 lines
5.5 KiB
JavaScript
// Remakes WEBSITE/assets/og.jpg, the 1200 x 630 card that chats and social sites show for a link
|
|
// to the website. The card is drawn from the site itself, so it follows it: the headline is read
|
|
// from WEBSITE/index.html, and the phones are drawn by the site's own script.js and styles.css.
|
|
//
|
|
// node flexera/website/make-og.mjs
|
|
//
|
|
// Needs Chrome and Node 22 or newer, nothing to install. Set CHROME to the browser's path if it
|
|
// is not in the usual place. Run it again whenever the headline or the look of the top changes.
|
|
import { spawn } from 'node:child_process';
|
|
import { readFileSync, writeFileSync, rmSync, mkdtempSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { dirname, join, resolve } from 'node:path';
|
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
import { setTimeout as sleep } from 'node:timers/promises';
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const site = resolve(here, '..', '..', 'WEBSITE');
|
|
const out = join(site, 'assets', 'og.jpg');
|
|
const card = join(site, '.og-card.html'); // lives beside index.html for a moment, so its links to styles, script and fonts are the site's own
|
|
const CHROME = process.env.CHROME || 'C:/Program Files/Google/Chrome/Application/chrome.exe';
|
|
const PORT = 9377;
|
|
|
|
const index = readFileSync(join(site, 'index.html'), 'utf8');
|
|
const sprites = [...index.matchAll(/<svg class="sprite"[\s\S]*?<\/svg>/g)].map((m) => m[0]).join('\n');
|
|
const headline = (index.match(/<h1 id="hero-title">([\s\S]*?)<\/h1>/) || [])[1];
|
|
if (!headline || !sprites) throw new Error('index.html: the headline (h1#hero-title) or the icon sprite was not found');
|
|
|
|
writeFileSync(card, `<!doctype html>
|
|
<html lang="en">
|
|
<meta charset="utf-8">
|
|
<meta name="robots" content="noindex">
|
|
<link rel="stylesheet" href="styles.css">
|
|
<style>
|
|
html, body { width: 1200px; height: 630px; overflow: hidden; }
|
|
body { position: relative; }
|
|
.card__text { position: absolute; left: 80px; top: 0; bottom: 0; width: 500px; display: flex; flex-direction: column; justify-content: center; }
|
|
.card__brand { display: flex; align-items: center; gap: 14px; margin: 0 0 44px; color: var(--white); font: 500 25px/1 var(--ui); letter-spacing: -.01em; }
|
|
.card__brand img { width: 46px; height: 46px; border-radius: 12px; }
|
|
.card__text h1 { font-size: 60px; line-height: 1.05; letter-spacing: -.035em; text-wrap: balance; }
|
|
.card__sub { margin: 30px 0 0; font-size: 25px; line-height: 1.4; color: var(--muted); }
|
|
.card__phones { isolation: isolate; } /* keeps the rim's light, which sits behind its phone, in front of the page */
|
|
.card__phone { position: absolute; bottom: 24px; }
|
|
.card__phone--side { left: 622px; width: 200px; }
|
|
.card__phone--main { left: 848px; width: 280px; }
|
|
</style>
|
|
${sprites}
|
|
<div class="card__text">
|
|
<div class="card__brand"><img src="assets/flexera-icon-256.webp" alt=""><span>Flexera Launcher</span></div>
|
|
<h1>${headline}</h1>
|
|
<p class="card__sub">A free launcher for Android</p>
|
|
</div>
|
|
<div class="card__phones" data-fig>
|
|
<div class="fig__item--side"><div class="phone-host card__phone card__phone--side" data-phone="edge"></div></div>
|
|
<div class="phone-host fig__phone card__phone card__phone--main" data-phone="hero"></div>
|
|
</div>
|
|
<script src="script.js"></script>
|
|
</html>`);
|
|
|
|
const profile = mkdtempSync(join(tmpdir(), 'flexera-og-'));
|
|
const chrome = spawn(CHROME, ['--headless=new', '--disable-gpu', '--hide-scrollbars', `--remote-debugging-port=${PORT}`, `--user-data-dir=${profile}`, '--window-size=1200,630', 'about:blank'], { stdio: 'ignore' });
|
|
try {
|
|
let page;
|
|
for (let i = 0; i < 60 && !page; i++) {
|
|
try {
|
|
page = (await (await fetch(`http://127.0.0.1:${PORT}/json`)).json()).find((t) => t.type === 'page');
|
|
} catch (_) { /* Chrome is not up yet */ }
|
|
if (!page) await sleep(200);
|
|
}
|
|
if (!page) throw new Error(`Chrome did not start (${CHROME}); set CHROME to its path`);
|
|
const ws = new WebSocket(page.webSocketDebuggerUrl);
|
|
await new Promise((res, rej) => { ws.onopen = res; ws.onerror = rej; });
|
|
let id = 0;
|
|
const waiting = new Map();
|
|
ws.onmessage = (m) => {
|
|
const msg = JSON.parse(m.data);
|
|
if (!waiting.has(msg.id)) return;
|
|
const { res, rej } = waiting.get(msg.id);
|
|
waiting.delete(msg.id);
|
|
if (msg.error) rej(new Error(JSON.stringify(msg.error))); else res(msg.result);
|
|
};
|
|
const send = (method, params = {}) => new Promise((res, rej) => { waiting.set(++id, { res, rej }); ws.send(JSON.stringify({ id, method, params })); });
|
|
|
|
await send('Page.enable');
|
|
await send('Emulation.setDeviceMetricsOverride', { width: 1200, height: 630, deviceScaleFactor: 1, mobile: false });
|
|
await send('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-reduced-motion', value: 'reduce' }] }); // the stills, with no entrance
|
|
await send('Page.navigate', { url: pathToFileURL(card).href });
|
|
await sleep(600);
|
|
await send('Runtime.evaluate', { expression: 'document.fonts.ready.then(() => new Promise((r) => setTimeout(r, 700)))', awaitPromise: true });
|
|
const shot = await send('Page.captureScreenshot', { format: 'jpeg', quality: 90 });
|
|
writeFileSync(out, Buffer.from(shot.data, 'base64'));
|
|
console.log(`wrote ${out} (${Math.round(Buffer.from(shot.data, 'base64').length / 1024)} KB), headline: ${headline.replace(/<[^>]+>/g, '')}`);
|
|
try { await send('Browser.close'); } catch (_) { /* gone already */ }
|
|
} finally {
|
|
chrome.kill();
|
|
rmSync(card, { force: true });
|
|
await sleep(300);
|
|
try { rmSync(profile, { recursive: true, force: true }); } catch (_) { /* Chrome may still hold it; it is in the temp folder */ }
|
|
}
|