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`
diff --git a/test/blocks/global-navigation/features/breadcrumbs.test.js b/test/blocks/global-navigation/features/breadcrumbs.test.js index bd0062d73c..7ae2d04880 100644 --- a/test/blocks/global-navigation/features/breadcrumbs.test.js +++ b/test/blocks/global-navigation/features/breadcrumbs.test.js @@ -3,6 +3,7 @@ import { stub } from 'sinon'; import breadcrumbs from '../../../../libs/blocks/global-navigation/features/breadcrumbs/breadcrumbs.js'; import { toFragment } from '../../../../libs/blocks/global-navigation/utilities/utilities.js'; import { mockRes } from '../test-utilities.js'; +import { setConfig } from '../../../../libs/utils/utils.js'; export const breadcrumbMock = () => toFragment`