Skip to content

Give article body images a srcset from the CMS's renditions - #133

Merged
ssavutu merged 1 commit into
mainfrom
feat/body-image-srcset
Oct 1, 2026
Merged

ssavutu merged 1 commit into
mainfrom
feat/body-image-srcset

Conversation

@ssavutu

@ssavutu ssavutu commented Oct 1, 2026

Copy link
Copy Markdown
Member

Why

#130 covers cards and the featured-image figure, but on article pages the lead photo is almost always inline in the body. That's true of all 8 of the latest articles, so article pages still load the full-size original. stripDimensions deliberately removes every body srcset, because WordPress's ones listed its own derivatives.

Change

  • Article.content_image_variants?: Record<string, ImageVariant[]>, new in Return renditions for the images inside an article body triangle-cms#240. It's keyed by each inline image's wp-content path, as the body references it.
  • addBodySrcsets runs after stripDimensions. For each body <img> the CMS has renditions for, it adds a srcset (via imageSrcset from Serve resized featured images through srcset #130) and sizes matching the article column. It skips anything that already has a srcset and leaves other images untouched.
  • The key match works whether src is absolute or already /proxy/-rewritten, and decodes &amp; and percent-escapes the way the CMS does.

Verified

I ran astro dev against a local stand-in for the #240 response: the public API, with content_image_variants added from renditions that actually exist on Delta.

  • The 8 latest articles have 8 body images, and all 8 get a srcset.
  • Body image bytes, picking the way browsers do (smallest candidate ≥ slot × DPR): 9.8 MB → 0.9 MB at 1440px @1x, 2.2 MB on a 390px @3x phone.
  • eslint is clean. astro check shows 0 errors and the same 8 hints as main.

Not exercised end to end: an inline WordPress resized copy (-1024x683.jpg). None of the articles I checked had one. The resolution happens in the CMS (aspect-checked, unit-tested in #240), and this page only uses the referenced path as the key.

Merge order

Replaces #131, which GitHub closed when its base branch (#130) was deleted on merge. Same commits, now against main. It is harmless before the matching triangle-cms change deploys.

🤖 Generated with Claude Code

https://claude.ai/code/session_019EcFyy8aqNnUd75CDPY6Bx

An article's lead photo is almost always inline in the body, not the
featured image, so article pages still loaded the full-size original. All 8
of the latest articles do this, for 9.8MB of body images between them.

triangle-cms now returns content_image_variants, keyed by each inline
image's wp-content path. After stripDimensions removes the srcsets WordPress
wrote, the page adds one back to each body <img> the CMS has renditions for,
sized to the article column. Images without renditions are unchanged.

Measured on the 8 latest articles through a local stand-in for the CMS
response: body image bytes go from 9.8MB to 0.9MB on a 1440px desktop and
2.2MB on a 3x phone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019EcFyy8aqNnUd75CDPY6Bx
@ssavutu
ssavutu merged commit f0cac01 into main Oct 1, 2026
1 check passed
@ssavutu
ssavutu deleted the feat/body-image-srcset branch October 1, 2026 03:30
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