coralite 0.6.3 → 0.6.5

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/change-logs.md CHANGED
@@ -1,3 +1,37 @@
1
+ # 🎁 Release notes (`v0.6.5`)
2
+
3
+ ## Changes
4
+ - 4610baa (HEAD -> main, tag: v0.6.5, origin/main) chore: version bump - (*Thomas David*)
5
+ - be2511d ci: remove windows due to unavailability - (*Thomas David*)
6
+ - 821f212 test: cover aggregate filter option - (*Thomas David*)
7
+ - 48eaa76 docs: add CoraliteAggregate to aggregate param - (*Thomas David*)
8
+ - 39ab5ba docs: add CoraliteAggregate typedef - (*Thomas David*)
9
+ - 148dee9 feat: add filter to aggregate function - (*Thomas David*)
10
+ - 15cf0fd docs: add CoraliteAggregate typedef - (*Thomas David*)
11
+ - dbb5b8f feat: remove unused parseHTMLMeta ignoreByAttribute param - (*Thomas David*)
12
+
13
+ ## Metadata
14
+ ```
15
+ This version -------- v0.6.5
16
+ Previous version ---- v0.6.4
17
+ Total commits ------- 8
18
+ ```
19
+ # 🎁 Release notes (`v0.6.4`)
20
+
21
+ ## Changes
22
+ - 41771d5 (HEAD -> main, tag: v0.6.4, origin/main) chore: version bump - (*Thomas David*)
23
+ - ea2ef46 test: cover values param - (*Thomas David*)
24
+ - 60e70d3 feat: add props argument to tokens and slots functions - (*Thomas David*)
25
+ - 1ed074a chore: version bump - (*Thomas David*)
26
+ - 9d710c0 ci: fix publish needs ref - (*Thomas David*)
27
+
28
+ ## Metadata
29
+ ```
30
+ This version -------- v0.6.4
31
+ Previous version ---- v0.6.3
32
+ Total commits ------- 5
33
+ ```
34
+
1
35
  # 🎁 Release notes (`v0.6.3`)
2
36
 
3
37
  ## Changes
package/lib/coralite.js CHANGED
@@ -5,10 +5,10 @@ import render from 'dom-serializer'
5
5
  * @import {
6
6
  * CoraliteElement,
7
7
  * CoraliteTextNode,
8
- * CoraliteAggregateTemplate,
9
8
  * CoraliteAnyNode,
10
9
  * CoraliteModule,
11
- * CoraliteResult
10
+ * CoraliteResult,
11
+ * CoraliteAggregate
12
12
  * } from '#types'
13
13
  */
14
14
 
@@ -19,7 +19,13 @@ import render from 'dom-serializer'
19
19
 
20
20
  /**
21
21
  * @callback DefineComponentSlot
22
- * @param {CoraliteAnyNode[]} nodes
22
+ * @param {CoraliteAnyNode[]} nodes - The nodes to be rendered in the component's slots
23
+ * @param {Object.<string, string>} values - Attribute values
24
+ */
25
+
26
+ /**
27
+ * @callback DefineComponentToken
28
+ * @param {Object.<string, string>} values - Attribute values
23
29
  */
24
30
 
25
31
  /**
@@ -32,7 +38,7 @@ export const tokens = {}
32
38
  *
33
39
  * @param {Object} options
34
40
  * @param {string} [options.id] - Optional component id, if not defined, the id will be extracted from the first top level element with the id attribute
35
- * @param {Object.<string, (string | Function)>} [options.tokens] - Token names and values are either strings or functions representing the corresponding tokens' content or behavior.
41
+ * @param {Object.<string, (string | DefineComponentToken)>} [options.tokens] - Token names and values are either strings or functions representing the corresponding tokens' content or behavior.
36
42
  * @param {Object.<string, DefineComponentSlot>} [options.slots] - Middleware for slot content
37
43
  * @returns {Promise<Object.<string, string>>}
38
44
  */
@@ -44,9 +50,7 @@ export async function defineComponent (options) {
44
50
  /**
45
51
  * Aggregates HTML content from specified paths into a single collection of components.
46
52
  *
47
- * @param {Object} options - Configuration object for the aggregation process
48
- * @param {CoraliteAggregateTemplate | string} options.template - Templates used to display the result
49
- * @param {string} options.path - The path to aggregate, relative to pages directory
53
+ * @param {CoraliteAggregate} options - Configuration object for the aggregation process
50
54
  * @returns {Promise<(CoraliteElement | CoraliteTextNode)[]>}
51
55
  */
52
56
  export async function aggregate (options) {
@@ -4,17 +4,13 @@ import { createComponent, parseHTMLMeta } from './parse.js'
4
4
  import { existsSync } from 'node:fs'
5
5
 
6
6
  /**
7
- * @import { CoraliteTokenOptions, CoraliteModule, CoraliteDocument, CoraliteModuleValues, CoraliteAggregateTemplate } from '#types'
7
+ * @import { CoraliteTokenOptions, CoraliteModule, CoraliteDocument, CoraliteModuleValues, CoraliteAggregateTemplate, CoraliteAggregate } from '#types'
8
8
  */
9
9
 
10
10
  /**
11
11
  * Aggregates HTML content from specified paths into a single collection of components.
12
12
  *
13
- * @param {Object} options - Configuration object for the aggregation process
14
- * @param {string} options.path - The path to aggregate, relative to pages directory
15
- * @param {CoraliteAggregateTemplate | string} options.template - Templates used to display the result
16
- * @param {boolean} [options.recursive] - Whether to recursively search subdirectories
17
- * @param {CoraliteTokenOptions} [options.tokens] - Token configuration options
13
+ * @param {CoraliteAggregate} options - Configuration object for the aggregation process
18
14
  * @param {CoraliteModuleValues} values - Default token values
19
15
  * @param {Object.<string, CoraliteModule>} components - Available components library
20
16
  * @param {CoraliteDocument} document - Current document being processed
@@ -66,8 +62,10 @@ export async function aggregate (options, values, components, document) {
66
62
 
67
63
  for (let i = 0; i < pages.length; i++) {
68
64
  const page = pages[i]
69
- const meta = parseHTMLMeta(page.content, document.ignoreByAttribute)
65
+ const meta = parseHTMLMeta(page.content)
70
66
  const pageValues = Object.assign({}, values)
67
+ let isFilter = !!options.filter
68
+ let ignorePage = false
71
69
 
72
70
  for (const key in meta) {
73
71
  if (Object.prototype.hasOwnProperty.call(meta, key)) {
@@ -77,6 +75,10 @@ export async function aggregate (options, values, components, document) {
77
75
  const item = data[i]
78
76
  let suffix = ''
79
77
 
78
+ if (isFilter && !ignorePage) {
79
+ ignorePage = options.filter(item)
80
+ }
81
+
80
82
  if (i > 0) {
81
83
  suffix = '_' + i
82
84
  }
@@ -86,6 +88,11 @@ export async function aggregate (options, values, components, document) {
86
88
  }
87
89
  }
88
90
 
91
+ // break if page is filtered
92
+ if (isFilter && !ignorePage) {
93
+ break
94
+ }
95
+
89
96
  const component = await createComponent({
90
97
  id: componentId,
91
98
  values: pageValues,
package/lib/parse.js CHANGED
@@ -19,8 +19,8 @@ import { invalidCustomTags, validTags } from './tags.js'
19
19
  * CoraliteDocumentRoot,
20
20
  * CoraliteContentNode,
21
21
  * CoraliteModuleValues,
22
- * CoraliteAggregateTemplate,
23
- * IgnoreByAttribute
22
+ * IgnoreByAttribute,
23
+ CoraliteAggregate
24
24
  * } from '#types'
25
25
  */
26
26
 
@@ -153,7 +153,6 @@ export function parseHTMLDocument (html, path, ignoreByAttribute) {
153
153
  * Parses HTML string containing meta tags and extracts associated metadata.
154
154
  *
155
155
  * @param {string} string - HTML content containing meta tags
156
- * @param {IgnoreByAttribute} ignoreByAttribute - IgnoreByAttribute option (optional) - If provided and true then the HTML tags will be ignored by this attribute name(s)
157
156
  * @returns {Object.<string, CoraliteToken[]>}
158
157
  *
159
158
  * @example
@@ -168,7 +167,7 @@ export function parseHTMLDocument (html, path, ignoreByAttribute) {
168
167
  * //}
169
168
  * ```
170
169
  */
171
- export function parseHTMLMeta (string, ignoreByAttribute) {
170
+ export function parseHTMLMeta (string) {
172
171
  // stack to keep track of current element hierarchy
173
172
  const stack = []
174
173
  /** @type {Object.<string, CoraliteToken[]>} */
@@ -179,15 +178,6 @@ export function parseHTMLMeta (string, ignoreByAttribute) {
179
178
  onopentag (name, attributes) {
180
179
  if (name === 'meta') {
181
180
  if (attributes.content) {
182
- if (ignoreByAttribute) {
183
- // ignore meta tags by attribute name
184
- const ignore = findAttributesToIgnore(ignoreByAttribute, attributes)
185
-
186
- if (ignore) {
187
- return
188
- }
189
- }
190
-
191
181
  if (attributes.property) {
192
182
  addMetadata(meta, attributes.property, attributes.content)
193
183
  }
@@ -697,7 +687,7 @@ export async function parseScript ({
697
687
  */
698
688
  async defineComponent (options) {
699
689
  /** @type {Object.<string, string>} */
700
- const values = {}
690
+ const tokens = {}
701
691
 
702
692
  if (options.tokens) {
703
693
  for (const key in options.tokens) {
@@ -705,7 +695,7 @@ export async function parseScript ({
705
695
  const token = options.tokens[key]
706
696
 
707
697
  if (typeof token === 'function') {
708
- values[key] = await token()
698
+ tokens[key] = await token(values)
709
699
  }
710
700
  }
711
701
  }
@@ -733,7 +723,7 @@ export async function parseScript ({
733
723
  }
734
724
 
735
725
  // compute slot nodes
736
- const result = computedSlot(slotContent) || slotContent
726
+ const result = computedSlot(slotContent, values) || slotContent
737
727
 
738
728
  // append new slot nodes
739
729
  for (let index = 0; index < result.length; index++) {
@@ -751,7 +741,7 @@ export async function parseScript ({
751
741
  }
752
742
  }
753
743
 
754
- return values
744
+ return tokens
755
745
  },
756
746
  /**
757
747
  * @overload
@@ -761,9 +751,7 @@ export async function parseScript ({
761
751
  */
762
752
 
763
753
  /**
764
- * @param {Object} options
765
- * @param {CoraliteAggregateTemplate} options.template - Templates used to display the result
766
- * @param {string} options.path
754
+ * @param {CoraliteAggregate} options
767
755
  */
768
756
  async aggregate (options) {
769
757
  /** @type {string} */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coralite",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "description": "HTML modules static site generator",
5
5
  "main": "./lib/coralite.js",
6
6
  "type": "module",
package/types/index.js CHANGED
@@ -141,3 +141,12 @@
141
141
  /**
142
142
  * @typedef {Array<Array<string, string>>} IgnoreByAttribute - An array of attribute names and values to ignore by element type.
143
143
  */
144
+
145
+ /**
146
+ * @typedef {Object} CoraliteAggregate – Configuration object for the aggregation process
147
+ * @property {string} path - The path to aggregate, relative to pages directory
148
+ * @property {CoraliteAggregateTemplate | string} template - Templates used to display the result
149
+ * @property {Function} [filter] - A function to filter out unwanted elements from the aggregated content.
150
+ * @property {boolean} [recursive] - Whether to recursively search subdirectories
151
+ * @property {CoraliteTokenOptions} [tokens] - Token configuration options
152
+ */