@pronto-tools-and-more/custom-js-functions 10.39.0 → 10.40.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
@@ -442,15 +442,23 @@
442
442
  };
443
443
 
444
444
  // src/parts/GetCategoryProperty/GetCategoryProperty.ts
445
+ var isCategory = (taxonomy) => {
446
+ return taxonomy.type === "category";
447
+ };
445
448
  var getPrimaryCategoryProperty = (content, key) => {
446
449
  const primaryCategoryId = content.properties["taxonomy.category.primary"];
447
- const category = content.taxonomies.find(
448
- (taxonomy) => taxonomy.id === primaryCategoryId
450
+ const categories = content.taxonomies.filter(isCategory);
451
+ let primaryCategory = categories.find(
452
+ (category) => category.id === primaryCategoryId
449
453
  );
450
- if (!category) {
451
- return "";
454
+ if (!primaryCategory) {
455
+ primaryCategory = categories[0];
456
+ }
457
+ if (!primaryCategory) {
458
+ return "n/a";
452
459
  }
453
- return category[key];
460
+ const value = primaryCategory[key] || "n/a";
461
+ return value;
454
462
  };
455
463
 
456
464
  // src/parts/HandleMenuItems/HandleMenuItems.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pronto-tools-and-more/custom-js-functions",
3
- "version": "10.39.0",
3
+ "version": "10.40.0",
4
4
  "description": "",
5
5
  "main": "dist/main.js",
6
6
  "type": "module",
@@ -1,10 +1,19 @@
1
+ const isCategory = (taxonomy) => {
2
+ return taxonomy.type === "category";
3
+ };
4
+
1
5
  export const getPrimaryCategoryProperty = (content, key) => {
2
6
  const primaryCategoryId = content.properties["taxonomy.category.primary"];
3
- const category = content.taxonomies.find(
4
- (taxonomy) => taxonomy.id === primaryCategoryId
7
+ const categories = content.taxonomies.filter(isCategory);
8
+ let primaryCategory = categories.find(
9
+ (category) => category.id === primaryCategoryId
5
10
  );
6
- if (!category) {
7
- return "";
11
+ if (!primaryCategory) {
12
+ primaryCategory = categories[0];
13
+ }
14
+ if (!primaryCategory) {
15
+ return "n/a";
8
16
  }
9
- return category[key];
17
+ const value = primaryCategory[key] || "n/a";
18
+ return value;
10
19
  };