@pronto-tools-and-more/custom-js-functions 12.45.0 → 12.47.0
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/main.js
CHANGED
@@ -412,7 +412,8 @@
|
|
412
412
|
getPrimaryCategoryProperty: () => getPrimaryCategoryProperty,
|
413
413
|
getReadTime: () => getReadTime,
|
414
414
|
handleMenuItems: () => handleMenuItems,
|
415
|
-
id: () => id
|
415
|
+
id: () => id,
|
416
|
+
parse: () => parse
|
416
417
|
});
|
417
418
|
|
418
419
|
// src/parts/Assign/Assign.ts
|
@@ -460,19 +461,24 @@
|
|
460
461
|
return taxonomy.type === "category";
|
461
462
|
};
|
462
463
|
var getPrimaryCategoryProperty = (content, key) => {
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
primaryCategory
|
470
|
-
|
471
|
-
|
472
|
-
|
464
|
+
try {
|
465
|
+
const primaryCategoryId = content.properties["taxonomy.category.primary"];
|
466
|
+
const categories = content.taxonomies.filter(isCategory);
|
467
|
+
let primaryCategory = categories.find(
|
468
|
+
(category) => category.id === primaryCategoryId
|
469
|
+
);
|
470
|
+
if (!primaryCategory) {
|
471
|
+
primaryCategory = categories[0];
|
472
|
+
}
|
473
|
+
if (!primaryCategory) {
|
474
|
+
return "n/a";
|
475
|
+
}
|
476
|
+
const value = primaryCategory[key] || "n/a";
|
477
|
+
return value;
|
478
|
+
} catch (error) {
|
479
|
+
console.error(`Category Error: ${error}`);
|
480
|
+
return `category error`;
|
473
481
|
}
|
474
|
-
const value = primaryCategory[key] || "n/a";
|
475
|
-
return value;
|
476
482
|
};
|
477
483
|
|
478
484
|
// src/parts/HandleMenuItems/HandleMenuItems.ts
|
@@ -484,9 +490,18 @@
|
|
484
490
|
return `highlight-${index}`;
|
485
491
|
};
|
486
492
|
|
493
|
+
// src/parts/Parse/Parse.ts
|
494
|
+
var parse = (content) => {
|
495
|
+
return JSON.parse(content);
|
496
|
+
};
|
497
|
+
|
487
498
|
// src/parts/ReadTime/ReadTime.ts
|
488
499
|
var getReadTime = (content) => {
|
489
500
|
const parsedSeo = JSON.parse(content?.properties?.purple_seo_meta);
|
501
|
+
const readTimeNumber = parsedSeo?.est_reading_time_minutes;
|
502
|
+
if (readTimeNumber) {
|
503
|
+
return `${readTimeNumber} min`;
|
504
|
+
}
|
490
505
|
const readTime = parsedSeo?.twitter_misc?.["Est. reading time"] || "n/a";
|
491
506
|
if (typeof readTime === "number") {
|
492
507
|
return `${readTime} min`;
|
package/package.json
CHANGED
@@ -5,4 +5,5 @@ export * from "../FunctionDebugId/FunctionDebugId.ts";
|
|
5
5
|
export * from "../FunctionId/FunctionId.ts";
|
6
6
|
export * from "../GetCategoryProperty/GetCategoryProperty.ts";
|
7
7
|
export * from "../HandleMenuItems/HandleMenuItems.ts";
|
8
|
+
export * from "../Parse/Parse.ts";
|
8
9
|
export * from "../ReadTime/ReadTime.ts";
|
@@ -3,17 +3,22 @@ const isCategory = (taxonomy) => {
|
|
3
3
|
};
|
4
4
|
|
5
5
|
export const getPrimaryCategoryProperty = (content, key) => {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
primaryCategory
|
6
|
+
try {
|
7
|
+
const primaryCategoryId = content.properties["taxonomy.category.primary"];
|
8
|
+
const categories = content.taxonomies.filter(isCategory);
|
9
|
+
let primaryCategory = categories.find(
|
10
|
+
(category) => category.id === primaryCategoryId
|
11
|
+
);
|
12
|
+
if (!primaryCategory) {
|
13
|
+
primaryCategory = categories[0];
|
14
|
+
}
|
15
|
+
if (!primaryCategory) {
|
16
|
+
return "n/a";
|
17
|
+
}
|
18
|
+
const value = primaryCategory[key] || "n/a";
|
19
|
+
return value;
|
20
|
+
} catch (error) {
|
21
|
+
console.error(`Category Error: ${error}`);
|
22
|
+
return `category error`;
|
13
23
|
}
|
14
|
-
if (!primaryCategory) {
|
15
|
-
return "n/a";
|
16
|
-
}
|
17
|
-
const value = primaryCategory[key] || "n/a";
|
18
|
-
return value;
|
19
24
|
};
|
@@ -1,5 +1,9 @@
|
|
1
1
|
export const getReadTime = (content: any) => {
|
2
2
|
const parsedSeo = JSON.parse(content?.properties?.purple_seo_meta);
|
3
|
+
const readTimeNumber = parsedSeo?.est_reading_time_minutes;
|
4
|
+
if (readTimeNumber) {
|
5
|
+
return `${readTimeNumber} min`;
|
6
|
+
}
|
3
7
|
const readTime = parsedSeo?.twitter_misc?.["Est. reading time"] || "n/a";
|
4
8
|
if (typeof readTime === "number") {
|
5
9
|
return `${readTime} min`;
|