coralite 0.6.7 → 0.6.9

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/changelog.md ADDED
@@ -0,0 +1,182 @@
1
+ # 🎁 Release notes (`v0.6.9`)
2
+
3
+ ## Changes
4
+ - e79d7c9 (HEAD -> main, tag: v0.6.9, origin/main) fix: aggregation limit is offset by offset - (*[Thomas David](https://codeberg.org/tjdavid)*)
5
+ - 6f8253f test: cover nested document root components - (*[Thomas David](https://codeberg.org/tjdavid)*)
6
+ - 77d0e36 feat: create nested custom elements on document root - (*[Thomas David](https://codeberg.org/tjdavid)*)
7
+ - 2c176e5 chore: update changelog - (*[Thomas David](https://codeberg.org/tjdavid)*)
8
+ - f5a3639 chore: version bump - (*[Thomas David](https://codeberg.org/tjdavid)*)
9
+
10
+ ## Metadata
11
+ ```
12
+ This version -------- v0.6.9
13
+ Previous version ---- v0.6.8
14
+ Total commits ------- 5
15
+ ```
16
+ # 🎁 Release notes (`v0.6.8`)
17
+
18
+ ## Changes
19
+ - 3b8fe8c (tag: v0.6.8, origin/main) test: use parseHTML - (*[Thomas David](https://codeberg.org/tjdavid)*)
20
+ - f7d6ab9 test: add meta prefix to tokens - (*[Thomas David](https://codeberg.org/tjdavid)*)
21
+ - 34c15d2 test: remove unused variables - (*[Thomas David](https://codeberg.org/tjdavid)*)
22
+ - b39ac47 test: cover nested components - (*[Thomas David](https://codeberg.org/tjdavid)*)
23
+ - 81c3da4 feat: computed slots parse strings - (*[Thomas David](https://codeberg.org/tjdavid)*)
24
+ - 585b7d6 fix: remove slot attribute - (*[Thomas David](https://codeberg.org/tjdavid)*)
25
+ - 00f68ef fix: process computed tokens before replacing values - (*[Thomas David](https://codeberg.org/tjdavid)*)
26
+ - b13a016 feat: add identifier to SourceTextModule - (*[Thomas David](https://codeberg.org/tjdavid)*)
27
+ - 6257a0f feat: aggregate add meta value namespace - (*[Thomas David](https://codeberg.org/tjdavid)*)
28
+ - 469d5fe feat: aggregate handle page sort - (*[Thomas David](https://codeberg.org/tjdavid)*)
29
+ - bd23fbe feat: aggregate handle page limit - (*[Thomas David](https://codeberg.org/tjdavid)*)
30
+
31
+ ## Metadata
32
+ ```
33
+ This version -------- v0.6.8
34
+ Previous version ---- v0.6.7
35
+ Total commits ------- 11
36
+ ```
37
+ # 🎁 Release notes (`v0.6.7`)
38
+
39
+ ## Changes
40
+ - 7138a0b (HEAD -> main, tag: v0.6.7, origin/main) update repo url - (*[Thomas David](https://codeberg.org/tjdavid)*)
41
+ - 41988a4 license change - (*[Thomas David](https://codeberg.org/tjdavid)*)
42
+ - f471dbc chore: version bump - (*[Thomas David](https://codeberg.org/tjdavid)*)
43
+ - 095e35c fix: aggregate filter single meta item - (*[Thomas David](https://codeberg.org/tjdavid)*)
44
+
45
+ ## Metadata
46
+ ```
47
+ This version -------- v0.6.7
48
+ Previous version ---- v0.6.6
49
+ Total commits ------- 4
50
+ ```
51
+ # 🎁 Release notes (`v0.6.6`)
52
+
53
+ ## Changes
54
+ - 790c585 (HEAD -> main, tag: v0.6.6, origin/main) fix: computedSlots token param includes attrib values - (*[Thomas David](https://codeberg.org/tjdavid)*)
55
+ - 505d4f0 feat: export parseHTML util - (*[Thomas David](https://codeberg.org/tjdavid)*)
56
+ - d0fc52d docs: update CoraliteModuleValues type - (*[Thomas David](https://codeberg.org/tjdavid)*)
57
+ - 6ad27ce feat: tokens parse HTML - (*[Thomas David](https://codeberg.org/tjdavid)*)
58
+ - 9497c25 feat: export current document to template context - (*[Thomas David](https://codeberg.org/tjdavid)*)
59
+ - df9a1a5 refactor: create reusable parseHTML function - (*[Thomas David](https://codeberg.org/tjdavid)*)
60
+ - ebb388c feat: append rendered token to custom element slots - (*[Thomas David](https://codeberg.org/tjdavid)*)
61
+ - 1f6ffd0 feat: add filtering to aggregate function - (*[Thomas David](https://codeberg.org/tjdavid)*)
62
+
63
+ ## Metadata
64
+ ```
65
+ This version -------- v0.6.6
66
+ Previous version ---- v0.6.5
67
+ Total commits ------- 8
68
+ ```
69
+ # 🎁 Release notes (`v0.6.5`)
70
+
71
+ ## Changes
72
+ - 4610baa (HEAD -> main, tag: v0.6.5, origin/main) chore: version bump - (*[Thomas David](https://codeberg.org/tjdavid)*)
73
+ - be2511d ci: remove windows due to unavailability - (*[Thomas David](https://codeberg.org/tjdavid)*)
74
+ - 821f212 test: cover aggregate filter option - (*[Thomas David](https://codeberg.org/tjdavid)*)
75
+ - 48eaa76 docs: add CoraliteAggregate to aggregate param - (*[Thomas David](https://codeberg.org/tjdavid)*)
76
+ - 39ab5ba docs: add CoraliteAggregate typedef - (*[Thomas David](https://codeberg.org/tjdavid)*)
77
+ - 148dee9 feat: add filter to aggregate function - (*[Thomas David](https://codeberg.org/tjdavid)*)
78
+ - 15cf0fd docs: add CoraliteAggregate typedef - (*[Thomas David](https://codeberg.org/tjdavid)*)
79
+ - dbb5b8f feat: remove unused parseHTMLMeta ignoreByAttribute param - (*[Thomas David](https://codeberg.org/tjdavid)*)
80
+
81
+ ## Metadata
82
+ ```
83
+ This version -------- v0.6.5
84
+ Previous version ---- v0.6.4
85
+ Total commits ------- 8
86
+ ```
87
+ # 🎁 Release notes (`v0.6.4`)
88
+
89
+ ## Changes
90
+ - 41771d5 (HEAD -> main, tag: v0.6.4, origin/main) chore: version bump - (*[Thomas David](https://codeberg.org/tjdavid)*)
91
+ - ea2ef46 test: cover values param - (*[Thomas David](https://codeberg.org/tjdavid)*)
92
+ - 60e70d3 feat: add props argument to tokens and slots functions - (*[Thomas David](https://codeberg.org/tjdavid)*)
93
+ - 1ed074a chore: version bump - (*[Thomas David](https://codeberg.org/tjdavid)*)
94
+ - 9d710c0 ci: fix publish needs ref - (*[Thomas David](https://codeberg.org/tjdavid)*)
95
+
96
+ ## Metadata
97
+ ```
98
+ This version -------- v0.6.4
99
+ Previous version ---- v0.6.3
100
+ Total commits ------- 5
101
+ ```
102
+
103
+ # 🎁 Release notes (`v0.6.3`)
104
+
105
+ ## Changes
106
+ - 6fe640d (HEAD -> main, tag: v0.6.3, origin/main) test: cover ignore by attribute - (*[Thomas David](https://codeberg.org/tjdavid)*)
107
+ - a47ff8f types: add IgnoreByAttribute type - (*[Thomas David](https://codeberg.org/tjdavid)*)
108
+ - 8547c37 feat: ignore element by attributes inside meta and component parsers - (*[Thomas David](https://codeberg.org/tjdavid)*)
109
+ - f61ae88 docs: update ignore-attribute example with quotes - (*[Thomas David](https://codeberg.org/tjdavid)*)
110
+ - d4a277d docs: create consistent path names in example - (*[Thomas David](https://codeberg.org/tjdavid)*)
111
+ - 566463f docs: remove requirements section - (*[Thomas David](https://codeberg.org/tjdavid)*)
112
+ - 2493ab3 style: import type new line - (*[Thomas David](https://codeberg.org/tjdavid)*)
113
+ - 2e44174 ci: test before publish - (*[Thomas David](https://codeberg.org/tjdavid)*)
114
+ - c1d5ce7 fix: add template id to script module error - (*[Thomas David](https://codeberg.org/tjdavid)*)
115
+ - 4fabac1 ci: include self to test script - (*[Thomas David](https://codeberg.org/tjdavid)*)
116
+ - efd34d0 fix: add --experimental-vm-modules to shebang - (*[Thomas David](https://codeberg.org/tjdavid)*)
117
+ - 7da5d98 refactor: add type check before splicing children. - (*[Thomas David](https://codeberg.org/tjdavid)*)
118
+ - 2e39027 fix: catch bad options for aggregate function - (*[Thomas David](https://codeberg.org/tjdavid)*)
119
+
120
+ ## Metadata
121
+ ```
122
+ This version -------- v0.6.3
123
+ Previous version ---- v0.6.2
124
+ Total commits ------- 13
125
+ ```
126
+ # 🎁 Release notes (`v0.6.2`)
127
+
128
+ ## Changes
129
+ - be6c54c (HEAD -> main, tag: v0.6.2, origin/main) fix: update lock - (*[Thomas David](https://codeberg.org/tjdavid)*)
130
+ - 15d9b4e chore: version bump - (*[Thomas David](https://codeberg.org/tjdavid)*)
131
+ - fac695e fix: node v18 requires globalThis reference for crypto - (*[Thomas David](https://codeberg.org/tjdavid)*)
132
+ - d7c551e doc: format doc links - (*[Thomas David](https://codeberg.org/tjdavid)*)
133
+
134
+ ## Metadata
135
+ ```
136
+ This version -------- v0.6.2
137
+ Previous version ---- v0.6.1
138
+ Total commits ------- 4
139
+ ```
140
+ # 🎁 Release notes (`v0.6.1`)
141
+
142
+ ## Changes
143
+ - bcc1637 (HEAD -> main, tag: v0.6.1, origin/main) chore: version bump - (*[Thomas David](https://codeberg.org/tjdavid)*)
144
+ - 95cfdba docs: add doc links - (*[Thomas David](https://codeberg.org/tjdavid)*)
145
+ - 101a305 fix: render computedSlot nodes - (*[Thomas David](https://codeberg.org/tjdavid)*)
146
+ - 11a35d8 feat: dynamically import modules - (*[Thomas David](https://codeberg.org/tjdavid)*)
147
+ - e1364b9 docs: add CoraliteResult type - (*[Thomas David](https://codeberg.org/tjdavid)*)
148
+ - 11c6405 docs: add @example to coralite - (*[Thomas David](https://codeberg.org/tjdavid)*)
149
+ - a050263 docs: basic technical documentation - (*[Thomas David](https://codeberg.org/tjdavid)*)
150
+ - 83fdddd docs: update dry run option - (*[Thomas David](https://codeberg.org/tjdavid)*)
151
+
152
+ ## Metadata
153
+ ```
154
+ This version -------- v0.6.1
155
+ Previous version ---- v0.6.0
156
+ Total commits ------- 8
157
+ ```
158
+ # 🎁 Release notes (`v0.6.0`)
159
+
160
+ ## Changes
161
+ - 22d75e2 (HEAD -> main, tag: v0.6.0, origin/main) chore: version bump - (*[Thomas David](https://codeberg.org/tjdavid)*)
162
+ - c5cc7cc lint: ignore playwright-report - (*[Thomas David](https://codeberg.org/tjdavid)*)
163
+ - fdb3697 docs: add dry run option - (*[Thomas David](https://codeberg.org/tjdavid)*)
164
+ - 891db2e feat: export coralite utils - (*[Thomas David](https://codeberg.org/tjdavid)*)
165
+ - 9265681 test: cover ignore attribute - (*[Thomas David](https://codeberg.org/tjdavid)*)
166
+ - 5d44661 fix: allow missing component to compile - (*[Thomas David](https://codeberg.org/tjdavid)*)
167
+ - f3d6e65 docs: add remove prop to CoraliteElement - (*[Thomas David](https://codeberg.org/tjdavid)*)
168
+ - 229fef5 feat: new option to ignore element by attribute name value pair - (*[Thomas David](https://codeberg.org/tjdavid)*)
169
+ - c78dde1 chore: include kleur dep - (*[Thomas David](https://codeberg.org/tjdavid)*)
170
+ - b10bbe8 feat: update cli to use coralite module - (*[Thomas David](https://codeberg.org/tjdavid)*)
171
+ - 48fe816 docs: make defineComponent param tokens and slots optional - (*[Thomas David](https://codeberg.org/tjdavid)*)
172
+ - 02a5e8f feat: move coralite to a module - (*[Thomas David](https://codeberg.org/tjdavid)*)
173
+ - d336090 feat: get package.json util function - (*[Thomas David](https://codeberg.org/tjdavid)*)
174
+ - e210844 feat: add document used in error message - (*[Thomas David](https://codeberg.org/tjdavid)*)
175
+ - 1556a3b chore: version bump - (*[Thomas David](https://codeberg.org/tjdavid)*)
176
+
177
+ ## Metadata
178
+ ```
179
+ This version -------- v0.6.0
180
+ Previous version ---- v0.5.1
181
+ Total commits ------- 15
182
+ ```
@@ -59,11 +59,31 @@ export async function aggregate (options, values, components, document) {
59
59
  })
60
60
 
61
61
  let result = []
62
+ let startIndex = 0
63
+ let endIndex = pages.length
64
+
65
+ if (options.offset) {
66
+ if (options.offset > endIndex) {
67
+ startIndex = endIndex
68
+ } else {
69
+ startIndex = options.offset
70
+ }
71
+ }
72
+
73
+ if (options.limit) {
74
+ const limit = options.limit + startIndex
62
75
 
63
- for (let i = 0; i < pages.length; i++) {
76
+ if (limit < endIndex) {
77
+ endIndex = limit
78
+ }
79
+ }
80
+
81
+
82
+ for (let i = startIndex; i < endIndex; i++) {
64
83
  const page = pages[i]
65
84
  const meta = parseHTMLMeta(page.content)
66
85
  const pageValues = Object.assign({}, values)
86
+ let prefix = 'meta_'
67
87
  let isFilter = !!options.filter
68
88
  let ignorePage = false
69
89
 
@@ -72,10 +92,12 @@ export async function aggregate (options, values, components, document) {
72
92
  const data = meta[key]
73
93
  const content = []
74
94
  const firstItem = data[0]
95
+ const firstItemName = prefix + firstItem.name
75
96
 
76
97
  if (data.length > 1) {
77
98
  for (let i = 0; i < data.length; i++) {
78
99
  const item = data[i]
100
+ let name = prefix + item.name
79
101
  let suffix = ''
80
102
 
81
103
  if (isFilter && !ignorePage) {
@@ -84,21 +106,21 @@ export async function aggregate (options, values, components, document) {
84
106
  suffix = '_' + i
85
107
 
86
108
  if (i === 0) {
87
- pageValues[item.name] = item.content
109
+ pageValues[name] = item.content
88
110
  }
89
111
 
90
- pageValues[item.name + suffix] = item.content
112
+ pageValues[name + suffix] = item.content
91
113
 
92
114
  content.push(item.content)
93
115
  }
94
116
 
95
- pageValues[firstItem.name + '_list'] = content
117
+ pageValues[firstItemName + '_list'] = content
96
118
  } else {
97
119
  if (isFilter && !ignorePage) {
98
120
  ignorePage = options.filter(firstItem)
99
121
  }
100
122
 
101
- pageValues[firstItem.name] = firstItem.content
123
+ pageValues[firstItemName] = firstItem.content
102
124
  }
103
125
  }
104
126
  }
@@ -121,5 +143,10 @@ export async function aggregate (options, values, components, document) {
121
143
  }
122
144
  }
123
145
 
146
+ // sort results
147
+ if (typeof options.sort === 'function') {
148
+ result.sort(options.sort)
149
+ }
150
+
124
151
  return result
125
152
  }
package/lib/parse.js CHANGED
@@ -2,7 +2,7 @@ import { Parser } from 'htmlparser2'
2
2
  import { aggregate } from './html-module.js'
3
3
  import vm from 'node:vm'
4
4
  import { invalidCustomTags, validTags } from './tags.js'
5
-
5
+ import { join } from 'path'
6
6
  /**
7
7
  * @import {Module} from 'node:vm'
8
8
  * @import {
@@ -490,7 +490,19 @@ export async function createComponent ({
490
490
  component = structuredClone(component)
491
491
 
492
492
  const template = component.template
493
- const computedTokens = []
493
+
494
+ // merge values from component script
495
+ if (component.script) {
496
+ const computedValues = await parseScript({
497
+ component,
498
+ values,
499
+ element,
500
+ components,
501
+ document
502
+ })
503
+
504
+ values = Object.assign(values, computedValues)
505
+ }
494
506
 
495
507
  // replace tokens in the template with their values from `values` object and store them into computedTokens array for later use if needed (e.g., to be injected back).
496
508
  for (let i = 0; i < component.tokens.attributes.length; i++) {
@@ -501,26 +513,17 @@ export async function createComponent ({
501
513
  let value = values[token.name]
502
514
 
503
515
  if (value == null) {
504
- if (component.script) {
505
- computedTokens.push({
506
- type: 'attribute',
507
- node: item.element,
508
- attribute: item.name,
509
- name: token.name,
510
- content: token.content
511
- })
512
-
513
- continue
514
- } else {
515
- console.log('Token "' + token.name +'" was empty used on "' + component.id + '"')
516
- value = ''
517
- }
516
+ console.error('Token "' + token.name +'" was empty used on "' + component.id + '"')
517
+ value = ''
518
518
  }
519
519
 
520
- if (typeof value === 'string') {
521
- // replace token with value
522
- item.element.attribs[item.name] = item.element.attribs[item.name].replace(token.content, value)
523
- }
520
+ replaceToken({
521
+ type: 'attribute',
522
+ node: item.element,
523
+ attribute: item.name,
524
+ content: token.content,
525
+ value
526
+ })
524
527
  }
525
528
  }
526
529
 
@@ -532,87 +535,16 @@ export async function createComponent ({
532
535
  let value = values[token.name]
533
536
 
534
537
  if (value == null) {
535
- if (component.script) {
536
- computedTokens.push({
537
- type: 'textNode',
538
- node: item.textNode,
539
- name: token.name,
540
- content: token.content
541
- })
542
-
543
- continue
544
- } else {
545
- console.error('Token "' + token.name +'" was empty used on "' + component.id + '"')
546
- value = ''
547
- }
548
- }
549
-
550
- if (typeof value === 'string') {
551
- // replace token with value
552
- item.textNode.data = item.textNode.data.replace(token.content, value)
538
+ console.error('Token "' + token.name +'" was empty used on "' + component.id + '"')
539
+ value = ''
553
540
  }
554
- }
555
- }
556
541
 
557
- // merge values from component script
558
- if (component.script) {
559
- const computedValues = await parseScript({
560
- component,
561
- values,
562
- element,
563
- components,
564
- document
565
- })
566
-
567
- values = Object.assign(values, computedValues)
568
-
569
- for (let i = 0; i < computedTokens.length; i++) {
570
- const computedToken = computedTokens[i]
571
- const node = computedToken.node
572
- const value = values[computedToken.name]
573
-
574
- if (
575
- computedToken.type === 'attribute'
576
- && node.type === 'tag'
577
- && typeof value === 'string'
578
- ) {
579
- node.attribs[computedToken.attribute] = node.attribs[computedToken.attribute].replace(computedToken.content, value)
580
- } else if (node.type === 'text') {
581
- if (Array.isArray(value)) {
582
- // inject nodes
583
- const textSplit = node.data.split(computedToken.content)
584
- const childIndex = node.parent.children.indexOf(node)
585
- const children = []
586
-
587
- // append computed tokens in between token split
588
- for (let i = 0; i < value.length; i++) {
589
- const child = value[i]
590
-
591
- if (typeof child !== 'string') {
592
- // update child parent
593
- child.parent = node.parent
594
- children.push(child)
595
- }
596
- }
597
-
598
- // replace computed token
599
- node.parent.children.splice(childIndex, 1,
600
- {
601
- type: 'text',
602
- data: textSplit[0],
603
- parent: node.parent
604
- },
605
- ...children,
606
- {
607
- type: 'text',
608
- data: textSplit[1],
609
- parent: node.parent
610
- })
611
- } else {
612
- // replace token string
613
- node.data = node.data.replace(computedToken.content, value)
614
- }
615
- }
542
+ replaceToken({
543
+ type: 'textNode',
544
+ node: item.textNode,
545
+ content: token.content,
546
+ value
547
+ })
616
548
  }
617
549
  }
618
550
 
@@ -643,9 +575,16 @@ export async function createComponent ({
643
575
  }
644
576
  }
645
577
 
578
+ // append custom attributes to values
579
+ for (const key in customElement.attribs) {
580
+ if (!values.hasOwnProperty(key)) {
581
+ values[key] = customElement.attribs[key]
582
+ }
583
+ }
584
+
646
585
  const component = await createComponent({
647
586
  id: customElement.name,
648
- values: Object.assign(values, customElement.attribs),
587
+ values,
649
588
  element: customElement,
650
589
  components,
651
590
  document
@@ -685,6 +624,11 @@ export async function createComponent ({
685
624
  const slot = slots[slotName]
686
625
 
687
626
  if (slot) {
627
+ if (elementSlotContent.node.attribs) {
628
+ // remove slot attribute
629
+ delete elementSlotContent.node.attribs.slot
630
+ }
631
+
688
632
  slotChildren[slotName].push(elementSlotContent.node)
689
633
  }
690
634
  }
@@ -699,6 +643,27 @@ export async function createComponent ({
699
643
  if (!slotNodes.length) {
700
644
  // set default content
701
645
  slotNodes = slot.element.children || []
646
+ } else {
647
+ const startIndex = slotNodes.length - 1
648
+
649
+ for (let i = startIndex; i > -1; i--) {
650
+ const node = slotNodes[i]
651
+ const component = components[node.name]
652
+
653
+ if (component) {
654
+ const component = await createComponent({
655
+ id: node.name,
656
+ values,
657
+ element: node,
658
+ components,
659
+ document
660
+ })
661
+
662
+ if (component) {
663
+ slotNodes.splice(i, 1, ...component.children)
664
+ }
665
+ }
666
+ }
702
667
  }
703
668
 
704
669
  // replace slot element with content
@@ -809,6 +774,11 @@ export async function parseScript ({
809
774
  for (let i = 0; i < element.slots.length; i++) {
810
775
  const slot = element.slots[i]
811
776
 
777
+ // exclude empty strings
778
+ if (slot.node.type === 'text' && !slot.node.data.trim()) {
779
+ continue
780
+ }
781
+
812
782
  if (slot.name === name) {
813
783
  // slot content to compute
814
784
  slotContent.push(slot.node)
@@ -821,13 +791,22 @@ export async function parseScript ({
821
791
  const result = computedSlot(slotContent, tokens) || slotContent
822
792
 
823
793
  // append new slot nodes
824
- for (let index = 0; index < result.length; index++) {
825
- const node = result[index]
826
-
794
+ if (typeof result === 'string') {
827
795
  elementSlots.push({
828
796
  name,
829
- node
797
+ node: {
798
+ type: 'text',
799
+ data: result
800
+ }
830
801
  })
802
+ } else if (Array.isArray(result)) {
803
+ for (let index = 0; index < result.length; index++) {
804
+ /** @TODO create a node checker to verify */
805
+ elementSlots.push({
806
+ name,
807
+ node: result[index]
808
+ })
809
+ }
831
810
  }
832
811
 
833
812
  // update element slots
@@ -870,6 +849,7 @@ export async function parseScript ({
870
849
  })
871
850
 
872
851
  const script = new vm.SourceTextModule(component.script, {
852
+ identifier: join(document.parentPath, document.name + '.js'),
873
853
  context: contextifiedObject
874
854
  })
875
855
 
@@ -1058,3 +1038,64 @@ function findAttributesToIgnore (ignore, attributes) {
1058
1038
 
1059
1039
  return false
1060
1040
  }
1041
+
1042
+ /**
1043
+ * Replaces a token in a Coralite node based on its type, attribute, and content.
1044
+ *
1045
+ * @param {Object} token - The token to replace.
1046
+ * @param {string} token.type - The type of the token ('attribute' or 'text').
1047
+ * @param {CoraliteElement|CoraliteTextNode} token.node - The node containing the token.
1048
+ * @param {string} token.attribute - The attribute name to replace within the node.
1049
+ * @param {string} token.content - The content of the token.
1050
+ * @param {string|CoraliteDirective|CoraliteAnyNode} token.value - The value associated with the token.
1051
+ */
1052
+ function replaceToken ({
1053
+ type,
1054
+ node,
1055
+ attribute,
1056
+ content,
1057
+ value
1058
+ }) {
1059
+ if (
1060
+ type === 'attribute'
1061
+ && node.type === 'tag'
1062
+ && typeof value === 'string'
1063
+ ) {
1064
+ node.attribs[attribute] = node.attribs[attribute].replace(content, value)
1065
+ } else if (node.type === 'text') {
1066
+ if (Array.isArray(value)) {
1067
+ // inject nodes
1068
+ const textSplit = node.data.split(content)
1069
+ const childIndex = node.parent.children.indexOf(node)
1070
+ const children = []
1071
+
1072
+ // append computed tokens in between token split
1073
+ for (let i = 0; i < value.length; i++) {
1074
+ const child = value[i]
1075
+
1076
+ if (typeof child !== 'string') {
1077
+ // update child parent
1078
+ child.parent = node.parent
1079
+ children.push(child)
1080
+ }
1081
+ }
1082
+
1083
+ // replace computed token
1084
+ node.parent.children.splice(childIndex, 1,
1085
+ {
1086
+ type: 'text',
1087
+ data: textSplit[0],
1088
+ parent: node.parent
1089
+ },
1090
+ ...children,
1091
+ {
1092
+ type: 'text',
1093
+ data: textSplit[1],
1094
+ parent: node.parent
1095
+ })
1096
+ } else {
1097
+ // replace token string
1098
+ node.data = node.data.replace(content, value)
1099
+ }
1100
+ }
1101
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coralite",
3
- "version": "0.6.7",
3
+ "version": "0.6.9",
4
4
  "description": "HTML modules static site generator",
5
5
  "main": "./lib/coralite.js",
6
6
  "type": "module",
@@ -3,4 +3,4 @@
3
3
  export VERSION=$(git tag --sort=-committerdate | head -1)
4
4
  export PREVIOUS_VERSION=$(git tag --sort=-committerdate | head -2 | awk '{split($0, tags, "\n")} END {print tags[1]}')
5
5
  export CHANGES=$(git log --pretty="- %h%d %s - (*%an*)" $VERSION...$PREVIOUS_VERSION)
6
- printf "# 🎁 Release notes (\`$VERSION\`)\n\n## Changes\n$CHANGES\n\n## Metadata\n\`\`\`\nThis version -------- $VERSION\nPrevious version ---- $PREVIOUS_VERSION\nTotal commits ------- $(echo "$CHANGES" | wc -l)\n\`\`\`\n" > change-logs.md
6
+ printf "# 🎁 Release notes (\`$VERSION\`)\n\n## Changes\n$CHANGES\n\n## Metadata\n\`\`\`\nThis version -------- $VERSION\nPrevious version ---- $PREVIOUS_VERSION\nTotal commits ------- $(echo "$CHANGES" | wc -l)\n\`\`\`\n" > changelog.md
package/types/index.js CHANGED
@@ -147,6 +147,12 @@
147
147
  * @param {Object.<string, string>} metadata - Aggregated HTML page metadata
148
148
  */
149
149
 
150
+ /**
151
+ * @callback CoraliteAggregateSort
152
+ * @param {Object.<string, string>} a - Aggregated HTML page metadata
153
+ * @param {Object.<string, string>} b - Aggregated HTML page metadata
154
+ */
155
+
150
156
  /**
151
157
  * @typedef {Object} CoraliteAggregate – Configuration object for the aggregation process
152
158
  * @property {string} path - The path to aggregate, relative to pages directory
@@ -154,4 +160,7 @@
154
160
  * @property {CoraliteAggregateFilter} [filter] - Callback to filter out unwanted elements from the aggregated content.
155
161
  * @property {boolean} [recursive] - Whether to recursively search subdirectories
156
162
  * @property {CoraliteTokenOptions} [tokens] - Token configuration options
163
+ * @property {CoraliteAggregateSort} [sort] - Sort aggregated pages
164
+ * @property {number} [limit] - Specifies the maximum number of results to retrieve.
165
+ * @property {number} [offset] - Specifies the starting index for the results list.
157
166
  */
package/change-logs.md DELETED
@@ -1,146 +0,0 @@
1
- # 🎁 Release notes (`v0.6.7`)
2
-
3
- ## Changes
4
- - 7138a0b (HEAD -> main, tag: v0.6.7, origin/main) update repo url - (*Thomas David*)
5
- - 41988a4 license change - (*Thomas David*)
6
- - f471dbc chore: version bump - (*Thomas David*)
7
- - 095e35c fix: aggregate filter single meta item - (*Thomas David*)
8
-
9
- ## Metadata
10
- ```
11
- This version -------- v0.6.7
12
- Previous version ---- v0.6.6
13
- Total commits ------- 4
14
- ```
15
- # 🎁 Release notes (`v0.6.6`)
16
-
17
- ## Changes
18
- - 790c585 (HEAD -> main, tag: v0.6.6, origin/main) fix: computedSlots token param includes attrib values - (*Thomas David*)
19
- - 505d4f0 feat: export parseHTML util - (*Thomas David*)
20
- - d0fc52d docs: update CoraliteModuleValues type - (*Thomas David*)
21
- - 6ad27ce feat: tokens parse HTML - (*Thomas David*)
22
- - 9497c25 feat: export current document to template context - (*Thomas David*)
23
- - df9a1a5 refactor: create reusable parseHTML function - (*Thomas David*)
24
- - ebb388c feat: append rendered token to custom element slots - (*Thomas David*)
25
- - 1f6ffd0 feat: add filtering to aggregate function - (*Thomas David*)
26
-
27
- ## Metadata
28
- ```
29
- This version -------- v0.6.6
30
- Previous version ---- v0.6.5
31
- Total commits ------- 8
32
- ```
33
- # 🎁 Release notes (`v0.6.5`)
34
-
35
- ## Changes
36
- - 4610baa (HEAD -> main, tag: v0.6.5, origin/main) chore: version bump - (*Thomas David*)
37
- - be2511d ci: remove windows due to unavailability - (*Thomas David*)
38
- - 821f212 test: cover aggregate filter option - (*Thomas David*)
39
- - 48eaa76 docs: add CoraliteAggregate to aggregate param - (*Thomas David*)
40
- - 39ab5ba docs: add CoraliteAggregate typedef - (*Thomas David*)
41
- - 148dee9 feat: add filter to aggregate function - (*Thomas David*)
42
- - 15cf0fd docs: add CoraliteAggregate typedef - (*Thomas David*)
43
- - dbb5b8f feat: remove unused parseHTMLMeta ignoreByAttribute param - (*Thomas David*)
44
-
45
- ## Metadata
46
- ```
47
- This version -------- v0.6.5
48
- Previous version ---- v0.6.4
49
- Total commits ------- 8
50
- ```
51
- # 🎁 Release notes (`v0.6.4`)
52
-
53
- ## Changes
54
- - 41771d5 (HEAD -> main, tag: v0.6.4, origin/main) chore: version bump - (*Thomas David*)
55
- - ea2ef46 test: cover values param - (*Thomas David*)
56
- - 60e70d3 feat: add props argument to tokens and slots functions - (*Thomas David*)
57
- - 1ed074a chore: version bump - (*Thomas David*)
58
- - 9d710c0 ci: fix publish needs ref - (*Thomas David*)
59
-
60
- ## Metadata
61
- ```
62
- This version -------- v0.6.4
63
- Previous version ---- v0.6.3
64
- Total commits ------- 5
65
- ```
66
-
67
- # 🎁 Release notes (`v0.6.3`)
68
-
69
- ## Changes
70
- - 6fe640d (HEAD -> main, tag: v0.6.3, origin/main) test: cover ignore by attribute - (*[Thomas David](https://github.com/tjdav)*)
71
- - a47ff8f types: add IgnoreByAttribute type - (*[Thomas David](https://github.com/tjdav)*)
72
- - 8547c37 feat: ignore element by attributes inside meta and component parsers - (*[Thomas David](https://github.com/tjdav)*)
73
- - f61ae88 docs: update ignore-attribute example with quotes - (*[Thomas David](https://github.com/tjdav)*)
74
- - d4a277d docs: create consistent path names in example - (*[Thomas David](https://github.com/tjdav)*)
75
- - 566463f docs: remove requirements section - (*[Thomas David](https://github.com/tjdav)*)
76
- - 2493ab3 style: import type new line - (*[Thomas David](https://github.com/tjdav)*)
77
- - 2e44174 ci: test before publish - (*[Thomas David](https://github.com/tjdav)*)
78
- - c1d5ce7 fix: add template id to script module error - (*[Thomas David](https://github.com/tjdav)*)
79
- - 4fabac1 ci: include self to test script - (*[Thomas David](https://github.com/tjdav)*)
80
- - efd34d0 fix: add --experimental-vm-modules to shebang - (*[Thomas David](https://github.com/tjdav)*)
81
- - 7da5d98 refactor: add type check before splicing children. - (*[Thomas David](https://github.com/tjdav)*)
82
- - 2e39027 fix: catch bad options for aggregate function - (*[Thomas David](https://github.com/tjdav)*)
83
-
84
- ## Metadata
85
- ```
86
- This version -------- v0.6.3
87
- Previous version ---- v0.6.2
88
- Total commits ------- 13
89
- ```
90
- # 🎁 Release notes (`v0.6.2`)
91
-
92
- ## Changes
93
- - be6c54c (HEAD -> main, tag: v0.6.2, origin/main) fix: update lock - (*[Thomas David](https://github.com/tjdav)*)
94
- - 15d9b4e chore: version bump - (*[Thomas David](https://github.com/tjdav)*)
95
- - fac695e fix: node v18 requires globalThis reference for crypto - (*[Thomas David](https://github.com/tjdav)*)
96
- - d7c551e doc: format doc links - (*[Thomas David](https://github.com/tjdav)*)
97
-
98
- ## Metadata
99
- ```
100
- This version -------- v0.6.2
101
- Previous version ---- v0.6.1
102
- Total commits ------- 4
103
- ```
104
- # 🎁 Release notes (`v0.6.1`)
105
-
106
- ## Changes
107
- - bcc1637 (HEAD -> main, tag: v0.6.1, origin/main) chore: version bump - (*[Thomas David](https://github.com/tjdav)*)
108
- - 95cfdba docs: add doc links - (*[Thomas David](https://github.com/tjdav)*)
109
- - 101a305 fix: render computedSlot nodes - (*[Thomas David](https://github.com/tjdav)*)
110
- - 11a35d8 feat: dynamically import modules - (*[Thomas David](https://github.com/tjdav)*)
111
- - e1364b9 docs: add CoraliteResult type - (*[Thomas David](https://github.com/tjdav)*)
112
- - 11c6405 docs: add @example to coralite - (*[Thomas David](https://github.com/tjdav)*)
113
- - a050263 docs: basic technical documentation - (*[Thomas David](https://github.com/tjdav)*)
114
- - 83fdddd docs: update dry run option - (*[Thomas David](https://github.com/tjdav)*)
115
-
116
- ## Metadata
117
- ```
118
- This version -------- v0.6.1
119
- Previous version ---- v0.6.0
120
- Total commits ------- 8
121
- ```
122
- # 🎁 Release notes (`v0.6.0`)
123
-
124
- ## Changes
125
- - 22d75e2 (HEAD -> main, tag: v0.6.0, origin/main) chore: version bump - (*[Thomas David](https://github.com/tjdav)*)
126
- - c5cc7cc lint: ignore playwright-report - (*[Thomas David](https://github.com/tjdav)*)
127
- - fdb3697 docs: add dry run option - (*[Thomas David](https://github.com/tjdav)*)
128
- - 891db2e feat: export coralite utils - (*[Thomas David](https://github.com/tjdav)*)
129
- - 9265681 test: cover ignore attribute - (*[Thomas David](https://github.com/tjdav)*)
130
- - 5d44661 fix: allow missing component to compile - (*[Thomas David](https://github.com/tjdav)*)
131
- - f3d6e65 docs: add remove prop to CoraliteElement - (*[Thomas David](https://github.com/tjdav)*)
132
- - 229fef5 feat: new option to ignore element by attribute name value pair - (*[Thomas David](https://github.com/tjdav)*)
133
- - c78dde1 chore: include kleur dep - (*[Thomas David](https://github.com/tjdav)*)
134
- - b10bbe8 feat: update cli to use coralite module - (*[Thomas David](https://github.com/tjdav)*)
135
- - 48fe816 docs: make defineComponent param tokens and slots optional - (*[Thomas David](https://github.com/tjdav)*)
136
- - 02a5e8f feat: move coralite to a module - (*[Thomas David](https://github.com/tjdav)*)
137
- - d336090 feat: get package.json util function - (*[Thomas David](https://github.com/tjdav)*)
138
- - e210844 feat: add document used in error message - (*[Thomas David](https://github.com/tjdav)*)
139
- - 1556a3b chore: version bump - (*[Thomas David](https://github.com/tjdav)*)
140
-
141
- ## Metadata
142
- ```
143
- This version -------- v0.6.0
144
- Previous version ---- v0.5.1
145
- Total commits ------- 15
146
- ```