fix: another rewrite refactor
This commit is contained in:
parent
ad71feea88
commit
2ae958fac7
|
@ -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,12 +20,10 @@ 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")) {
|
||||
if (urlValue.startsWith("http") && !isICANN(urlValue)) {
|
||||
$(element).attr(attrName, `/browse${urlValue}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue