Skip to content

Commit

Permalink
remove unecessary decorateLinks
Browse files Browse the repository at this point in the history
  • Loading branch information
anthoula committed Mar 4, 2025
1 parent 40829cd commit e40e753
Showing 1 changed file with 0 additions and 26 deletions.
26 changes: 0 additions & 26 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ export function decorateMain(main) {
buildAutoBlocks(main);
decorateSections(main);
decorateBlocks(main);
// decorateLinks(main); // author can decide when to localize links
}

/**
Expand Down Expand Up @@ -384,31 +383,6 @@ export function getRootPath() {
return window.ROOT_PATH;
}

/**
* Decorates links.
* @param {Element} main The main element
*/
export function decorateLinks(main) {
const root = getRootPath();
if (root === '/') return;
const links = main.querySelectorAll('a');

links.forEach((link) => {
const url = new URL(link.href, window.location.origin);
const { pathname } = url;

// If the link is already localized, do nothing
if (pathname.startsWith('//') || pathname.startsWith(root)) return;

if (
link.href.startsWith('/')
|| link.href.startsWith(window.location.origin)
) {
link.href = `${root}${url.pathname.substring(1)}${url.search}${url.hash}`;
}
});
}

/**
* Decorates links.
* @param {string} [link] url to be localized
Expand Down

0 comments on commit e40e753

Please sign in to comment.