@pronto-tools-and-more/custom-js-functions 10.38.0 → 10.40.0
Sign up to get free protection for your applications and to get access to all the features.
package/dist/main.js
CHANGED
@@ -407,6 +407,7 @@
|
|
407
407
|
__export(Functions_exports, {
|
408
408
|
dateHelper: () => dateHelper,
|
409
409
|
debugId: () => debugId,
|
410
|
+
getPrimaryCategoryProperty: () => getPrimaryCategoryProperty,
|
410
411
|
getReadTime: () => getReadTime,
|
411
412
|
handleMenuItems: () => handleMenuItems,
|
412
413
|
id: () => id
|
@@ -440,6 +441,26 @@
|
|
440
441
|
return current;
|
441
442
|
};
|
442
443
|
|
444
|
+
// src/parts/GetCategoryProperty/GetCategoryProperty.ts
|
445
|
+
var isCategory = (taxonomy) => {
|
446
|
+
return taxonomy.type === "category";
|
447
|
+
};
|
448
|
+
var getPrimaryCategoryProperty = (content, key) => {
|
449
|
+
const primaryCategoryId = content.properties["taxonomy.category.primary"];
|
450
|
+
const categories = content.taxonomies.filter(isCategory);
|
451
|
+
let primaryCategory = categories.find(
|
452
|
+
(category) => category.id === primaryCategoryId
|
453
|
+
);
|
454
|
+
if (!primaryCategory) {
|
455
|
+
primaryCategory = categories[0];
|
456
|
+
}
|
457
|
+
if (!primaryCategory) {
|
458
|
+
return "n/a";
|
459
|
+
}
|
460
|
+
const value = primaryCategory[key] || "n/a";
|
461
|
+
return value;
|
462
|
+
};
|
463
|
+
|
443
464
|
// src/parts/HandleMenuItems/HandleMenuItems.ts
|
444
465
|
var handleMenuItems = (items, active) => {
|
445
466
|
const index = items.findIndex((item) => item.id === active);
|
package/package.json
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
export * from "../DateHelper/DateHelper.ts";
|
2
2
|
export * from "../FunctionDebugId/FunctionDebugId.ts";
|
3
3
|
export * from "../FunctionId/FunctionId.ts";
|
4
|
+
export * from "../GetCategoryProperty/GetCategoryProperty.ts";
|
4
5
|
export * from "../HandleMenuItems/HandleMenuItems.ts";
|
5
6
|
export * from "../ReadTime/ReadTime.ts";
|
@@ -0,0 +1,19 @@
|
|
1
|
+
const isCategory = (taxonomy) => {
|
2
|
+
return taxonomy.type === "category";
|
3
|
+
};
|
4
|
+
|
5
|
+
export const getPrimaryCategoryProperty = (content, key) => {
|
6
|
+
const primaryCategoryId = content.properties["taxonomy.category.primary"];
|
7
|
+
const categories = content.taxonomies.filter(isCategory);
|
8
|
+
let primaryCategory = categories.find(
|
9
|
+
(category) => category.id === primaryCategoryId
|
10
|
+
);
|
11
|
+
if (!primaryCategory) {
|
12
|
+
primaryCategory = categories[0];
|
13
|
+
}
|
14
|
+
if (!primaryCategory) {
|
15
|
+
return "n/a";
|
16
|
+
}
|
17
|
+
const value = primaryCategory[key] || "n/a";
|
18
|
+
return value;
|
19
|
+
};
|