File tree 4 files changed +32
-4
lines changed
tools/importer/transformers
4 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { createOptimizedPicture, getMetadata } from '../../scripts/lib-franklin.
2
2
3
3
// domain to be used when not being the CDN stitching
4
4
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' ;
6
6
7
7
async function getTagFilters ( ) {
8
8
let index = new URL ( `${ isCanada ? '/ca' : '' } /blog/tag-filters.json` , window . location . origin ) ;
Original file line number Diff line number Diff line change @@ -196,6 +196,24 @@ function instrumentTrackingEvents(header) {
196
196
} ) ;
197
197
}
198
198
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
+
199
217
/**
200
218
* decorates the header, mainly the nav
201
219
* @param {Element } block The header block element
@@ -280,6 +298,8 @@ export default async function decorate(block) {
280
298
decorateButtons ( nav ) ;
281
299
decorateLinks ( nav ) ;
282
300
instrumentTrackingEvents ( nav ) ;
301
+ updateCountryLink ( nav ) ;
302
+
283
303
const navWrapper = document . createElement ( 'div' ) ;
284
304
navWrapper . className = 'nav-wrapper' ;
285
305
navWrapper . append ( nav ) ;
Original file line number Diff line number Diff line change @@ -15,15 +15,23 @@ const createHeader = async (main, document) => {
15
15
16
16
main . append ( document . createElement ( 'hr' ) ) ;
17
17
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 ) ;
19
26
20
27
main . append ( document . createElement ( 'hr' ) ) ;
21
28
22
29
const ul = document . createElement ( 'ul' ) ;
23
30
document . querySelectorAll ( 'div.page-header__notificationBar > div > div' ) . forEach ( ( element ) => {
24
31
if ( ! element . classList . contains ( 'languagenavigation' ) ) {
25
32
const li = document . createElement ( 'li' ) ;
26
- li . append ( element ) ;
33
+ const link = element . querySelector ( 'a' ) ;
34
+ li . append ( link ) ;
27
35
ul . append ( li ) ;
28
36
}
29
37
} ) ;
Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ import createMetadata from './metadata.js';
9
9
import cleanUpHTML from './cleanUpHTML.js' ;
10
10
11
11
export const transformers = [
12
- cleanUpHTML ,
13
12
createFullLayoutSection ,
14
13
createHero ,
15
14
createHomepage ,
@@ -31,4 +30,5 @@ export const preTransformers = [
31
30
32
31
export const postTransformers = [
33
32
createMetadata ,
33
+ cleanUpHTML ,
34
34
] ;
You can’t perform that action at this time.
0 commit comments