From 2ae958fac752cbfb67f69b8feb4fa74a07a34f3d Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 17 Oct 2023 11:00:27 -0400 Subject: [PATCH] fix: another rewrite refactor --- src/backend/filters/urlRewrite.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/backend/filters/urlRewrite.ts b/src/backend/filters/urlRewrite.ts index a884aeb..ea88f8d 100644 --- a/src/backend/filters/urlRewrite.ts +++ b/src/backend/filters/urlRewrite.ts @@ -13,13 +13,6 @@ export default class URLRewriteFilter implements ContentFilter { const $ = cheerio.load(html); - // Insert or adjust the tag - if ($("base").length) { - $("base").attr("href", "/browse/"); - } else { - $("head").prepend(''); - } - ["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}`); } } });