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);
|
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) => {
|
["a", "link", "script", "img"].forEach((tag) => {
|
||||||
$.root()
|
$.root()
|
||||||
.find(tag)
|
.find(tag)
|
||||||
|
@ -27,12 +20,10 @@ export default class URLRewriteFilter implements ContentFilter {
|
||||||
let attrName = ["a", "link"].includes(tag) ? "href" : "src";
|
let attrName = ["a", "link"].includes(tag) ? "href" : "src";
|
||||||
let urlValue = $(element).attr(attrName);
|
let urlValue = $(element).attr(attrName);
|
||||||
if (urlValue) {
|
if (urlValue) {
|
||||||
if (!isICANN(urlValue)) {
|
if (urlValue.startsWith("http") && !isICANN(urlValue)) {
|
||||||
if (urlValue.startsWith("http")) {
|
|
||||||
$(element).attr(attrName, `/browse${urlValue}`);
|
$(element).attr(attrName, `/browse${urlValue}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue