fix: another rewrite refactor

This commit is contained in:
Derrick Hammer 2023-10-17 11:00:27 -04:00
parent ad71feea88
commit 2ae958fac7
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 2 additions and 11 deletions

View File

@ -13,13 +13,6 @@ export default class URLRewriteFilter implements ContentFilter {
const $ = cheerio.load(html);
// Insert or adjust the <base> tag
if ($("base").length) {
$("base").attr("href", "/browse/");
} else {
$("head").prepend('<base href="/browse/">');
}
["a", "link", "script", "img"].forEach((tag) => {
$.root()
.find(tag)
@ -27,10 +20,8 @@ export default class URLRewriteFilter implements ContentFilter {
let attrName = ["a", "link"].includes(tag) ? "href" : "src";
let urlValue = $(element).attr(attrName);
if (urlValue) {
if (!isICANN(urlValue)) {
if (urlValue.startsWith("http")) {
$(element).attr(attrName, `/browse${urlValue}`);
}
if (urlValue.startsWith("http") && !isICANN(urlValue)) {
$(element).attr(attrName, `/browse${urlValue}`);
}
}
});