@stati/core 1.5.0 → 1.6.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.
@@ -1 +1 @@
1
- {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/core/templates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAG1B,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAkB,MAAM,mBAAmB,CAAC;AAqLzF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,WAAW,GAAG,GAAG,CAW7D;AAED,wBAAsB,UAAU,CAC9B,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,EACnB,GAAG,EAAE,GAAG,EACR,UAAU,CAAC,EAAE,OAAO,EAAE,EACtB,QAAQ,CAAC,EAAE,SAAS,EAAE,GACrB,OAAO,CAAC,MAAM,CAAC,CA0JjB"}
1
+ {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/core/templates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAG1B,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAkB,MAAM,mBAAmB,CAAC;AAsLzF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,WAAW,GAAG,GAAG,CAW7D;AAED,wBAAsB,UAAU,CAC9B,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,EACnB,GAAG,EAAE,GAAG,EACR,UAAU,CAAC,EAAE,OAAO,EAAE,EACtB,QAAQ,CAAC,EAAE,SAAS,EAAE,GACrB,OAAO,CAAC,MAAM,CAAC,CA4JjB"}
@@ -8,6 +8,7 @@ import { isCollectionIndexPage, discoverLayout, getCollectionPathForPage, } from
8
8
  import { resolveSrcDir } from './utils/paths.js';
9
9
  import { createTemplateError } from './utils/template-errors.js';
10
10
  import { createValidatingPartialsProxy } from './utils/partial-validation.js';
11
+ import { propValue } from './utils/template-utils.js';
11
12
  /**
12
13
  * Groups pages by their tags for aggregation purposes.
13
14
  *
@@ -197,6 +198,8 @@ export async function renderPage(page, body, config, eta, navigation, allPages)
197
198
  generator: {
198
199
  version: getStatiVersion(),
199
200
  },
201
+ // Template utilities
202
+ propValue,
200
203
  };
201
204
  // Render partials and store their content
202
205
  // Use multiple passes to allow partials to reference other partials
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Utility functions for Eta templates
3
+ */
4
+ type PropValueArg = string | number | boolean | null | undefined | Record<string, boolean | string | number | null | undefined> | PropValueArg[];
5
+ /**
6
+ * Builds a property value from various inputs, similar to classnames but for any property.
7
+ * Accepts strings, arrays, and objects. Filters out falsy values.
8
+ *
9
+ * @param args - Values to combine
10
+ * @returns Combined property value string
11
+ *
12
+ * @example
13
+ * propValue('class1', 'class2') // 'class1 class2'
14
+ * propValue(['class1', 'class2']) // 'class1 class2'
15
+ * propValue({ 'class1': true, 'class2': false }) // 'class1'
16
+ * propValue('class1', ['class2', 'class3'], { 'class4': true }) // 'class1 class2 class3 class4'
17
+ */
18
+ export declare function propValue(...args: PropValueArg[]): string;
19
+ export {};
20
+ //# sourceMappingURL=template-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-utils.d.ts","sourceRoot":"","sources":["../../../src/core/utils/template-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,KAAK,YAAY,GACb,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,GACT,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GAC5D,YAAY,EAAE,CAAC;AAEnB;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,GAAG,IAAI,EAAE,YAAY,EAAE,GAAG,MAAM,CAwBzD"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Utility functions for Eta templates
3
+ */
4
+ /**
5
+ * Builds a property value from various inputs, similar to classnames but for any property.
6
+ * Accepts strings, arrays, and objects. Filters out falsy values.
7
+ *
8
+ * @param args - Values to combine
9
+ * @returns Combined property value string
10
+ *
11
+ * @example
12
+ * propValue('class1', 'class2') // 'class1 class2'
13
+ * propValue(['class1', 'class2']) // 'class1 class2'
14
+ * propValue({ 'class1': true, 'class2': false }) // 'class1'
15
+ * propValue('class1', ['class2', 'class3'], { 'class4': true }) // 'class1 class2 class3 class4'
16
+ */
17
+ export function propValue(...args) {
18
+ const classes = [];
19
+ for (const arg of args) {
20
+ if (!arg)
21
+ continue;
22
+ if (typeof arg === 'string' || typeof arg === 'number') {
23
+ classes.push(String(arg));
24
+ }
25
+ else if (Array.isArray(arg)) {
26
+ classes.push(...arg
27
+ .filter((item) => item && (typeof item === 'string' || typeof item === 'number'))
28
+ .map(String));
29
+ }
30
+ else if (typeof arg === 'object') {
31
+ for (const [key, value] of Object.entries(arg)) {
32
+ if (value) {
33
+ classes.push(key);
34
+ }
35
+ }
36
+ }
37
+ }
38
+ return classes.join(' ');
39
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stati/core",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",