Skip to content

Commit

Permalink
feat: refine HTML transformation to handle root-relative links for im…
Browse files Browse the repository at this point in the history
…g and link tags
  • Loading branch information
lisonge committed Nov 7, 2024
1 parent cc14590 commit 33ae124
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions docs/.vitepress/plugins/mirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down

0 comments on commit 33ae124

Please sign in to comment.