Skip to content

Return renditions for the images inside an article body - #240

Merged
ssavutu merged 1 commit into
mainfrom
feat/content-image-variants
Oct 1, 2026
Merged

ssavutu merged 1 commit into
mainfrom
feat/content-image-variants

Conversation

@ssavutu

@ssavutu ssavutu commented Oct 1, 2026

Copy link
Copy Markdown
Member

Why

Article pages still load full-size originals. The lead photo is almost always inline in content, not in featured_image; that's true for all 30 of the latest articles. The CMS editor inserts it there, and WordPress did too. So featured_image_variants (#239) never reaches the image readers actually see on an article page.

Change

GET /v1/articles/{slug} gains content_image_variants: a map from each inline image's wp-content path, exactly as content references it (URL-decoded, no host, no query), to that image's renditions.

  • Finds <img src> with a regexp, since bodies are WordPress-era markup mixed with shortcodes, and decodes HTML entities before lookup.
  • About half of inline images in a sample of live articles reference WordPress resized copies (photo-1024x683.jpg). These resolve to the original's renditions only if the aspect ratio matches within 2%. WordPress also made square-cropped thumbnails, and replacing one with the uncropped photo would change the picture, not just its sharpness.
  • Served from the same in-memory index as featured_image_variants, so it adds no queries. Omitted when no inline image has renditions.

Scalene side: it rebuilds a srcset on body images after stripDimensions (follow-up PR, after DrexelTriangle/Scalene#130).

Verified

  • New TestIndexForContent covers originals, query strings, single-quoted src inside [caption], &amp; in paths, a 1024×683 copy resolving to its 3:2 original, a 150×150 crop not resolving, and unrendered or hotlinked images being skipped.
  • go test -race ./... and go vet ./... pass. Swagger is regenerated.

🤖 Generated with Claude Code

https://claude.ai/code/session_019EcFyy8aqNnUd75CDPY6Bx

Article pages still load full-size originals. The lead photo is almost
always inline in the body rather than in featured_image: the CMS editor
inserts it there, and WordPress did too. All 30 of the latest articles do
this. featured_image_variants therefore never reaches it.

The article detail now carries content_image_variants: renditions for each
inline <img>, keyed by the wp-content path exactly as the body references
it. About half of those references are WordPress resized copies
(photo-1024x683.jpg). These resolve to the original's renditions, but only
when the aspect ratio matches within 2%, so a square-cropped thumbnail is
never replaced with the uncropped photo.

The lookup is served from the same in-memory index, so it adds no queries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019EcFyy8aqNnUd75CDPY6Bx
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