feat: enhance HTML transformation to handle root-relative links

This commit is contained in:
二刺螈 2024-11-07 17:00:45 +08:00
parent 53d3df502f
commit cc14590e5c

View File

@ -87,5 +87,11 @@ export const transformHtml = (code: string) => {
e.setAttribute(attr, mirrorBaseUrl + e.getAttribute(attr)); e.setAttribute(attr, mirrorBaseUrl + e.getAttribute(attr));
}); });
}); });
doc.querySelectorAll('link[href^="/"]').forEach((e) => {
const href = e.getAttribute('href');
if (href && href.lastIndexOf('/') === 0) {
e.setAttribute('href', mirrorBaseUrl + href);
}
});
return doc.documentElement.outerHTML; return doc.documentElement.outerHTML;
}; };