diff --git a/blocks/fragment/fragment.js b/blocks/fragment/fragment.js index 493fea7..a929598 100644 --- a/blocks/fragment/fragment.js +++ b/blocks/fragment/fragment.js @@ -65,14 +65,17 @@ async function loadFragment(path, fromDocs) { setBranch(imageURL, store.branch); image.src = imageURL.toString(); } else { - image.src = `${store.docsOrigin}${imageURL.pathname}`; + // add /docs/ prefix if missing + const pathname = imageURL.pathname.startsWith('/docs/') ? imageURL.pathname : `/docs${imageURL.pathname}`; + image.src = `${store.docsOrigin}${pathname}${imageURL.search}`; } const picture = image.parentElement; if (picture.tagName === 'PICTURE') { + const [baseUrl] = image.src.split('?'); for (const source of picture.querySelectorAll('source')) { const search = source.srcset.split('?')[1]; - source.srcset = `${image.src}?${search}`; + source.srcset = `${baseUrl}?${search}`; } } }