Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions libs/c2/blocks/global-navigation/global-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
convertStageLinks,
lingoActive,
getLingoRegion,
getFederatedUrl,
} from '../../../utils/utils.js';

const DEFAULT_FEDERAL_URL = 'https://main--federal--adobecom.aem.page';
Expand Down Expand Up @@ -82,6 +83,24 @@ export default async function init(el) {
return handleCommands(cs, root, true, true);
};

// Mirrors fragment.js's mep.fragments lookup + handleFragmentCommand: swaps
// a nested `#_inline` product-card (or other) fragment href for whatever
// MEP's page-wide fragment-replace manifest points it at.
const resolveFragmentHref = async (href) => {
const isFederalHref = href.includes('/federal/');
const path = isFederalHref
? getFederatedUrl(href).replace('#_inline', '')
: new URL(href).pathname;
const mepFrag = config.mep?.fragments?.[path]
?? config.mep?.fragments?.[path.replace(config.locale?.prefix ?? '', '')];
if (!mepFrag) return href;
const { handleFragmentCommand } = await import('../../../features/personalization/personalization.js');
const tempAnchor = document.createElement('a');
tempAnchor.href = href;
const resolved = handleFragmentCommand(mepFrag, tempAnchor);
return resolved ? tempAnchor.href : href;
};

const { main } = await import(federalGnavUrl);
const gnavUrl = new URL(getMetadata('gnav-source') || `${config.locale?.contentRoot ?? window.location.origin}/gnav`);

Expand Down Expand Up @@ -112,6 +131,7 @@ export default async function init(el) {
personalization: {
commands: [...commands, ...gnavMepCommands],
handleCommands: personalizationHandler,
resolveFragmentHref,
},
convertStageLinks: ({ anchors, hostname, href }) => {
convertStageLinks({ anchors, config, hostname, href });
Expand Down
Loading