From c49e05dd298f8f09597bf1d65df336fbfd12d6ba Mon Sep 17 00:00:00 2001 From: Cosmin Popovici Date: Sat, 20 Jul 2024 11:58:28 +0300 Subject: [PATCH] fix: srcset path join --- lib/index.js | 8 +++++++- test/expected/srcset.html | 10 ++++------ test/fixtures/srcset.html | 2 -- test/test.js | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/index.js b/lib/index.js index ffa7c2b..1824318 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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 diff --git a/test/expected/srcset.html b/test/expected/srcset.html index 8421fe6..3321879 100644 --- a/test/expected/srcset.html +++ b/test/expected/srcset.html @@ -1,9 +1,7 @@ - - + - - - - ... + + + ... diff --git a/test/fixtures/srcset.html b/test/fixtures/srcset.html index bae593d..24a4f9f 100644 --- a/test/fixtures/srcset.html +++ b/test/fixtures/srcset.html @@ -1,7 +1,5 @@ - - diff --git a/test/test.js b/test/test.js index f087361..2699877 100644 --- a/test/test.js +++ b/test/test.js @@ -49,7 +49,7 @@ test('src attribute', t => { test('srcset attribute', t => { return process(t, 'srcset', { - url: 'https://example.com/', + url: 'images', allTags: true, }) })