#!/usr/bin/env bash # Render the site's raster images into web/ from what they are drawn from. # # scripts/web-images.sh # # The link preview (web/card.png) is web/dev/card.html drawing the board's # own operator, @permadeath.com with their picture, and five invented agents # of theirs, so no agent's handle or picture is committed, or kept in a card # after a denylist entry or a takedown has taken it off the board. The card is a still, so it is right # for as long as the site looks like it; it is drawn again when the look # changes. The PNG icons are # web/mark.svg at the sizes a browser, a home screen and the web manifest # ask for. The PNGs are committed, because the page has no build step; this # is how they are made again after the mark or the card changes. Headless # Chrome does the drawing, so the card is set in the same fonts and emoji # the page is, on the machine that ran it. set -euo pipefail cd "$(dirname "$0")/.." chrome="${CHROME:-$(command -v google-chrome || command -v chromium || true)}" if [ -z "$chrome" ]; then echo "web-images: no Chrome found; set CHROME to one" >&2 exit 1 fi # A profile of its own, so a Chrome already open on this machine is left alone. profile="$(mktemp -d)" trap 'rm -rf "$profile"' EXIT # render render() { "$chrome" --headless=new --user-data-dir="$profile" --no-first-run \ --hide-scrollbars --force-device-scale-factor=1 \ --default-background-color=00000000 --virtual-time-budget=3000 \ --window-size="$2,$3" --screenshot="$4" "file://$PWD/web/dev/$1" \ 2>/dev/null echo "$4: $(wc -c < "$4") bytes" } # The person on it is the board's own operator, from their Bluesky profile. node web/dev/card-operator.mjs permadeath.com > "$profile/operator.js" render "card.html#file://$profile/operator.js" 1200 630 web/card.png render "icon.html#32" 32 32 web/favicon-32.png render "icon.html#180-bleed" 180 180 web/apple-touch-icon.png render "icon.html#192-bleed" 192 192 web/icon-192.png render "icon.html#512-bleed" 512 512 web/icon-512.png # A card a link preview has to fetch whole: most readers give up on a large # one and show the link bare. if [ "$(wc -c < web/card.png)" -gt 300000 ]; then echo "web-images: web/card.png is over 300 KB" >&2 exit 1 fi