coralite 0.6.7 → 0.6.8
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 +167 -0
- package/lib/html-module.js +27 -5
- package/lib/parse.js +124 -104
- package/package.json +1 -1
- package/scripts/{change-log.sh → changelog.sh} +1 -1
- package/types/index.js +9 -0
- package/change-logs.md +0 -146
package/changelog.md
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# 🎁 Release notes (`v0.6.8`)
|
|
2
|
+
|
|
3
|
+
## Changes
|
|
4
|
+
- 3b8fe8c (tag: v0.6.8, origin/main) test: use parseHTML - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
5
|
+
- f7d6ab9 test: add meta prefix to tokens - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
6
|
+
- 34c15d2 test: remove unused variables - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
7
|
+
- b39ac47 test: cover nested components - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
8
|
+
- 81c3da4 feat: computed slots parse strings - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
9
|
+
- 585b7d6 fix: remove slot attribute - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
10
|
+
- 00f68ef fix: process computed tokens before replacing values - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
11
|
+
- b13a016 feat: add identifier to SourceTextModule - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
12
|
+
- 6257a0f feat: aggregate add meta value namespace - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
13
|
+
- 469d5fe feat: aggregate handle page sort - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
14
|
+
- bd23fbe feat: aggregate handle page limit - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
15
|
+
|
|
16
|
+
## Metadata
|
|
17
|
+
```
|
|
18
|
+
This version -------- v0.6.8
|
|
19
|
+
Previous version ---- v0.6.7
|
|
20
|
+
Total commits ------- 11
|
|
21
|
+
```
|
|
22
|
+
# 🎁 Release notes (`v0.6.7`)
|
|
23
|
+
|
|
24
|
+
## Changes
|
|
25
|
+
- 7138a0b (HEAD -> main, tag: v0.6.7, origin/main) update repo url - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
26
|
+
- 41988a4 license change - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
27
|
+
- f471dbc chore: version bump - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
28
|
+
- 095e35c fix: aggregate filter single meta item - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
29
|
+
|
|
30
|
+
## Metadata
|
|
31
|
+
```
|
|
32
|
+
This version -------- v0.6.7
|
|
33
|
+
Previous version ---- v0.6.6
|
|
34
|
+
Total commits ------- 4
|
|
35
|
+
```
|
|
36
|
+
# 🎁 Release notes (`v0.6.6`)
|
|
37
|
+
|
|
38
|
+
## Changes
|
|
39
|
+
- 790c585 (HEAD -> main, tag: v0.6.6, origin/main) fix: computedSlots token param includes attrib values - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
40
|
+
- 505d4f0 feat: export parseHTML util - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
41
|
+
- d0fc52d docs: update CoraliteModuleValues type - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
42
|
+
- 6ad27ce feat: tokens parse HTML - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
43
|
+
- 9497c25 feat: export current document to template context - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
44
|
+
- df9a1a5 refactor: create reusable parseHTML function - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
45
|
+
- ebb388c feat: append rendered token to custom element slots - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
46
|
+
- 1f6ffd0 feat: add filtering to aggregate function - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
47
|
+
|
|
48
|
+
## Metadata
|
|
49
|
+
```
|
|
50
|
+
This version -------- v0.6.6
|
|
51
|
+
Previous version ---- v0.6.5
|
|
52
|
+
Total commits ------- 8
|
|
53
|
+
```
|
|
54
|
+
# 🎁 Release notes (`v0.6.5`)
|
|
55
|
+
|
|
56
|
+
## Changes
|
|
57
|
+
- 4610baa (HEAD -> main, tag: v0.6.5, origin/main) chore: version bump - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
58
|
+
- be2511d ci: remove windows due to unavailability - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
59
|
+
- 821f212 test: cover aggregate filter option - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
60
|
+
- 48eaa76 docs: add CoraliteAggregate to aggregate param - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
61
|
+
- 39ab5ba docs: add CoraliteAggregate typedef - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
62
|
+
- 148dee9 feat: add filter to aggregate function - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
63
|
+
- 15cf0fd docs: add CoraliteAggregate typedef - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
64
|
+
- dbb5b8f feat: remove unused parseHTMLMeta ignoreByAttribute param - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
65
|
+
|
|
66
|
+
## Metadata
|
|
67
|
+
```
|
|
68
|
+
This version -------- v0.6.5
|
|
69
|
+
Previous version ---- v0.6.4
|
|
70
|
+
Total commits ------- 8
|
|
71
|
+
```
|
|
72
|
+
# 🎁 Release notes (`v0.6.4`)
|
|
73
|
+
|
|
74
|
+
## Changes
|
|
75
|
+
- 41771d5 (HEAD -> main, tag: v0.6.4, origin/main) chore: version bump - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
76
|
+
- ea2ef46 test: cover values param - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
77
|
+
- 60e70d3 feat: add props argument to tokens and slots functions - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
78
|
+
- 1ed074a chore: version bump - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
79
|
+
- 9d710c0 ci: fix publish needs ref - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
80
|
+
|
|
81
|
+
## Metadata
|
|
82
|
+
```
|
|
83
|
+
This version -------- v0.6.4
|
|
84
|
+
Previous version ---- v0.6.3
|
|
85
|
+
Total commits ------- 5
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
# 🎁 Release notes (`v0.6.3`)
|
|
89
|
+
|
|
90
|
+
## Changes
|
|
91
|
+
- 6fe640d (HEAD -> main, tag: v0.6.3, origin/main) test: cover ignore by attribute - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
92
|
+
- a47ff8f types: add IgnoreByAttribute type - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
93
|
+
- 8547c37 feat: ignore element by attributes inside meta and component parsers - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
94
|
+
- f61ae88 docs: update ignore-attribute example with quotes - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
95
|
+
- d4a277d docs: create consistent path names in example - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
96
|
+
- 566463f docs: remove requirements section - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
97
|
+
- 2493ab3 style: import type new line - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
98
|
+
- 2e44174 ci: test before publish - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
99
|
+
- c1d5ce7 fix: add template id to script module error - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
100
|
+
- 4fabac1 ci: include self to test script - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
101
|
+
- efd34d0 fix: add --experimental-vm-modules to shebang - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
102
|
+
- 7da5d98 refactor: add type check before splicing children. - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
103
|
+
- 2e39027 fix: catch bad options for aggregate function - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
104
|
+
|
|
105
|
+
## Metadata
|
|
106
|
+
```
|
|
107
|
+
This version -------- v0.6.3
|
|
108
|
+
Previous version ---- v0.6.2
|
|
109
|
+
Total commits ------- 13
|
|
110
|
+
```
|
|
111
|
+
# 🎁 Release notes (`v0.6.2`)
|
|
112
|
+
|
|
113
|
+
## Changes
|
|
114
|
+
- be6c54c (HEAD -> main, tag: v0.6.2, origin/main) fix: update lock - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
115
|
+
- 15d9b4e chore: version bump - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
116
|
+
- fac695e fix: node v18 requires globalThis reference for crypto - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
117
|
+
- d7c551e doc: format doc links - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
118
|
+
|
|
119
|
+
## Metadata
|
|
120
|
+
```
|
|
121
|
+
This version -------- v0.6.2
|
|
122
|
+
Previous version ---- v0.6.1
|
|
123
|
+
Total commits ------- 4
|
|
124
|
+
```
|
|
125
|
+
# 🎁 Release notes (`v0.6.1`)
|
|
126
|
+
|
|
127
|
+
## Changes
|
|
128
|
+
- bcc1637 (HEAD -> main, tag: v0.6.1, origin/main) chore: version bump - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
129
|
+
- 95cfdba docs: add doc links - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
130
|
+
- 101a305 fix: render computedSlot nodes - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
131
|
+
- 11a35d8 feat: dynamically import modules - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
132
|
+
- e1364b9 docs: add CoraliteResult type - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
133
|
+
- 11c6405 docs: add @example to coralite - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
134
|
+
- a050263 docs: basic technical documentation - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
135
|
+
- 83fdddd docs: update dry run option - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
136
|
+
|
|
137
|
+
## Metadata
|
|
138
|
+
```
|
|
139
|
+
This version -------- v0.6.1
|
|
140
|
+
Previous version ---- v0.6.0
|
|
141
|
+
Total commits ------- 8
|
|
142
|
+
```
|
|
143
|
+
# 🎁 Release notes (`v0.6.0`)
|
|
144
|
+
|
|
145
|
+
## Changes
|
|
146
|
+
- 22d75e2 (HEAD -> main, tag: v0.6.0, origin/main) chore: version bump - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
147
|
+
- c5cc7cc lint: ignore playwright-report - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
148
|
+
- fdb3697 docs: add dry run option - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
149
|
+
- 891db2e feat: export coralite utils - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
150
|
+
- 9265681 test: cover ignore attribute - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
151
|
+
- 5d44661 fix: allow missing component to compile - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
152
|
+
- f3d6e65 docs: add remove prop to CoraliteElement - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
153
|
+
- 229fef5 feat: new option to ignore element by attribute name value pair - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
154
|
+
- c78dde1 chore: include kleur dep - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
155
|
+
- b10bbe8 feat: update cli to use coralite module - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
156
|
+
- 48fe816 docs: make defineComponent param tokens and slots optional - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
157
|
+
- 02a5e8f feat: move coralite to a module - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
158
|
+
- d336090 feat: get package.json util function - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
159
|
+
- e210844 feat: add document used in error message - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
160
|
+
- 1556a3b chore: version bump - (*[Thomas David](https://codeberg.org/tjdavid)*)
|
|
161
|
+
|
|
162
|
+
## Metadata
|
|
163
|
+
```
|
|
164
|
+
This version -------- v0.6.0
|
|
165
|
+
Previous version ---- v0.5.1
|
|
166
|
+
Total commits ------- 15
|
|
167
|
+
```
|
package/lib/html-module.js
CHANGED
|
@@ -59,11 +59,26 @@ 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
|
|
62
64
|
|
|
63
|
-
|
|
65
|
+
if (options.limit && options.limit < pages.length) {
|
|
66
|
+
endIndex = options.limit
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (options.offset) {
|
|
70
|
+
if (options.offset > endIndex) {
|
|
71
|
+
startIndex = endIndex - 1
|
|
72
|
+
} else {
|
|
73
|
+
startIndex = options.offset
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
for (let i = startIndex; i < endIndex; i++) {
|
|
64
78
|
const page = pages[i]
|
|
65
79
|
const meta = parseHTMLMeta(page.content)
|
|
66
80
|
const pageValues = Object.assign({}, values)
|
|
81
|
+
let prefix = 'meta_'
|
|
67
82
|
let isFilter = !!options.filter
|
|
68
83
|
let ignorePage = false
|
|
69
84
|
|
|
@@ -72,10 +87,12 @@ export async function aggregate (options, values, components, document) {
|
|
|
72
87
|
const data = meta[key]
|
|
73
88
|
const content = []
|
|
74
89
|
const firstItem = data[0]
|
|
90
|
+
const firstItemName = prefix + firstItem.name
|
|
75
91
|
|
|
76
92
|
if (data.length > 1) {
|
|
77
93
|
for (let i = 0; i < data.length; i++) {
|
|
78
94
|
const item = data[i]
|
|
95
|
+
let name = prefix + item.name
|
|
79
96
|
let suffix = ''
|
|
80
97
|
|
|
81
98
|
if (isFilter && !ignorePage) {
|
|
@@ -84,21 +101,21 @@ export async function aggregate (options, values, components, document) {
|
|
|
84
101
|
suffix = '_' + i
|
|
85
102
|
|
|
86
103
|
if (i === 0) {
|
|
87
|
-
pageValues[
|
|
104
|
+
pageValues[name] = item.content
|
|
88
105
|
}
|
|
89
106
|
|
|
90
|
-
pageValues[
|
|
107
|
+
pageValues[name + suffix] = item.content
|
|
91
108
|
|
|
92
109
|
content.push(item.content)
|
|
93
110
|
}
|
|
94
111
|
|
|
95
|
-
pageValues[
|
|
112
|
+
pageValues[firstItemName + '_list'] = content
|
|
96
113
|
} else {
|
|
97
114
|
if (isFilter && !ignorePage) {
|
|
98
115
|
ignorePage = options.filter(firstItem)
|
|
99
116
|
}
|
|
100
117
|
|
|
101
|
-
pageValues[
|
|
118
|
+
pageValues[firstItemName] = firstItem.content
|
|
102
119
|
}
|
|
103
120
|
}
|
|
104
121
|
}
|
|
@@ -121,5 +138,10 @@ export async function aggregate (options, values, components, document) {
|
|
|
121
138
|
}
|
|
122
139
|
}
|
|
123
140
|
|
|
141
|
+
// sort results
|
|
142
|
+
if (typeof options.sort === 'function') {
|
|
143
|
+
result.sort(options.sort)
|
|
144
|
+
}
|
|
145
|
+
|
|
124
146
|
return result
|
|
125
147
|
}
|
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
|
-
|
|
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
|
-
|
|
505
|
-
|
|
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
|
-
|
|
521
|
-
|
|
522
|
-
|
|
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
|
-
|
|
536
|
-
|
|
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
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
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
|
|
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
|
}
|
|
@@ -809,6 +753,11 @@ export async function parseScript ({
|
|
|
809
753
|
for (let i = 0; i < element.slots.length; i++) {
|
|
810
754
|
const slot = element.slots[i]
|
|
811
755
|
|
|
756
|
+
// exclude empty strings
|
|
757
|
+
if (slot.node.type === 'text' && !slot.node.data.trim()) {
|
|
758
|
+
continue
|
|
759
|
+
}
|
|
760
|
+
|
|
812
761
|
if (slot.name === name) {
|
|
813
762
|
// slot content to compute
|
|
814
763
|
slotContent.push(slot.node)
|
|
@@ -821,13 +770,22 @@ export async function parseScript ({
|
|
|
821
770
|
const result = computedSlot(slotContent, tokens) || slotContent
|
|
822
771
|
|
|
823
772
|
// append new slot nodes
|
|
824
|
-
|
|
825
|
-
const node = result[index]
|
|
826
|
-
|
|
773
|
+
if (typeof result === 'string') {
|
|
827
774
|
elementSlots.push({
|
|
828
775
|
name,
|
|
829
|
-
node
|
|
776
|
+
node: {
|
|
777
|
+
type: 'text',
|
|
778
|
+
data: result
|
|
779
|
+
}
|
|
830
780
|
})
|
|
781
|
+
} else if (Array.isArray(result)) {
|
|
782
|
+
for (let index = 0; index < result.length; index++) {
|
|
783
|
+
/** @TODO create a node checker to verify */
|
|
784
|
+
elementSlots.push({
|
|
785
|
+
name,
|
|
786
|
+
node: result[index]
|
|
787
|
+
})
|
|
788
|
+
}
|
|
831
789
|
}
|
|
832
790
|
|
|
833
791
|
// update element slots
|
|
@@ -870,6 +828,7 @@ export async function parseScript ({
|
|
|
870
828
|
})
|
|
871
829
|
|
|
872
830
|
const script = new vm.SourceTextModule(component.script, {
|
|
831
|
+
identifier: join(document.parentPath, document.name + '.js'),
|
|
873
832
|
context: contextifiedObject
|
|
874
833
|
})
|
|
875
834
|
|
|
@@ -1058,3 +1017,64 @@ function findAttributesToIgnore (ignore, attributes) {
|
|
|
1058
1017
|
|
|
1059
1018
|
return false
|
|
1060
1019
|
}
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* Replaces a token in a Coralite node based on its type, attribute, and content.
|
|
1023
|
+
*
|
|
1024
|
+
* @param {Object} token - The token to replace.
|
|
1025
|
+
* @param {string} token.type - The type of the token ('attribute' or 'text').
|
|
1026
|
+
* @param {CoraliteElement|CoraliteTextNode} token.node - The node containing the token.
|
|
1027
|
+
* @param {string} token.attribute - The attribute name to replace within the node.
|
|
1028
|
+
* @param {string} token.content - The content of the token.
|
|
1029
|
+
* @param {string|CoraliteDirective|CoraliteAnyNode} token.value - The value associated with the token.
|
|
1030
|
+
*/
|
|
1031
|
+
function replaceToken ({
|
|
1032
|
+
type,
|
|
1033
|
+
node,
|
|
1034
|
+
attribute,
|
|
1035
|
+
content,
|
|
1036
|
+
value
|
|
1037
|
+
}) {
|
|
1038
|
+
if (
|
|
1039
|
+
type === 'attribute'
|
|
1040
|
+
&& node.type === 'tag'
|
|
1041
|
+
&& typeof value === 'string'
|
|
1042
|
+
) {
|
|
1043
|
+
node.attribs[attribute] = node.attribs[attribute].replace(content, value)
|
|
1044
|
+
} else if (node.type === 'text') {
|
|
1045
|
+
if (Array.isArray(value)) {
|
|
1046
|
+
// inject nodes
|
|
1047
|
+
const textSplit = node.data.split(content)
|
|
1048
|
+
const childIndex = node.parent.children.indexOf(node)
|
|
1049
|
+
const children = []
|
|
1050
|
+
|
|
1051
|
+
// append computed tokens in between token split
|
|
1052
|
+
for (let i = 0; i < value.length; i++) {
|
|
1053
|
+
const child = value[i]
|
|
1054
|
+
|
|
1055
|
+
if (typeof child !== 'string') {
|
|
1056
|
+
// update child parent
|
|
1057
|
+
child.parent = node.parent
|
|
1058
|
+
children.push(child)
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
// replace computed token
|
|
1063
|
+
node.parent.children.splice(childIndex, 1,
|
|
1064
|
+
{
|
|
1065
|
+
type: 'text',
|
|
1066
|
+
data: textSplit[0],
|
|
1067
|
+
parent: node.parent
|
|
1068
|
+
},
|
|
1069
|
+
...children,
|
|
1070
|
+
{
|
|
1071
|
+
type: 'text',
|
|
1072
|
+
data: textSplit[1],
|
|
1073
|
+
parent: node.parent
|
|
1074
|
+
})
|
|
1075
|
+
} else {
|
|
1076
|
+
// replace token string
|
|
1077
|
+
node.data = node.data.replace(content, value)
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
}
|
package/package.json
CHANGED
|
@@ -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" >
|
|
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
|
-
```
|