ngx-xtroedge-cms 1.3.12 → 1.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1360,15 +1360,23 @@ var XtroedgeCMS = class _XtroedgeCMS {
1360
1360
  return null;
1361
1361
  }
1362
1362
  }
1363
+ hasSection(type) {
1364
+ if (type === "header") return !!(document.querySelector("header") || document.querySelector('[class*="-header"]') || document.querySelector('[tagName$="-header"]'));
1365
+ return !!(document.querySelector("footer") || document.querySelector('[class*="-footer"]') || document.querySelector('[tagName$="-footer"]'));
1366
+ }
1363
1367
  async loadPageContent(status) {
1364
1368
  this.setLoading(true);
1365
1369
  this.cleanOldHistory();
1366
1370
  try {
1367
- const [pageSec, headerSec, footerSec] = await Promise.all([
1368
- this.fetchSection(this.currentSlug, status),
1369
- this.fetchSection("/header", status),
1370
- this.fetchSection("/footer", status)
1371
- ]);
1371
+ const requests = [this.fetchSection(this.currentSlug, status)];
1372
+ const hasHeader = this.hasSection("header");
1373
+ const hasFooter = this.hasSection("footer");
1374
+ if (hasHeader) requests.push(this.fetchSection("/header", status));
1375
+ if (hasFooter) requests.push(this.fetchSection("/footer", status));
1376
+ const results = await Promise.all(requests);
1377
+ const pageSec = results[0];
1378
+ const headerSec = hasHeader ? results[1] : null;
1379
+ const footerSec = hasFooter ? results[hasHeader ? 2 : 1] : null;
1372
1380
  const getTexts = (sec) => sec?.content?.texts || sec?.published_content?.texts || null;
1373
1381
  const pageTexts = getTexts(pageSec);
1374
1382
  const headerTexts = getTexts(headerSec);
@@ -1399,11 +1407,15 @@ var XtroedgeCMS = class _XtroedgeCMS {
1399
1407
  async loadPublishedContent() {
1400
1408
  this.setLoading(true);
1401
1409
  try {
1402
- const [pageSec, headerSec, footerSec] = await Promise.all([
1403
- this.fetchSection(this.currentSlug, "published"),
1404
- this.fetchSection("/header", "published"),
1405
- this.fetchSection("/footer", "published")
1406
- ]);
1410
+ const requests = [this.fetchSection(this.currentSlug, "published")];
1411
+ const hasHeader = this.hasSection("header");
1412
+ const hasFooter = this.hasSection("footer");
1413
+ if (hasHeader) requests.push(this.fetchSection("/header", "published"));
1414
+ if (hasFooter) requests.push(this.fetchSection("/footer", "published"));
1415
+ const results = await Promise.all(requests);
1416
+ const pageSec = results[0];
1417
+ const headerSec = hasHeader ? results[1] : null;
1418
+ const footerSec = hasFooter ? results[hasHeader ? 2 : 1] : null;
1407
1419
  const getTexts = (sec) => sec?.published_content?.texts || null;
1408
1420
  const merged = { ...getTexts(pageSec) || {}, ...getTexts(headerSec) || {}, ...getTexts(footerSec) || {} };
1409
1421
  if (Object.keys(merged).length > 0) {