diff --git a/libs/blocks/global-navigation/features/breadcrumbs/breadcrumbs.js b/libs/blocks/global-navigation/features/breadcrumbs/breadcrumbs.js index 6a13052840..564e669328 100644 --- a/libs/blocks/global-navigation/features/breadcrumbs/breadcrumbs.js +++ b/libs/blocks/global-navigation/features/breadcrumbs/breadcrumbs.js @@ -1,4 +1,4 @@ -import { getMetadata } from '../../../../utils/utils.js'; +import { getMetadata, localizeLink } from '../../../../utils/utils.js'; import { toFragment, lanaLog } from '../../utilities/utilities.js'; const metadata = { @@ -35,17 +35,10 @@ const setBreadcrumbSEO = (breadcrumbs) => { document.head.append(script); }; -const getHiddenEntries = (str) => str - ?.toLowerCase() - .split(',') - .map((item) => item.trim()) || []; - -const removeHiddenEntries = ({ ul }) => { - const hidden = getHiddenEntries(getMetadata(metadata.hiddenEntries)); - if (!hidden.length) return; - ul.querySelectorAll('li').forEach( - (li) => hidden.includes(li.innerText?.toLowerCase().trim()) && li.remove(), - ); +const localizeEntries = (anchor) => { + if (!anchor) return; + const href = anchor.getAttribute('href'); + anchor.setAttribute('href', localizeLink(href)); }; const createBreadcrumbs = (element) => { @@ -59,7 +52,18 @@ const createBreadcrumbs = (element) => { `); } - removeHiddenEntries({ ul }); + + const hiddenEntries = getMetadata(metadata.hiddenEntries) + ?.toLowerCase() + .split(',') + .map((item) => item.trim()) || []; + + ul.querySelectorAll('li').forEach( + (li) => { + if (hiddenEntries.includes(li.innerText?.toLowerCase().trim())) return li.remove(); + return localizeEntries(li.querySelector('a')); + }, + ); const breadcrumbs = toFragment`