Skip to content

Commit

Permalink
move render blocking code to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
saugatmalla authored and overmyheadandbody committed Dec 3, 2024
1 parent fe33191 commit deb5af5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
12 changes: 0 additions & 12 deletions libs/features/icons/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,6 @@ export async function decorateIcons(area, icons, config) {
});
}

export function setIconsIndexClass(icons) {
[...icons].forEach((icon) => {
const parent = icon.parentNode;
const children = parent.childNodes;
const nodeIndex = [...children].indexOf.call(children, icon);
let indexClass = (nodeIndex === children.length - 1) ? 'last' : 'middle';
if (nodeIndex === 0) indexClass = 'first';
if (children.length === 1) indexClass = 'only';
icon.classList.add(`node-index-${indexClass}`);
});
}

export default async function loadIcons(icons) {
const fedRoot = getFederatedContentRoot();
const iconRequests = [];
Expand Down
21 changes: 16 additions & 5 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export function localizeLink(
const isLocalizedLink = path.startsWith(`/${LANGSTORE}`)
|| path.startsWith(`/${PREVIEW}`)
|| Object.keys(locales).some((loc) => loc !== '' && (path.startsWith(`/${loc}/`)
|| path.endsWith(`/${loc}`)));
|| path.endsWith(`/${loc}`)));
if (isLocalizedLink) return processedHref;
const urlPath = `${locale.prefix}${path}${url.search}${hash}`;
return relative ? urlPath : `${url.origin}${urlPath}`;
Expand Down Expand Up @@ -764,7 +764,7 @@ function decorateHeader() {
}
header.className = headerMeta || 'global-navigation';
const metadataConfig = getMetadata('breadcrumbs')?.toLowerCase()
|| getConfig().breadcrumbs;
|| getConfig().breadcrumbs;
if (metadataConfig === 'off') return;
const baseBreadcrumbs = getMetadata('breadcrumbs-base')?.length;

Expand Down Expand Up @@ -816,8 +816,8 @@ async function decoratePlaceholders(area, config) {
area.dataset.hasPlaceholders = 'true';
const placeholderPath = `${config.locale?.contentRoot}/placeholders.json`;
placeholderRequest = placeholderRequest
|| customFetch({ resource: placeholderPath, withCacheRules: true })
.catch(() => ({}));
|| customFetch({ resource: placeholderPath, withCacheRules: true })
.catch(() => ({}));
const { decoratePlaceholderArea } = await import('../features/placeholders.js');
await decoratePlaceholderArea({ placeholderPath, placeholderRequest, nodes });
}
Expand Down Expand Up @@ -1252,6 +1252,18 @@ async function resolveInlineFrags(section) {
section.preloadLinks = newlyDecoratedSection.preloadLinks;
}

function setIconsIndexClass(icons) {
[...icons].forEach((icon) => {
const parent = icon.parentNode;
const children = parent.childNodes;
const nodeIndex = [...children].indexOf.call(children, icon);
let indexClass = (nodeIndex === children.length - 1) ? 'last' : 'middle';
if (nodeIndex === 0) indexClass = 'first';
if (children.length === 1) indexClass = 'only';
icon.classList.add(`node-index-${indexClass}`);
});
}

async function processSection(section, config, isDoc) {
await resolveInlineFrags(section);
const firstSection = section.el.dataset.idx === '0';
Expand Down Expand Up @@ -1293,7 +1305,6 @@ export async function loadArea(area = document) {

const allIcons = area.querySelectorAll('span.icon');
if (allIcons.length) {
const { setIconsIndexClass } = await import('../features/icons/icons.js');
setIconsIndexClass(allIcons);
}

Expand Down

0 comments on commit deb5af5

Please sign in to comment.