Skip to content

Commit 72d5b27

Browse files
committed
fix: link list detection for url is job listing
Fix the link list so it displays the job listing specific layout when the URLs are linked to the aem domains, so the correct layout can be previewed. It previously was only applying the job listing specific class if the URL started with the main domain or a slash.
1 parent 588acbb commit 72d5b27

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

blocks/link-list/link-list.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ const JOB_LISTING_ROOT = "careers";
99
* @returns {boolean}
1010
*/
1111
const urlIsJobListing = (url) => {
12-
return url.startsWith(`https://adobe.design/${JOB_LISTING_ROOT}/`) || url.startsWith(`/${JOB_LISTING_ROOT}/`);
12+
try {
13+
const urlObject = new URL(url, 'https://adobe.design');
14+
return ['adobe.design','adobe.aem.live', 'adobe.aem.page'].some(suffix => urlObject.hostname.endsWith(suffix)) &&
15+
urlObject.pathname.startsWith(`/${JOB_LISTING_ROOT}/`);
16+
} catch {
17+
return false;
18+
}
1319
};
1420

1521
/**
@@ -19,7 +25,6 @@ const urlIsJobListing = (url) => {
1925
* @param {string} [altText] the link aria-label
2026
* @returns {Element}
2127
*/
22-
2328
const buildLinkListItem = ({ textContent, url, altText }) => {
2429
const item = document.createElement("li");
2530
const itemAnchor = document.createElement("a");
@@ -72,7 +77,6 @@ const buildLinkListFooterLink = ({ textContent, url, altText }) => {
7277

7378
/**
7479
* Loads and decorates the link list block.
75-
* @function
7680
* @param {Element} block the block element
7781
* @returns {Element}
7882
*/
@@ -93,6 +97,7 @@ export default async function decorate(block) {
9397
altText: block.children[0]?.children[2]?.innerText,
9498
};
9599

100+
// If Link List contains all job listing links, it has a different layout.
96101
if (linksData.every((link) => urlIsJobListing(link.url))) {
97102
linkList.classList.add("link-list--jobs");
98103
}

0 commit comments

Comments
 (0)