Skip to content

Commit

Permalink
Update components to use meta getFallback option
Browse files Browse the repository at this point in the history
  • Loading branch information
infloent committed Sep 13, 2024
1 parent 28e345c commit 35cd8cc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 23 deletions.
8 changes: 2 additions & 6 deletions blocks/breadcrumbs/breadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ export default class Breadcrumbs extends ComponentBase {
this.classList.add('full-width');
this.classList.add('breadcrumbs');
const { origin, pathname } = window.location;
let breadcrumbRoot = getMeta(metaTags.breadcrumbRoot.metaName);
if (breadcrumbRoot) {
breadcrumbRoot = breadcrumbRoot?.starsWith('/') ? breadcrumbRoot : `/${breadcrumbRoot}`;
} else {
breadcrumbRoot = metaTags.breadcrumbRoot.fallbackContent;
}
let breadcrumbRoot = getMeta(metaTags.breadcrumbRoot.metaName, { getFallback: true });
breadcrumbRoot = breadcrumbRoot?.startsWith('/') ? breadcrumbRoot : `/${breadcrumbRoot}`;

this.pathPages = `${origin}${pathname}`.split(`${origin}${breadcrumbRoot}`).join('/').split('/');
this.innerHTML = `
Expand Down
6 changes: 2 additions & 4 deletions blocks/footer/footer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import ComponentBase from '../../scripts/component-base.js';
import { getMeta, metaTags } from '../../scripts/libs.js';

const { metaName, fallbackContent } = metaTags.footer;
const metaFooter = getMeta(metaName);
const metaFragment = !!metaFooter && `${metaFooter}.plain.html`;
const metaFooter = getMeta(metaTags.footer.metaName, { getFallback: true });
export default class Footer extends ComponentBase {
static loaderConfig = {
...ComponentBase.loaderConfig,
Expand All @@ -12,7 +10,7 @@ export default class Footer extends ComponentBase {
},
};

fragmentPath = metaFragment || `${fallbackContent}.plain.html`;
fragmentPath = `${metaFooter}.plain.html`;

extendConfig() {
return [
Expand Down
6 changes: 2 additions & 4 deletions blocks/header/header.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import ComponentBase from '../../scripts/component-base.js';
import { eagerImage, getMeta, metaTags } from '../../scripts/libs.js';

const { metaName, fallbackContent } = metaTags.header;
const metaHeader = getMeta(metaName);
const metaFragment = !!metaHeader && `${metaHeader}.plain.html`;
const metaHeader = getMeta(metaTags.header.metaName, { getFallback: true });
export default class Header extends ComponentBase {
static loaderConfig = {
...ComponentBase.loaderConfig,
Expand All @@ -20,7 +18,7 @@ export default class Header extends ComponentBase {
},
};

fragmentPath = metaFragment || `${fallbackContent}.plain.html`;
fragmentPath = `${metaHeader}.plain.html`;

dependencies = ['navigation', 'image'];

Expand Down
9 changes: 3 additions & 6 deletions blocks/icon/icon.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import ComponentBase from '../../scripts/component-base.js';
import { flatAsValue, isObject, stringToJsVal , getMeta, metaTags} from '../../scripts/libs.js';

const { metaName, fallbackContent } = metaTags.icons;
const metaIcons = getMeta(metaName);
const metaPath = !!metaIcons && `${metaIcons}`;
import { flatAsValue, isObject, stringToJsVal, getMeta, metaTags } from '../../scripts/libs.js';

const metaIcons = getMeta(metaTags.icons.metaName, { getFallback: true });
export default class Icon extends ComponentBase {
static observedAttributes = ['data-active', 'data-icon'];

Expand Down Expand Up @@ -50,7 +47,7 @@ export default class Icon extends ComponentBase {
}

iconUrl(iconName) {
const path = metaPath || fallbackContent;
const path = `${metaIcons}`;
return `${path}/${iconName}.svg`;
}

Expand Down
6 changes: 3 additions & 3 deletions scripts/libs/external-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export const externalConfig = {

async loadConfig() {
window.raqnComponentsConfig ??= (async () => {
const { metaName, fallbackContent } = metaTags.themecomponent;
const metaConfigPath = getMeta(metaName);
const configPath = (!!metaConfigPath && `${metaConfigPath}.json`) || `${fallbackContent}.json`;
const { metaName } = metaTags.themeConfigComponent;
const metaConfigPath = getMeta(metaName, { getFallback: true });
const configPath = `${metaConfigPath}.json`;
let result = null;
try {
const response = await fetch(`${configPath}`);
Expand Down

0 comments on commit 35cd8cc

Please sign in to comment.