Skip to content

Commit d622d9f

Browse files
committed
Some fixes to the menu
1 parent 8e76eea commit d622d9f

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

blocks/cards/cards.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createOptimizedPicture, getMetadata } from '../../scripts/lib-franklin.
22

33
// domain to be used when not being the CDN stitching
44
const edsDomain = 'main--24petwatch--hlxsites.hlx.live';
5-
const isCanada = window.location.pathname.startsWith('/ca/');
5+
const isCanada = window.location.pathname.startsWith('/ca/') || window.location.pathname === '/ca';
66

77
async function getTagFilters() {
88
let index = new URL(`${isCanada ? '/ca' : ''}/blog/tag-filters.json`, window.location.origin);

blocks/header/header.js

+20
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,24 @@ function instrumentTrackingEvents(header) {
196196
});
197197
}
198198

199+
/**
200+
* instruments the tracking in the header
201+
* @param {Element} header The header block element
202+
*/
203+
function updateCountryLink(nav) {
204+
const isCanada = window.location.pathname.startsWith('/ca/') || window.location.pathname === '/ca';
205+
const baseDomain = !window.location.port
206+
? `${window.location.protocol}//${window.location.hostname}`
207+
: `${window.location.protocol}//${window.location.hostname}:${window.location.port}`;
208+
nav.querySelectorAll('a').forEach((anchor) => {
209+
if (isCanada && (anchor.href.startsWith(baseDomain) || anchor.href.startsWith('/'))) {
210+
const url = new URL(anchor.href);
211+
url.pathname = `/ca${url.pathname}`;
212+
anchor.href = url.toString();
213+
}
214+
});
215+
}
216+
199217
/**
200218
* decorates the header, mainly the nav
201219
* @param {Element} block The header block element
@@ -280,6 +298,8 @@ export default async function decorate(block) {
280298
decorateButtons(nav);
281299
decorateLinks(nav);
282300
instrumentTrackingEvents(nav);
301+
updateCountryLink(nav);
302+
283303
const navWrapper = document.createElement('div');
284304
navWrapper.className = 'nav-wrapper';
285305
navWrapper.append(nav);

tools/importer/transformers/header.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,23 @@ const createHeader = async (main, document) => {
1515

1616
main.append(document.createElement('hr'));
1717

18-
main.append(document.querySelector('ul.cmp-navigation__group'));
18+
const blog = document.createElement('li');
19+
20+
// Force append blog to the end of the navigation group
21+
blog.innerHTML = '<a href="/blog" class="cmp-navigation__item-link">Blog</a>';
22+
const navigationGroup = document.querySelector('ul.cmp-navigation__group');
23+
navigationGroup.children[navigationGroup.children.length - 1].before(blog);
24+
25+
main.append(navigationGroup);
1926

2027
main.append(document.createElement('hr'));
2128

2229
const ul = document.createElement('ul');
2330
document.querySelectorAll('div.page-header__notificationBar > div > div').forEach((element) => {
2431
if (!element.classList.contains('languagenavigation')) {
2532
const li = document.createElement('li');
26-
li.append(element);
33+
const link = element.querySelector('a');
34+
li.append(link);
2735
ul.append(li);
2836
}
2937
});

tools/importer/transformers/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import createMetadata from './metadata.js';
99
import cleanUpHTML from './cleanUpHTML.js';
1010

1111
export const transformers = [
12-
cleanUpHTML,
1312
createFullLayoutSection,
1413
createHero,
1514
createHomepage,
@@ -31,4 +30,5 @@ export const preTransformers = [
3130

3231
export const postTransformers = [
3332
createMetadata,
33+
cleanUpHTML,
3434
];

0 commit comments

Comments
 (0)