fix: add srcset support

This commit is contained in:
Derrick Hammer 2023-10-18 08:58:33 -04:00
parent ab103d4f0a
commit 3ea1ce06c9
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 14 additions and 0 deletions

View File

@ -43,6 +43,20 @@ export default class URLRewriteFilter implements ContentFilter {
$(element).attr(attrName, urlValue);
}
}
if (tag === "img" && $(element).attr("srcset")) {
let srcsetValue = $(element).attr("srcset");
let srcsetValues = srcsetValue?.split(",");
let rewrittenSrcsetValues = srcsetValues?.map((srcsetEntry) => {
let [url, descriptor] = srcsetEntry.trim().split(" ");
if (!url.startsWith("http") && !url.startsWith("//")) {
url = path.join(rUrl.pathname, url);
url = `${rUrl.protocol}//${rUrl.hostname}/browse/${rUrl.hostname}${url}`;
}
return `${url} ${descriptor}`;
});
$(element).attr("srcset", rewrittenSrcsetValues?.join(", "));
}
});
});