Skip to content

Commit cf0ff28

Browse files
Use unchanged <img> srcset as <source> srcset
To prevent unexpected behaviors transfer `srcset` from <img> to <source> exactly as-is
1 parent 635463d commit cf0ff28

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

lib/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,9 @@ function getAmpPicture (imgNode, options) {
7676

7777
function getPicture (imgNode, options) {
7878
imgNode.skip = true
79-
80-
var src = imgNode.attrs.src
81-
var srcset = (imgNode.attrs.srcset || '')
79+
// set <source> `srcset` to <img> `srcset`, if present; otherwise — use <img> `src`
80+
var srcset = (imgNode.attrs.srcset || imgNode.attrs.src)
8281
.split(',')
83-
.concat(src)
8482
.filter(Boolean)
8583
.map(value => {
8684
value = value.trim().split(/\s/)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!doctype html>
22
<html>
33
<body>
4-
<picture><source type="image/webp" srcset="photo-lg.webp 1000w, photo-md.webp 500w, photo-sm.webp 250w, photo.webp"><img srcset="photo-lg.jpg 1000w, photo-md.jpg 500w, photo-sm.jpg 250w" src="photo.png"></picture>
4+
<picture><source type="image/webp" srcset="photo-lg.webp 1000w, photo-md.webp 500w, photo-sm.webp 250w, photo.webp"><img srcset="photo-lg.jpg 1000w, photo-md.jpg 500w, photo-sm.jpg 250w, photo.jpg" src="photo.png"></picture>
55
</body>
66
</html>

test/fixtures/multisrcset.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!doctype html>
22
<html>
33
<body>
4-
<img srcset="photo-lg.jpg 1000w, photo-md.jpg 500w, photo-sm.jpg 250w" src="photo.png">
4+
<img srcset="photo-lg.jpg 1000w, photo-md.jpg 500w, photo-sm.jpg 250w, photo.jpg" src="photo.png">
55
</body>
66
</html>

0 commit comments

Comments
 (0)