Fix image dedup collapsing distinct images that share generic alt text (#286)#305
Open
Imccccc wants to merge 1 commit into
Open
Fix image dedup collapsing distinct images that share generic alt text (#286)#305Imccccc wants to merge 1 commit into
Imccccc wants to merge 1 commit into
Conversation
_deduplicateImages keyed its out-of-figure pass on alt text: a run of images sharing the same non-empty alt but differing in src was treated as lazy-load/reader-mode duplicates and collapsed to one. That assumption breaks whenever many *distinct* images share a generic identical alt — image galleries, and WeChat 公众号 (mp.weixin.qq.com) articles in particular, where every inline image gets alt="Image". On a real WeChat article this collapsed 28 inline images down to 1. Dedup the out-of-figure pass on image identity instead: two images are duplicates only when their normalized src (host + path, ignoring the query string) matches but the raw src differs (a size/query variant of the same asset). Distinct images are never merged on alt alone, and the existing "identical src = legitimate repeat" behavior is preserved. Fixes kepano#286. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
_deduplicateImageskeyed its out-of-figure pass on alt text: a run of images sharing the same non-empty alt but differing insrcwas treated as lazy-load / reader-mode duplicates and collapsed to a single image.That assumption holds for a large/small variant pair, but breaks whenever many distinct images share a generic identical alt:
alt="image"(the case in Lazy-loaded article images with generic identical alt text are deduplicated away #286), andmp.weixin.qq.com) articles, where every inline image is emitted withalt="Image".On a real WeChat article this collapsed 28 distinct inline images down to 1 — the long-standing "Web Clipper only saves the first image from 公众号" symptom traces directly here.
Root cause
In the second loop of
_deduplicateImages, the duplicate signal wassame alt && different src. With N distinct images all carrying the same generic alt, each pair matched and all but one were removed.Fix
Dedup the out-of-figure pass on image identity rather than alt:
srcdiffers — i.e. a size/query variant of the same asset.The in-figure pass and the lightbox pass are unchanged.
Testing
tests/image-dedup-generic-alt.test.ts: distinct images sharing an identical generic alt / empty alt / WeChat-stylemmbizmarkup all survive; a legitimately repeated identical-src image still keeps both copies.npm test): 312/312, including the existingelements--image-dedup,elements--lazy-image,elements--lightbox-image-dedup, andelements--svg-placeholder-lazy-imagefixtures — no regressions.Fixes #286.