Skip to content

Commit b31efc6

Browse files
committed
feat: multi srcset, close #5
1 parent cc7079e commit b31efc6

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

lib/index.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,18 @@ function getPicture (imgNode, options) {
6464
imgNode.skip = true
6565

6666
var src = imgNode.attrs.src
67-
if (options.replaceExtension) {
68-
src = removeExtension(src)
69-
}
70-
src += '.webp'
67+
var srcset = (imgNode.attrs.srcset || '')
68+
.split(',')
69+
.concat(src)
70+
.filter(Boolean)
71+
.map(value => {
72+
value = value.trim().split(/\s/)
73+
var path = options.replaceExtension ? removeExtension(value[0]) : value[0]
74+
var size = value[1]
75+
76+
return [path + '.webp', size].filter(Boolean).join(' ')
77+
})
78+
.join(', ')
7179

7280
return {
7381
tag: 'picture',
@@ -76,7 +84,7 @@ function getPicture (imgNode, options) {
7684
tag: 'source',
7785
attrs: {
7886
type: 'image/webp',
79-
srcset: src
87+
srcset
8088
}
8189
},
8290
imgNode

0 commit comments

Comments
 (0)