Repository navigation
feat(docsite): theme-aware (light/dark) images in blog post bodies - #4770
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Aug 6, 2026
Contributor
Author
|
Preview of how this looks: Screen.Recording.2026-08-07.at.12.22.04.PM.mov |
github-actions
Bot
requested review from
cvkxx,
ernestt,
kentonquatman and
rubyycheung
August 7, 2026 16:26
nynexman4464
marked this pull request as ready for review
August 7, 2026 16:59
Adds ThemedImage (explicit lightSrc/darkSrc; falls back to whichever is provided) plus a MarkdownImage adapter wired as the blog Markdown image override. Authors drop a sibling '<name>.dark.<ext>' next to an image and it's used in dark mode automatically. Dark variants are resolved at BUILD time, not runtime: generate-data.mjs scans public/blog/** for '<name>.dark.<ext>' files and emits a blogDarkImages[] manifest in the generated registry, which MarkdownImage consults — deterministic, no runtime probe, no flash. Honors the manual theme toggle (via useThemeMode), not just the OS preference. Body images also get a subtle frame so screenshots read intentionally on either background.
…uide Adds a 'Images in the post body' section to the blog README: the Markdown syntax, alt-text expectation, framing, and the <name>.dark.<ext> convention for automatic dark-mode swaps — including how the build-time blogDarkImages manifest makes the decision (no runtime probe). Renumbers later sections.
nynexman4464
force-pushed
the
nynexman4464/blog/dark-image-feature
branch
from
August 7, 2026 19:24
bf18140 to
f1092bb
Compare
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Theme-aware images for blog post bodies (PR 1 of 2 — the infrastructure; the post that uses it is stacked on top).
ThemedImage— takes explicitlightSrc/darkSrc; if only one is given, it's always used.MarkdownImage— adapter wired as the blogMarkdownimage override. Authors drop a sibling<name>.dark.<ext>next to an image and it's shown in dark mode automatically.generate-data.mjsscanspublic/blog/**for<name>.dark.<ext>files and emits ablogDarkImages[]manifest into the generated registry.MarkdownImageconsults that manifest, so the dark-variant decision is deterministic at build time — no runtime existence probe, no flash.useThemeMode), not just OSprefers-color-scheme:<picture>+prefers-color-schemebefore the toggle resolves, a resolved<img>after.No behavior change for existing posts: with no
.dark.sibling, an image renders once (framed), exactly as before.Testing
generate-data.mjsruns;blogDarkImagespopulates frompublic/blog/**.How it works
Authoring stays plain Markdown. An author references only the light image:
To add a dark variant, they drop a sibling file named
foo.dark.pngnext to it — that's the whole contract. No frontmatter, no<picture>, no per-image config.At build time,
generate-data.mjswalkspublic/blog/**and records every*.dark.*file into ablogDarkImagesmanifest in the generated registry. The Markdownimageoverride (MarkdownImage) derives the candidatefoo.dark.pngpath fromfoo.pngand uses it only if it's in that manifest — so the light/dark decision is resolved at build time, not by probing for the file in the browser.ThemedImagethen renders the right one for the resolved color mode (and honors the manual toggle viauseThemeMode, falling back to<picture>+prefers-color-schemefor the pre-hydrationsystemcase). Posts with no.dark.sibling render a single framed image, exactly as before.Why a filename convention (and not explicit props)
ThemedImageitself takes explicitlightSrc/darkSrc, which is the API you'd want if you were writing TSX. But blog post bodies are plain Markdown (.md, not MDX) — they're rendered by the coreMarkdowncomponent from a string, so you can't drop a<ThemedImage lightSrc=... darkSrc=... />into a post. The only extension point isMarkdown'simagecomponent override, and an image node carries just{ src, alt }— a single source. There's no way to thread a second URL through Markdown image syntax.So the convention (
foo.png+foo.dark.png) is what bridges that gap:MarkdownImagetakes the onesrcMarkdown gives it, derives the dark candidate, checks the build-time manifest, and hands both toThemedImage. The explicit-props component stays clean for any future TSX use; the convention adapts it to the constraints of Markdown.Alternatives considered
new Image()to check if a.darkfile exists). Rejected — an extra request per image and a possible flash before it resolves. The build-time manifest is deterministic and free at render.<picture>+prefers-color-scheme. Rejected as the sole mechanism — it ignores the docsite's manual theme toggle, so it'd disagree with the toggle. We use it only for the pre-hydration/systemcase and letuseThemeModewin after.<picture>/dual<img>in the post. Rejected — posts are plain.md(not MDX), and it pushes theme logic onto every author. The<name>.dark.<ext>convention keeps markdown clean.prefers-color-scheme-onlysrcsetwith no JS. Same toggle-blindness problem; kept the component so the manual toggle is honored.