generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move federal base code to utils * Migrate federated.js * Fix linting errors
- Loading branch information
Showing
17 changed files
with
99 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
libs/blocks/global-navigation/features/breadcrumbs/breadcrumbs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,3 @@ | ||
import { getConfig, SLD } from './utils.js'; | ||
|
||
let federatedContentRoot; | ||
/* eslint-disable import/prefer-default-export */ | ||
export const getFederatedContentRoot = () => { | ||
const cdnWhitelistedOrigins = [ | ||
'https://www.adobe.com', | ||
'https://business.adobe.com', | ||
'https://blog.adobe.com', | ||
'https://milo.adobe.com', | ||
'https://news.adobe.com', | ||
]; | ||
const { allowedOrigins = [], origin: configOrigin } = getConfig(); | ||
if (federatedContentRoot) return federatedContentRoot; | ||
// Non milo consumers will have its origin from config | ||
const origin = configOrigin || window.location.origin; | ||
|
||
federatedContentRoot = [...allowedOrigins, ...cdnWhitelistedOrigins].some((o) => origin.replace('.stage', '') === o) | ||
? origin | ||
: 'https://www.adobe.com'; | ||
|
||
if (origin.includes('localhost') || origin.includes(`.${SLD}.`)) { | ||
federatedContentRoot = `https://main--federal--adobecom.aem.${origin.endsWith('.live') ? 'live' : 'page'}`; | ||
} | ||
|
||
return federatedContentRoot; | ||
}; | ||
|
||
// TODO we should match the akamai patterns /locale/federal/ at the start of the url | ||
// and make the check more strict. | ||
export const getFederatedUrl = (url = '') => { | ||
if (typeof url !== 'string' || !url.includes('/federal/')) return url; | ||
if (url.startsWith('/')) return `${getFederatedContentRoot()}${url}`; | ||
try { | ||
const { pathname, search, hash } = new URL(url); | ||
return `${getFederatedContentRoot()}${pathname}${search}${hash}`; | ||
} catch (e) { | ||
window.lana?.log(`getFederatedUrl errored parsing the URL: ${url}: ${e.toString()}`); | ||
} | ||
return url; | ||
}; | ||
|
||
let fedsPlaceholderConfig; | ||
export const getFedsPlaceholderConfig = ({ useCache = true } = {}) => { | ||
if (useCache && fedsPlaceholderConfig) return fedsPlaceholderConfig; | ||
|
||
const { locale, placeholders } = getConfig(); | ||
const libOrigin = getFederatedContentRoot(); | ||
|
||
fedsPlaceholderConfig = { | ||
locale: { | ||
...locale, | ||
contentRoot: `${libOrigin}${locale.prefix}/federal/globalnav`, | ||
}, | ||
placeholders, | ||
}; | ||
|
||
return fedsPlaceholderConfig; | ||
}; | ||
import { getFederatedContentRoot, getFederatedUrl, getFedsPlaceholderConfig } from './utils.js'; | ||
// DO NOT USE THIS FILE, THIS IS HERE FOR HISTORY PURPOSES AND AVOIDING BREAKING CHANGES. | ||
export { getFederatedContentRoot, getFederatedUrl, getFedsPlaceholderConfig }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters