@treely/strapi-slices 7.5.0 → 7.5.2
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/strapi-slices.cjs.development.js +63 -82
- package/dist/strapi-slices.cjs.development.js.map +1 -1
- package/dist/strapi-slices.cjs.production.min.js +1 -1
- package/dist/strapi-slices.cjs.production.min.js.map +1 -1
- package/dist/strapi-slices.esm.js +63 -82
- package/dist/strapi-slices.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/integrations/strapi/getAllSlugsFromStrapi.test.ts +1 -13
- package/src/integrations/strapi/getAllSlugsFromStrapi.ts +24 -19
- package/src/integrations/strapi/getAvailableLocalesFromStrapi.test.ts +1 -1
- package/src/integrations/strapi/getStrapiCollectionType.test.ts +20 -15
- package/src/integrations/strapi/getStrapiCollectionType.ts +38 -28
|
@@ -40,11 +40,6 @@ var useEmblaCarousel__default = /*#__PURE__*/_interopDefault(useEmblaCarousel);
|
|
|
40
40
|
var AutoScroll__default = /*#__PURE__*/_interopDefault(AutoScroll);
|
|
41
41
|
var useSWRInfinite__default = /*#__PURE__*/_interopDefault(useSWRInfinite);
|
|
42
42
|
|
|
43
|
-
function _arrayLikeToArray(r, a) {
|
|
44
|
-
(null == a || a > r.length) && (a = r.length);
|
|
45
|
-
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
46
|
-
return n;
|
|
47
|
-
}
|
|
48
43
|
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
49
44
|
try {
|
|
50
45
|
var i = n[a](c),
|
|
@@ -70,23 +65,6 @@ function _asyncToGenerator(n) {
|
|
|
70
65
|
});
|
|
71
66
|
};
|
|
72
67
|
}
|
|
73
|
-
function _createForOfIteratorHelperLoose(r, e) {
|
|
74
|
-
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
75
|
-
if (t) return (t = t.call(r)).next.bind(t);
|
|
76
|
-
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
|
|
77
|
-
t && (r = t);
|
|
78
|
-
var o = 0;
|
|
79
|
-
return function () {
|
|
80
|
-
return o >= r.length ? {
|
|
81
|
-
done: !0
|
|
82
|
-
} : {
|
|
83
|
-
done: !1,
|
|
84
|
-
value: r[o++]
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
89
|
-
}
|
|
90
68
|
function _extends() {
|
|
91
69
|
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
92
70
|
for (var e = 1; e < arguments.length; e++) {
|
|
@@ -409,13 +387,6 @@ function _regeneratorRuntime() {
|
|
|
409
387
|
function _taggedTemplateLiteralLoose(e, t) {
|
|
410
388
|
return t || (t = e.slice(0)), e.raw = t, e;
|
|
411
389
|
}
|
|
412
|
-
function _unsupportedIterableToArray(r, a) {
|
|
413
|
-
if (r) {
|
|
414
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
415
|
-
var t = {}.toString.call(r).slice(8, -1);
|
|
416
|
-
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
390
|
|
|
420
391
|
var STRAPI_URI = process.env.NEXT_PUBLIC_STRAPI_URI || 'http://127.0.0.1:1337';
|
|
421
392
|
var STRAPI_DEFAULT_PAGE_SIZE = '100';
|
|
@@ -475,27 +446,34 @@ var getAllSlugsFromStrapi = /*#__PURE__*/function () {
|
|
|
475
446
|
case 3:
|
|
476
447
|
allLocales = _context.sent;
|
|
477
448
|
slugPromises = allLocales.map(function (locale) {
|
|
478
|
-
var params = {
|
|
479
|
-
locale: locale,
|
|
480
|
-
'pagination[pageSize]': STRAPI_DEFAULT_PAGE_SIZE,
|
|
481
|
-
filters: filters
|
|
482
|
-
};
|
|
483
449
|
return strapiClient.get(path, {
|
|
484
|
-
params:
|
|
450
|
+
params: {
|
|
451
|
+
locale: locale,
|
|
452
|
+
'pagination[pageSize]': STRAPI_DEFAULT_PAGE_SIZE,
|
|
453
|
+
filters: filters
|
|
454
|
+
}
|
|
455
|
+
}).then(function (response) {
|
|
456
|
+
return response.data.data.map(function (page) {
|
|
457
|
+
return {
|
|
458
|
+
slug: page.attributes.slug,
|
|
459
|
+
locale: page.attributes.locale
|
|
460
|
+
};
|
|
461
|
+
});
|
|
462
|
+
})
|
|
463
|
+
// when a collection type for a requested locale does not exist, Strapi returns a 404. In this case, we return an empty array instead of throwing an error
|
|
464
|
+
["catch"](function (error) {
|
|
465
|
+
var _error$response;
|
|
466
|
+
if (((_error$response = error.response) == null ? void 0 : _error$response.status) === 404) {
|
|
467
|
+
return [];
|
|
468
|
+
}
|
|
469
|
+
throw error;
|
|
485
470
|
});
|
|
486
471
|
});
|
|
487
472
|
_context.next = 7;
|
|
488
473
|
return Promise.all(slugPromises);
|
|
489
474
|
case 7:
|
|
490
475
|
slugResults = _context.sent;
|
|
491
|
-
allSlugs = slugResults.
|
|
492
|
-
return result.data.data.map(function (page) {
|
|
493
|
-
return {
|
|
494
|
-
slug: page.attributes.slug,
|
|
495
|
-
locale: page.attributes.locale
|
|
496
|
-
};
|
|
497
|
-
});
|
|
498
|
-
}).flat(); // Identify missing locales for each slug
|
|
476
|
+
allSlugs = slugResults.flat(); // Identify missing locales for each slug
|
|
499
477
|
missingLocales = locales.flatMap(function (locale) {
|
|
500
478
|
return allSlugs.filter(function (slug) {
|
|
501
479
|
return slug.locale === STRAPI_FALLBACK_LOCALE;
|
|
@@ -611,7 +589,7 @@ var getPortfolioProjects = /*#__PURE__*/function () {
|
|
|
611
589
|
|
|
612
590
|
var getStrapiCollectionType = /*#__PURE__*/function () {
|
|
613
591
|
var _ref2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(path, key, _ref) {
|
|
614
|
-
var _ref$locale, locale, _ref$preview, preview, _ref$filters, filters, cache, allLocales,
|
|
592
|
+
var _ref$locale, locale, _ref$preview, preview, _ref$filters, filters, cache, allLocales, promises, responses, results, localizedResponses, fallbackResponses, result;
|
|
615
593
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
616
594
|
while (1) switch (_context.prev = _context.next) {
|
|
617
595
|
case 0:
|
|
@@ -624,45 +602,48 @@ var getStrapiCollectionType = /*#__PURE__*/function () {
|
|
|
624
602
|
if (!allLocales.includes(STRAPI_FALLBACK_LOCALE)) {
|
|
625
603
|
allLocales.push(STRAPI_FALLBACK_LOCALE);
|
|
626
604
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
605
|
+
promises = allLocales.map(function (loc) {
|
|
606
|
+
return strapiClient.get(path, {
|
|
607
|
+
params: _extends({
|
|
608
|
+
pLevel: '6',
|
|
609
|
+
locale: loc,
|
|
610
|
+
'pagination[pageSize]': STRAPI_DEFAULT_PAGE_SIZE,
|
|
611
|
+
filters: filters
|
|
612
|
+
}, preview ? {
|
|
613
|
+
publicationState: 'preview'
|
|
614
|
+
} : {}),
|
|
615
|
+
cache: cache
|
|
616
|
+
}).then(function (response) {
|
|
617
|
+
return response.data.data;
|
|
618
|
+
})
|
|
619
|
+
// when a collection type for a requested locale does not exist, Strapi returns a 404. In this case, we return an empty array instead of throwing an error
|
|
620
|
+
["catch"](function (error) {
|
|
621
|
+
var _error$response;
|
|
622
|
+
if (((_error$response = error.response) == null ? void 0 : _error$response.status) === 404) {
|
|
623
|
+
return [];
|
|
624
|
+
}
|
|
625
|
+
throw error;
|
|
626
|
+
});
|
|
648
627
|
});
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
responses
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
628
|
+
_context.next = 9;
|
|
629
|
+
return Promise.all(promises);
|
|
630
|
+
case 9:
|
|
631
|
+
responses = _context.sent;
|
|
632
|
+
results = responses.flat();
|
|
633
|
+
localizedResponses = results.filter(function (d) {
|
|
634
|
+
return d.attributes.locale === locale;
|
|
635
|
+
});
|
|
636
|
+
fallbackResponses = results.filter(function (d) {
|
|
637
|
+
return d.attributes.locale === STRAPI_FALLBACK_LOCALE;
|
|
638
|
+
});
|
|
639
|
+
result = fallbackResponses.map(function (fallbackResponse) {
|
|
640
|
+
var localizedResponse = localizedResponses.find(function (localized) {
|
|
641
|
+
return localized.attributes[key] === fallbackResponse.attributes[key];
|
|
642
|
+
});
|
|
643
|
+
return localizedResponse || fallbackResponse;
|
|
644
|
+
});
|
|
645
|
+
return _context.abrupt("return", result);
|
|
646
|
+
case 15:
|
|
666
647
|
case "end":
|
|
667
648
|
return _context.stop();
|
|
668
649
|
}
|