Skip to content

Commit

Permalink
Merge pull request #101 from posthtml/fix-srcset
Browse files Browse the repository at this point in the history
  • Loading branch information
cossssmin authored Jul 20, 2024
2 parents dc92475 + c49e05d commit 034f2bc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
8 changes: 7 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@ const plugin = (options = {}) => tree => {

parsed.map(p => {
if (!isUrl(p.url)) {
p.url = typeof value === 'boolean' ? options.url + p.url : value + p.url
p.url = typeof value === 'boolean'
? isUrl(options.url)
? options.url + p.url
: path.join(options.url, p.url)
: isUrl(value)
? value + p.url
: path.join(value, p.url)
}

return p
Expand Down
10 changes: 4 additions & 6 deletions test/expected/srcset.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<img src="https://example.com/image1.jpg" srcset="https://example.com/image1-HD.jpg 2x, https://example.com/image1-phone.jpg 100w">

<img src="images/image1.jpg" srcset="images/image1-HD.jpg 2x, images/image1-phone.jpg 100w">
<img src="https://example.com/image2.jpg" srcset="https://example.com/image2-HD.jpg 2x, https://example.com/image2-phone.jpg 100w">

<picture>
<source media="(max-width: 799px)" srcset="https://example.com/elva-480w-close-portrait.jpg">
<source media="(min-width: 800px)" srcset="https://example.com/elva-800w.jpg">
<img src="https://example.com/elva-800w.jpg" alt="...">
<source media="(max-width: 799px)" srcset="images/elva-480w-close-portrait.jpg">
<source media="(min-width: 800px)" srcset="images/elva-800w.jpg">
<img src="images/elva-800w.jpg" alt="...">
</picture>
2 changes: 0 additions & 2 deletions test/fixtures/srcset.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<img src="image1.jpg" srcset="image1-HD.jpg 2x,image1-phone.jpg 100w">

<img src="https://example.com/image2.jpg" srcset="https://example.com/image2-HD.jpg 2x, https://example.com/image2-phone.jpg 100w">

<picture>
<source media="(max-width: 799px)" srcset="elva-480w-close-portrait.jpg">
<source media="(min-width: 800px)" srcset="elva-800w.jpg">
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test('src attribute', t => {

test('srcset attribute', t => {
return process(t, 'srcset', {
url: 'https://example.com/',
url: 'images',
allTags: true,
})
})
Expand Down

0 comments on commit 034f2bc

Please sign in to comment.