Skip to content

feat(blog): rasterise a post's diagrams automatically when the copy buttons render - #167

Merged
axsaucedo merged 1 commit into
masterfrom
feat/copy-auto-rasterise
Sep 27, 2026
Merged

axsaucedo merged 1 commit into
masterfrom
feat/copy-auto-rasterise

Conversation

@axsaucedo

Copy link
Copy Markdown
Collaborator

The dev-only copy buttons now render any missing or outdated diagram PNGs themselves, so the LinkedIn copy of a blog post can't quietly fall back to SVGs.

This bit on Agentic Security Part 1 today. The copy payload inlines PNGs from tmp/diagrams/<post-dir>/, but they only existed if someone had run rasterise-diagrams.mjs in that checkout. Renaming the folder on publish orphaned them too. So all 13 diagrams went into the clipboard as SVGs, and LinkedIn dropped them.

CopyIssue now checks the post's SVGs against their PNGs by mtime. When any are missing or stale, it runs the rasteriser for only those, as a child process: I tried importing it directly first, and Vite's module runner fails on Playwright's CommonJS entry (module is not defined). The cheap check is in a new diagram-cache.mjs, so the component never loads Playwright.

Verified on a dev server in a fresh worktree with no tmp/diagrams. The first request for Part 1 took 3.1s and embedded all 13 PNGs, counted as 26 because the LinkedIn and newsletter payloads each carry them. The second request took 0.8s. After touching one SVG, only that diagram was re-rendered.

The weakness: the first render of a post with many diagrams blocks for a few seconds while Chromium starts. It's dev-only and happens once per change, so I didn't make it async.

This also removes the TODO entry about renamed folders orphaning their diagrams, since that gap is now closed. The neighbouring TODO point is still open, and today's paste is the first real test of it: whether LinkedIn accepts a pasted data-URI image at all has never been verified.

…uttons render

The copy-for-LinkedIn payload only swaps SVG diagrams for inlined PNGs that
rasterise-diagrams.mjs has already written to tmp/diagrams/<post-dir>/. In a
fresh checkout or worktree, or after a post folder is renamed on publish,
there are none, and the copy silently falls back to SVGs that LinkedIn drops.
That is what happened copying Agentic Security Part 1.

CopyIssue now checks whether any of the post's PNGs are missing or older than
their SVG and, if so, runs the rasteriser for just those. It runs as a child
process because Playwright cannot be loaded through Vite's module runner; the
cheap staleness check lives in diagram-cache.mjs so the component never pulls
Playwright in. First render of a post costs ~3s, later ones nothing extra.
Dev-only, as before. Drops the TODO entry this resolves.
@github-actions

Copy link
Copy Markdown

Visual parity — light theme ☀️

Every captured route is pixel-identical to the merge base across 1440x1000 (40 routes) and 420x900 (40 routes).

Informational: label the PR visual-change to state that pixels are meant to move, or dependencies to require zero.

@github-actions

Copy link
Copy Markdown

Visual parity — dark theme 🌙

Every captured route is pixel-identical to the merge base across 1440x1000 (40 routes) and 420x900 (40 routes).

Informational: label the PR visual-change to state that pixels are meant to move, or dependencies to require zero.

@axsaucedo
axsaucedo merged commit 6f248ac into master Sep 27, 2026
7 checks passed
@axsaucedo
axsaucedo deleted the feat/copy-auto-rasterise branch September 27, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant