Skip to content

Commit 034f2bc

Browse files
authored
Merge pull request #101 from posthtml/fix-srcset
2 parents dc92475 + c49e05d commit 034f2bc

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

lib/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,13 @@ const plugin = (options = {}) => tree => {
132132

133133
parsed.map(p => {
134134
if (!isUrl(p.url)) {
135-
p.url = typeof value === 'boolean' ? options.url + p.url : value + p.url
135+
p.url = typeof value === 'boolean'
136+
? isUrl(options.url)
137+
? options.url + p.url
138+
: path.join(options.url, p.url)
139+
: isUrl(value)
140+
? value + p.url
141+
: path.join(value, p.url)
136142
}
137143

138144
return p

test/expected/srcset.html

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
<img src="https://example.com/image1.jpg" srcset="https://example.com/image1-HD.jpg 2x, https://example.com/image1-phone.jpg 100w">
2-
1+
<img src="images/image1.jpg" srcset="images/image1-HD.jpg 2x, images/image1-phone.jpg 100w">
32
<img src="https://example.com/image2.jpg" srcset="https://example.com/image2-HD.jpg 2x, https://example.com/image2-phone.jpg 100w">
4-
53
<picture>
6-
<source media="(max-width: 799px)" srcset="https://example.com/elva-480w-close-portrait.jpg">
7-
<source media="(min-width: 800px)" srcset="https://example.com/elva-800w.jpg">
8-
<img src="https://example.com/elva-800w.jpg" alt="...">
4+
<source media="(max-width: 799px)" srcset="images/elva-480w-close-portrait.jpg">
5+
<source media="(min-width: 800px)" srcset="images/elva-800w.jpg">
6+
<img src="images/elva-800w.jpg" alt="...">
97
</picture>

test/fixtures/srcset.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<img src="image1.jpg" srcset="image1-HD.jpg 2x,image1-phone.jpg 100w">
2-
32
<img src="https://example.com/image2.jpg" srcset="https://example.com/image2-HD.jpg 2x, https://example.com/image2-phone.jpg 100w">
4-
53
<picture>
64
<source media="(max-width: 799px)" srcset="elva-480w-close-portrait.jpg">
75
<source media="(min-width: 800px)" srcset="elva-800w.jpg">

test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test('src attribute', t => {
4949

5050
test('srcset attribute', t => {
5151
return process(t, 'srcset', {
52-
url: 'https://example.com/',
52+
url: 'images',
5353
allTags: true,
5454
})
5555
})

0 commit comments

Comments
 (0)