mirror of
https://github.com/gkd-kit/docs.git
synced 2024-11-16 14:42:19 +08:00
feat: refine HTML transformation to handle root-relative links for img and link tags
This commit is contained in:
parent
cc14590e5c
commit
33ae1240bb
|
@ -87,9 +87,15 @@ export const transformHtml = (code: string) => {
|
|||
e.setAttribute(attr, mirrorBaseUrl + e.getAttribute(attr));
|
||||
});
|
||||
});
|
||||
doc.querySelectorAll('link[href^="/"]').forEach((e) => {
|
||||
|
||||
doc.querySelectorAll('[href^="/"]').forEach((e) => {
|
||||
const tag = e.tagName.toLowerCase();
|
||||
const href = e.getAttribute('href');
|
||||
if (href && href.lastIndexOf('/') === 0) {
|
||||
if (
|
||||
(tag === 'img' || tag === 'link') &&
|
||||
href &&
|
||||
href.lastIndexOf('/') === 0
|
||||
) {
|
||||
e.setAttribute('href', mirrorBaseUrl + href);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user