@rettangoli/sites 1.0.0-rc3 → 1.0.0-rc4
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/README.md +1 -1
- package/package.json +1 -1
- package/src/builtinTemplateFunctions.js +32 -2
- package/templates/default/README.md +1 -1
package/README.md
CHANGED
|
@@ -121,7 +121,7 @@ Available in YAML templates/pages without extra setup:
|
|
|
121
121
|
|
|
122
122
|
`formatDate` tokens: `YYYY`, `MM`, `DD`, `HH`, `mm`, `ss`.
|
|
123
123
|
`decodeURI`/`decodeURIComponent` return the original input when decoding fails.
|
|
124
|
-
`sort` supports `order` as `asc` or `desc` and returns a new array.
|
|
124
|
+
`sort` supports `order` as `asc` or `desc` (default: `asc`), accepts dot-path keys (for example `data.date`), and returns a new array.
|
|
125
125
|
`md` returns raw rendered HTML from Markdown for template insertion.
|
|
126
126
|
|
|
127
127
|
## Screenshots
|
package/package.json
CHANGED
|
@@ -75,15 +75,45 @@ function safeDecode(value, decoder) {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
function readSortValue(item, key, keyParts) {
|
|
79
|
+
if (key == null) {
|
|
80
|
+
return item;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (item == null) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!keyParts) {
|
|
88
|
+
return item?.[key];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (Object.prototype.hasOwnProperty.call(item, key)) {
|
|
92
|
+
return item[key];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let current = item;
|
|
96
|
+
for (const part of keyParts) {
|
|
97
|
+
if (!part) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
current = current?.[part];
|
|
101
|
+
}
|
|
102
|
+
return current;
|
|
103
|
+
}
|
|
104
|
+
|
|
78
105
|
function sortImpl(value, key, order = 'asc') {
|
|
79
106
|
if (!Array.isArray(value)) {
|
|
80
107
|
return [];
|
|
81
108
|
}
|
|
109
|
+
|
|
82
110
|
const normalizedOrder = String(order ?? 'asc').toLowerCase() === 'desc' ? 'desc' : 'asc';
|
|
83
111
|
const factor = normalizedOrder === 'asc' ? 1 : -1;
|
|
112
|
+
const keyParts = typeof key === 'string' && key.includes('.') ? key.split('.') : null;
|
|
113
|
+
|
|
84
114
|
return [...value].sort((left, right) => {
|
|
85
|
-
const leftRaw =
|
|
86
|
-
const rightRaw =
|
|
115
|
+
const leftRaw = readSortValue(left, key, keyParts);
|
|
116
|
+
const rightRaw = readSortValue(right, key, keyParts);
|
|
87
117
|
|
|
88
118
|
if (leftRaw == null && rightRaw == null) return 0;
|
|
89
119
|
if (leftRaw == null) return 1;
|
|
@@ -233,7 +233,7 @@ Use these directly in `${...}` expressions:
|
|
|
233
233
|
|
|
234
234
|
Date format tokens: `YYYY`, `MM`, `DD`, `HH`, `mm`, `ss`.
|
|
235
235
|
`decodeURI`/`decodeURIComponent` return the original input when decoding fails.
|
|
236
|
-
`sort` supports `order` as `asc` or `desc` and returns a new array.
|
|
236
|
+
`sort` supports `order` as `asc` or `desc` (default: `asc`), accepts dot-path keys (for example `data.date`), and returns a new array.
|
|
237
237
|
`md` returns raw rendered HTML from Markdown for template insertion.
|
|
238
238
|
|
|
239
239
|
## Static Files
|