Skip to content
Open
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
29 changes: 15 additions & 14 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,26 +614,29 @@ function processQueryIndexMap(link, domain) {
return result;
}

async function loadQueryIndexes(prefix, onlyCurrentSite = false) {
async function loadQueryIndexes(prefix, onlyCurrentSite = false, links = []) {
const config = getConfig();
const queryIndexSuffix = window.location.host.includes(`${SLD}.page`) ? '-preview' : '';

if (links.length && links.some((link) => link.includes('/federal/')) && !queryIndexes.federal) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: No need to check for length, some will return false if array is empty

Suggested change
if (links.length && links.some((link) => link.includes('/federal/')) && !queryIndexes.federal) {
if (links.some((link) => link.includes('/federal/')) && !queryIndexes.federal) {

queryIndexes.federal = processQueryIndexMap(
`${getFederatedContentRoot()}${prefix}/federal/assets/lingo/query-index${queryIndexSuffix}.json`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vhargrave Currently there are no lingo query indexes created for the /federal/ content. If needed, this might get setup for ACOM for the mid-year WWW Lingo release. Have you added this mostly to cater the eventual WWW use-case? Or do you see the need to set this up for the BACOM release?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sunilkamat it's for when we need it later this year exactly. It's probably not very necessary for BACOM.

getFederatedContentRoot().replace('https://', ''),
);
queryIndexes.federal.domains.push(window.location.hostname);
}
if (lingoSiteMapping || isLoadingQueryIndexes) return;
isLoadingQueryIndexes = true;

const origin = config.origin || window.location.origin;
const contentRoot = config.contentRoot ?? '';
const regionalContentRoot = `${origin}${prefix}${contentRoot}`;
const siteId = config.uniqueSiteId ?? '';
const queryIndexSuffix = window.location.host.includes(`${SLD}.page`) ? '-preview' : '';

queryIndexes[siteId] = processQueryIndexMap(
`${regionalContentRoot}/assets/lingo/query-index${queryIndexSuffix}.json`,
window.location.hostname,
);
queryIndexes.federal = processQueryIndexMap(
`${getFederatedContentRoot()}${prefix}/federal/assets/lingo/query-index${queryIndexSuffix}.json`,
getFederatedContentRoot().replace('https://', ''),
);

if (onlyCurrentSite) {
lingoSiteMapping = Promise.resolve(lingoSiteMappingLoaded = true);
Expand Down Expand Up @@ -730,9 +733,7 @@ function localizeLinkCore(
&& ((locale.base && !path.includes('/fragments/'))
|| (!!locale.regions && path.includes('/fragments/') && aTag.dataset.mepLingo === 'true'))) {
return (async () => {
if (!(lingoSiteMapping || isLoadingQueryIndexes)) {
loadQueryIndexes(prefix);
}
loadQueryIndexes(prefix, false, [href]);
if (!(queryIndexes[siteId]?.requestResolved || lingoSiteMappingLoaded)) {
await Promise.all([queryIndexes[siteId]?.pathsRequest, lingoSiteMapping].filter(Boolean));
}
Expand Down Expand Up @@ -2125,17 +2126,16 @@ async function processSection(section, config, isDoc, lcpSectionId) {
return section.blocks;
}

function loadLingoIndexes() {
function loadLingoIndexes(area = document) {
const config = getConfig();
const { locale } = config || {};

if (locale?.base) {
loadQueryIndexes(config.locale.prefix);
loadQueryIndexes(config.locale.prefix, false, [...area.querySelectorAll('.section a')].map((a) => a.href).filter(Boolean));
return;
}
const prefix = getMepLingoPrefix();
if (prefix) {
loadQueryIndexes(prefix, true);
loadQueryIndexes(prefix, true, [...area.querySelectorAll('.section a')].map((a) => a.href).filter(Boolean));
}
}

Expand All @@ -2159,11 +2159,12 @@ export async function loadArea(area = document) {
await decorateDocumentExtras();
initModalEventListener();
}
if (isLingoActive) loadLingoIndexes();

const htmlSections = [...area.querySelectorAll(isDoc ? 'body > main > div' : ':scope > div')];
htmlSections.forEach((section) => { section.className = 'section'; section.dataset.status = 'pending'; });

if (isLingoActive) loadLingoIndexes(area);

const areaBlocks = [];
let lcpSectionId = null;

Expand Down
Loading