@se-studio/contentful-rest-api 1.0.41 → 1.0.43
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.js +64 -44
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -122,13 +122,13 @@ async function revalidateTags(tags, reason) {
|
|
|
122
122
|
await delay(500);
|
|
123
123
|
for (const tag of tags) {
|
|
124
124
|
console.log(`Revalidating tag: ${tag} - ${reason}`);
|
|
125
|
-
revalidateTag(tag);
|
|
125
|
+
revalidateTag(tag, "max");
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
async function revalidateSingleTag(tag, reason) {
|
|
129
129
|
await delay(500);
|
|
130
130
|
console.log(`Revalidating single tag: ${tag} - ${reason}`);
|
|
131
|
-
revalidateTag(tag);
|
|
131
|
+
revalidateTag(tag, "max");
|
|
132
132
|
}
|
|
133
133
|
function delay(ms) {
|
|
134
134
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -591,6 +591,7 @@ function createInternalLink(id, fields, context, href, internalType, additionalP
|
|
|
591
591
|
const {
|
|
592
592
|
cmsLabel,
|
|
593
593
|
title,
|
|
594
|
+
name,
|
|
594
595
|
useName,
|
|
595
596
|
featuredImage,
|
|
596
597
|
backgroundColour,
|
|
@@ -605,7 +606,7 @@ function createInternalLink(id, fields, context, href, internalType, additionalP
|
|
|
605
606
|
type: "Internal link",
|
|
606
607
|
internalType,
|
|
607
608
|
id,
|
|
608
|
-
name: cmsLabel ?? "",
|
|
609
|
+
name: name ?? cmsLabel ?? "",
|
|
609
610
|
useName,
|
|
610
611
|
text,
|
|
611
612
|
visual: lookupAsset(context, featuredImage),
|
|
@@ -986,19 +987,42 @@ function collectIconsFromNavigation(navigation) {
|
|
|
986
987
|
}
|
|
987
988
|
return icons;
|
|
988
989
|
}
|
|
990
|
+
function collectIconsFromRichText(richText, processContent) {
|
|
991
|
+
if (!richText?.json) {
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
const traverseNode = (node) => {
|
|
995
|
+
if (node.data?.target && typeof node.data.target === "object" && "type" in node.data.target && "id" in node.data.target) {
|
|
996
|
+
processContent(node.data.target);
|
|
997
|
+
}
|
|
998
|
+
if ("content" in node && Array.isArray(node.content)) {
|
|
999
|
+
for (const child of node.content) {
|
|
1000
|
+
if (typeof child === "object" && child !== null && "nodeType" in child) {
|
|
1001
|
+
traverseNode(child);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
traverseNode(richText.json);
|
|
1007
|
+
}
|
|
989
1008
|
function collectIconsFromContent(contents) {
|
|
990
1009
|
if (!contents) {
|
|
991
1010
|
return [];
|
|
992
1011
|
}
|
|
993
1012
|
const icons = [];
|
|
994
1013
|
const seenIds = /* @__PURE__ */ new Set();
|
|
1014
|
+
const processedIds = /* @__PURE__ */ new Set();
|
|
995
1015
|
function addIcon(icon) {
|
|
996
1016
|
if (!seenIds.has(icon.id)) {
|
|
997
1017
|
seenIds.add(icon.id);
|
|
998
1018
|
icons.push(icon);
|
|
999
1019
|
}
|
|
1000
1020
|
}
|
|
1001
|
-
|
|
1021
|
+
function processContentItem(content) {
|
|
1022
|
+
if (processedIds.has(content.id)) {
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
processedIds.add(content.id);
|
|
1002
1026
|
if (content.type === "Component") {
|
|
1003
1027
|
const componentIcons = collectIconsFromComponent(content);
|
|
1004
1028
|
for (const icon of componentIcons) {
|
|
@@ -1006,11 +1030,12 @@ function collectIconsFromContent(contents) {
|
|
|
1006
1030
|
}
|
|
1007
1031
|
const component = content;
|
|
1008
1032
|
if (component.contents) {
|
|
1009
|
-
const
|
|
1010
|
-
|
|
1011
|
-
addIcon(icon);
|
|
1033
|
+
for (const nested of component.contents) {
|
|
1034
|
+
processContentItem(nested);
|
|
1012
1035
|
}
|
|
1013
1036
|
}
|
|
1037
|
+
collectIconsFromRichText(component.body, processContentItem);
|
|
1038
|
+
collectIconsFromRichText(component.additionalCopy, processContentItem);
|
|
1014
1039
|
}
|
|
1015
1040
|
if (content.type === "Collection") {
|
|
1016
1041
|
const collectionIcons = collectIconsFromCollection(content);
|
|
@@ -1019,11 +1044,14 @@ function collectIconsFromContent(contents) {
|
|
|
1019
1044
|
}
|
|
1020
1045
|
const collection = content;
|
|
1021
1046
|
if (collection.contents) {
|
|
1022
|
-
const
|
|
1023
|
-
|
|
1024
|
-
|
|
1047
|
+
for (const nested of collection.contents) {
|
|
1048
|
+
if (typeof nested === "object" && nested !== null && "type" in nested && "id" in nested) {
|
|
1049
|
+
processContentItem(nested);
|
|
1050
|
+
}
|
|
1025
1051
|
}
|
|
1026
1052
|
}
|
|
1053
|
+
collectIconsFromRichText(collection.body, processContentItem);
|
|
1054
|
+
collectIconsFromRichText(collection.additionalCopy, processContentItem);
|
|
1027
1055
|
}
|
|
1028
1056
|
if (content.type === "Internal link" || content.type === "External link" || content.type === "Download link" || content.type === "Blank link") {
|
|
1029
1057
|
const link = content;
|
|
@@ -1035,6 +1063,9 @@ function collectIconsFromContent(contents) {
|
|
|
1035
1063
|
}
|
|
1036
1064
|
}
|
|
1037
1065
|
}
|
|
1066
|
+
for (const content of contents) {
|
|
1067
|
+
processContentItem(content);
|
|
1068
|
+
}
|
|
1038
1069
|
return icons;
|
|
1039
1070
|
}
|
|
1040
1071
|
function deduplicateIcons(...iconArrays) {
|
|
@@ -2020,14 +2051,21 @@ function baseArticleLinkConverter(context, entry) {
|
|
|
2020
2051
|
const author = fieldsAuthor ? resolveLink(context, sys.id, fieldsAuthor) : void 0;
|
|
2021
2052
|
const download = lookupDownloadAsset(context, fieldsDownload);
|
|
2022
2053
|
const href = externalLink ? externalLink : context.urlCalculators.article(articleType.slug, fields.slug, primaryTag?.slug);
|
|
2023
|
-
return createInternalLink(
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2054
|
+
return createInternalLink(
|
|
2055
|
+
sys.id,
|
|
2056
|
+
{ ...simpleFields, name: fields.cmsLabel },
|
|
2057
|
+
context,
|
|
2058
|
+
href,
|
|
2059
|
+
"Article",
|
|
2060
|
+
{
|
|
2061
|
+
tags,
|
|
2062
|
+
primaryTag,
|
|
2063
|
+
articleType,
|
|
2064
|
+
date,
|
|
2065
|
+
author,
|
|
2066
|
+
download
|
|
2067
|
+
}
|
|
2068
|
+
);
|
|
2031
2069
|
}
|
|
2032
2070
|
function baseArticleTypeLinkConverter(context, entry) {
|
|
2033
2071
|
const { sys, fields } = entry;
|
|
@@ -2041,6 +2079,7 @@ function baseArticleTypeLinkConverter(context, entry) {
|
|
|
2041
2079
|
sys.id,
|
|
2042
2080
|
{
|
|
2043
2081
|
cmsLabel,
|
|
2082
|
+
name,
|
|
2044
2083
|
title: name,
|
|
2045
2084
|
featuredImage,
|
|
2046
2085
|
slug,
|
|
@@ -2278,16 +2317,7 @@ function baseCustomTypeLinkConverter(context, entry) {
|
|
|
2278
2317
|
}
|
|
2279
2318
|
return createInternalLink(
|
|
2280
2319
|
id,
|
|
2281
|
-
|
|
2282
|
-
cmsLabel: fields.cmsLabel,
|
|
2283
|
-
title: fields.name,
|
|
2284
|
-
featuredImage: fields.featuredImage,
|
|
2285
|
-
backgroundColour: fields.backgroundColour,
|
|
2286
|
-
textColour: fields.textColour,
|
|
2287
|
-
indexed: fields.indexed,
|
|
2288
|
-
hidden: fields.hidden,
|
|
2289
|
-
slug: fields.slug
|
|
2290
|
-
},
|
|
2320
|
+
fields,
|
|
2291
2321
|
context,
|
|
2292
2322
|
context.urlCalculators.customType(fields.slug),
|
|
2293
2323
|
"CustomType"
|
|
@@ -2482,14 +2512,8 @@ function basePageLinkConverter(context, entry) {
|
|
|
2482
2512
|
return createInternalLink(
|
|
2483
2513
|
id,
|
|
2484
2514
|
{
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
featuredImage: fields.featuredImage,
|
|
2488
|
-
backgroundColour: fields.backgroundColour,
|
|
2489
|
-
textColour: fields.textColour,
|
|
2490
|
-
indexed: fields.indexed,
|
|
2491
|
-
hidden: fields.hidden,
|
|
2492
|
-
slug: fields.slug
|
|
2515
|
+
...fields,
|
|
2516
|
+
name: fields.cmsLabel
|
|
2493
2517
|
},
|
|
2494
2518
|
context,
|
|
2495
2519
|
context.urlCalculators.page(fields.slug),
|
|
@@ -2511,14 +2535,8 @@ function basePageVariantLinkConverter(context, entry) {
|
|
|
2511
2535
|
return createInternalLink(
|
|
2512
2536
|
id,
|
|
2513
2537
|
{
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
featuredImage: fields.featuredImage,
|
|
2517
|
-
backgroundColour: fields.backgroundColour,
|
|
2518
|
-
textColour: fields.textColour,
|
|
2519
|
-
indexed: fields.indexed,
|
|
2520
|
-
hidden: fields.hidden,
|
|
2521
|
-
slug: fields.slug
|
|
2538
|
+
...fields,
|
|
2539
|
+
name: fields.cmsLabel
|
|
2522
2540
|
},
|
|
2523
2541
|
context,
|
|
2524
2542
|
context.urlCalculators.pageVariant(fields.slug),
|
|
@@ -2549,6 +2567,7 @@ function basePersonLinkConverter(context, entry) {
|
|
|
2549
2567
|
sys.id,
|
|
2550
2568
|
{
|
|
2551
2569
|
...simpleFields,
|
|
2570
|
+
name,
|
|
2552
2571
|
title,
|
|
2553
2572
|
featuredImage: media,
|
|
2554
2573
|
cmsLabel: title
|
|
@@ -2631,6 +2650,7 @@ function baseTagLinkConverter(context, entry) {
|
|
|
2631
2650
|
{
|
|
2632
2651
|
...simpleFields,
|
|
2633
2652
|
cmsLabel,
|
|
2653
|
+
name,
|
|
2634
2654
|
useName: false,
|
|
2635
2655
|
title: name
|
|
2636
2656
|
},
|