coralite-plugin-aggregation 0.1.0 → 0.2.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.
- package/README.md +2 -2
- package/changelog.md +40 -8
- package/package.json +4 -4
- package/src/index.js +79 -94
- package/src/templates/coralite-pagination.html +2 -1
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ Create a file like `coralite-posts.html` to define your aggregation logic and re
|
|
|
58
58
|
</template>
|
|
59
59
|
|
|
60
60
|
<script type="module">
|
|
61
|
-
import { defineComponent, aggregation } from 'coralite'
|
|
61
|
+
import { defineComponent, aggregation } from 'coralite/plugins'
|
|
62
62
|
|
|
63
63
|
export default defineComponent({
|
|
64
64
|
tokens: {
|
|
@@ -133,7 +133,7 @@ Define a `<template>` element for rendering individual items:
|
|
|
133
133
|
</template>
|
|
134
134
|
|
|
135
135
|
<script type="module">
|
|
136
|
-
import { defineComponent } from 'coralite'
|
|
136
|
+
import { defineComponent } from 'coralite/plugins'
|
|
137
137
|
|
|
138
138
|
export default defineComponent({
|
|
139
139
|
tokens: {
|
package/changelog.md
CHANGED
|
@@ -1,10 +1,42 @@
|
|
|
1
1
|
# 🎁 Complete Release History
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Release: `v0.1.2`
|
|
4
|
+
|
|
5
|
+
### Changes from `v0.1.0` to `v0.1.2`
|
|
6
|
+
|
|
7
|
+
- cb7205a (HEAD -> main, tag: v0.1.2) chore: version bump - ([Thomas David](https://codeberg.org/tjdavid))
|
|
8
|
+
- 042b730 (origin/main) fix: rename meta to values in sort function - ([Thomas David](https://codeberg.org/tjdavid))
|
|
9
|
+
- b4dc56a refactor: remove unused parsePagination function - ([Thomas David](https://codeberg.org/tjdavid))
|
|
10
|
+
- c61a727 (tag: v0.1.1) 0.1.1 - ([Thomas David](https://codeberg.org/tjdavid))
|
|
11
|
+
- 3e0dcec feat: changelog script - ([Thomas David](https://codeberg.org/tjdavid))
|
|
12
|
+
|
|
13
|
+
### Metadata
|
|
14
|
+
```
|
|
15
|
+
This version -------- v0.1.2
|
|
16
|
+
Previous version ---- v0.1.0
|
|
17
|
+
Total commits ------- 5
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Release: `v0.1.0`
|
|
21
|
+
|
|
22
|
+
### Changes from `v0.1.1` to `v0.1.0`
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Metadata
|
|
26
|
+
```
|
|
27
|
+
This version -------- v0.1.0
|
|
28
|
+
Previous version ---- v0.1.1
|
|
29
|
+
Total commits ------- 0
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Initial Release: `v0.1.1`
|
|
4
33
|
|
|
5
34
|
### Initial Commits
|
|
6
35
|
|
|
7
|
-
-
|
|
36
|
+
- c61a727 (tag: v0.1.1) 0.1.1 - ([Thomas David](https://codeberg.org/tjdavid))
|
|
37
|
+
- 3e0dcec feat: changelog script - ([Thomas David](https://codeberg.org/tjdavid))
|
|
38
|
+
- edcda41 chore: add changelog - ([Thomas David](https://codeberg.org/tjdavid))
|
|
39
|
+
- 2b0f1dc (tag: v0.1.0) feat: Implement dynamic pagination with visible items and ellipsis - ([Thomas David](https://codeberg.org/tjdavid))
|
|
8
40
|
- 6b4d75f test: add fixtures to cover visibility feature - ([Thomas David](https://codeberg.org/tjdavid))
|
|
9
41
|
- 70f5a4b add npm ignore list - ([Thomas David](https://codeberg.org/tjdavid))
|
|
10
42
|
- 48cf1e0 docs: Add custom pager template user guide - ([Thomas David](https://codeberg.org/tjdavid))
|
|
@@ -19,7 +51,7 @@
|
|
|
19
51
|
- 74ba4a0 fix: simplify page limit handling by removing array check and using offset correctly - ([Thomas David](https://codeberg.org/tjdavid))
|
|
20
52
|
- 2cf82e6 refactor: Use tokens instead of values in component definitions - ([Thomas David](https://codeberg.org/tjdavid))
|
|
21
53
|
- b5fde9d fix: fix previous navigation link generation in pagination - ([Thomas David](https://codeberg.org/tjdavid))
|
|
22
|
-
Correctly adjust the
|
|
54
|
+
Correctly adjust the “Previous” link href based on current index to ensure proper
|
|
23
55
|
navigation when on pages beyond the second one. The fix updates the logic to
|
|
24
56
|
reference the correct page number for the previous item, resolving invalid
|
|
25
57
|
navigation links in multi-page scenarios.
|
|
@@ -31,7 +63,7 @@
|
|
|
31
63
|
- 4879d44 refactor: rename values to tokens in pagination_list - ([Thomas David](https://codeberg.org/tjdavid))
|
|
32
64
|
- 3b06c3c chore: upgrade coralite to 0.11.1 - ([Thomas David](https://codeberg.org/tjdavid))
|
|
33
65
|
- cfa07cb chore: update coralite to 0.10.0 - ([Thomas David](https://codeberg.org/tjdavid))
|
|
34
|
-
- 320f665 chore: add
|
|
66
|
+
- 320f665 chore: add “type”: “module” to package.json - ([Thomas David](https://codeberg.org/tjdavid))
|
|
35
67
|
- 0ad0f60 chore: update repository and issues URLs in package.json - ([Thomas David](https://codeberg.org/tjdavid))
|
|
36
68
|
- 679b3cf fix: use import.meta.dirname for template path - ([Thomas David](https://codeberg.org/tjdavid))
|
|
37
69
|
- 093b1ea fix: ensure context scope for new components - ([Thomas David](https://codeberg.org/tjdavid))
|
|
@@ -77,12 +109,12 @@
|
|
|
77
109
|
|
|
78
110
|
### Metadata
|
|
79
111
|
```
|
|
80
|
-
First version ------- v0.1.
|
|
81
|
-
Total commits -------
|
|
112
|
+
First version ------- v0.1.1
|
|
113
|
+
Total commits ------- 50
|
|
82
114
|
```
|
|
83
115
|
|
|
84
116
|
## Summary
|
|
85
117
|
```
|
|
86
|
-
Total releases ------
|
|
87
|
-
Total commits -------
|
|
118
|
+
Total releases ------ 3
|
|
119
|
+
Total commits ------- 55
|
|
88
120
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coralite-plugin-aggregation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Build database free coralite websites",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "coralite -t tests/fixtures/templates -p tests/fixtures/pages -o dist",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"license": "AGPL-3.0-only",
|
|
36
|
-
"packageManager": "pnpm@10.
|
|
36
|
+
"packageManager": "pnpm@10.13.1",
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@playwright/test": "^1.52.0",
|
|
39
39
|
"@stylistic/eslint-plugin-js": "^4.2.0",
|
|
40
40
|
"@stylistic/eslint-plugin-plus": "^4.2.0",
|
|
41
|
-
"coralite": "^0.
|
|
41
|
+
"coralite": "^0.12.0",
|
|
42
42
|
"sirv-cli": "^3.0.1"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
@@ -46,6 +46,6 @@
|
|
|
46
46
|
"htmlparser2": "^10.0.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"coralite": "^0.
|
|
49
|
+
"coralite": "^0.12.0"
|
|
50
50
|
}
|
|
51
51
|
}
|
package/src/index.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
2
|
import { existsSync } from 'node:fs'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
getHtmlFiles,
|
|
6
|
-
createElement,
|
|
7
|
-
createTextNode,
|
|
8
|
-
createPlugin,
|
|
9
|
-
} from 'coralite/utils'
|
|
3
|
+
import { getHtmlFiles, createPlugin, } from 'coralite/utils'
|
|
10
4
|
|
|
11
5
|
/**
|
|
12
6
|
* @import {CoraliteAnyNode, CoraliteCollectionItem, CoraliteContentNode, CoraliteDocumentRoot} from 'coralite/types'
|
|
@@ -79,11 +73,11 @@ export default createPlugin({
|
|
|
79
73
|
let endIndex = pages.length
|
|
80
74
|
let paginationOffset = context.values.pagination_offset
|
|
81
75
|
|
|
82
|
-
//
|
|
76
|
+
// sort results based on custom sort function
|
|
83
77
|
if (typeof options.sort === 'function') {
|
|
84
78
|
pages.sort((a, b) => {
|
|
85
|
-
const metaA = a.result.
|
|
86
|
-
const metaB = b.result.
|
|
79
|
+
const metaA = a.result.values
|
|
80
|
+
const metaB = b.result.values
|
|
87
81
|
|
|
88
82
|
return options.sort(metaA, metaB)
|
|
89
83
|
})
|
|
@@ -97,7 +91,7 @@ export default createPlugin({
|
|
|
97
91
|
const metadata = page.result.values
|
|
98
92
|
let keepItem = false
|
|
99
93
|
|
|
100
|
-
//
|
|
94
|
+
// process metadata and populate token values for rendering
|
|
101
95
|
for (const key in metadata) {
|
|
102
96
|
if (Object.prototype.hasOwnProperty.call(metadata, key)) {
|
|
103
97
|
const data = metadata[key]
|
|
@@ -110,7 +104,7 @@ export default createPlugin({
|
|
|
110
104
|
}
|
|
111
105
|
}
|
|
112
106
|
} else {
|
|
113
|
-
//
|
|
107
|
+
// handle single metadata item
|
|
114
108
|
if (!keepItem) {
|
|
115
109
|
keepItem = options.filter({
|
|
116
110
|
name: key,
|
|
@@ -130,7 +124,7 @@ export default createPlugin({
|
|
|
130
124
|
endIndex = pages.length
|
|
131
125
|
}
|
|
132
126
|
|
|
133
|
-
//
|
|
127
|
+
// apply page offset
|
|
134
128
|
if (Object.prototype.hasOwnProperty.call(options, 'offset') || paginationOffset != null) {
|
|
135
129
|
let offset = paginationOffset || options.offset
|
|
136
130
|
|
|
@@ -192,6 +186,7 @@ export default createPlugin({
|
|
|
192
186
|
}
|
|
193
187
|
}
|
|
194
188
|
|
|
189
|
+
// process pagination
|
|
195
190
|
if (options.pagination) {
|
|
196
191
|
const pagination = options.pagination
|
|
197
192
|
const paginationPath = context.values.pagination_path || pagination.path || 'page'
|
|
@@ -239,7 +234,7 @@ export default createPlugin({
|
|
|
239
234
|
}
|
|
240
235
|
|
|
241
236
|
// add pagination page to render queue
|
|
242
|
-
this.addRenderQueue({
|
|
237
|
+
await this.addRenderQueue({
|
|
243
238
|
values: {
|
|
244
239
|
pagination_pager_dirname: path.dirname,
|
|
245
240
|
pagination_pager_index: pageIndex,
|
|
@@ -280,94 +275,84 @@ export default createPlugin({
|
|
|
280
275
|
values = context.values
|
|
281
276
|
this.values[contextId] = values
|
|
282
277
|
}
|
|
283
|
-
|
|
278
|
+
|
|
284
279
|
const templateId = pagination.template || 'coralite-pagination'
|
|
285
280
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
281
|
+
if (typeof templateId === 'string') {
|
|
282
|
+
const component = await this.createComponent({
|
|
283
|
+
id: templateId,
|
|
284
|
+
values,
|
|
285
|
+
document: context.document,
|
|
286
|
+
contextId: contextId + templateId
|
|
287
|
+
})
|
|
292
288
|
|
|
293
|
-
|
|
294
|
-
|
|
289
|
+
if (typeof component === 'object') {
|
|
290
|
+
result = result.concat(component.children)
|
|
291
|
+
}
|
|
295
292
|
}
|
|
296
293
|
}
|
|
297
294
|
|
|
298
295
|
return result
|
|
299
296
|
},
|
|
300
|
-
|
|
301
|
-
|
|
297
|
+
async onPageCreate ({ elements, values, data }) {
|
|
298
|
+
// loop through all children of the root element to process metadata in <head> tags.
|
|
299
|
+
for (let i = 0; i < elements.root.children.length; i++) {
|
|
300
|
+
const rootNode = elements.root.children[i]
|
|
301
|
+
|
|
302
|
+
// traverse html children to find the head element
|
|
303
|
+
if (rootNode.type === 'tag' && rootNode.name === 'html') {
|
|
304
|
+
for (let i = 0; i < rootNode.children.length; i++) {
|
|
305
|
+
const node = rootNode.children[i];
|
|
306
|
+
|
|
307
|
+
// check if the current node is a <head> tag where metadata is typically found.
|
|
308
|
+
if (node.type === 'tag' && node.name === 'head') {
|
|
309
|
+
// iterate over the children of the head element to locate meta tags or component slots.
|
|
310
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
311
|
+
const element = node.children[i]
|
|
312
|
+
|
|
313
|
+
// if the element is a tag named "meta" with both name and content attributes, store its metadata.
|
|
314
|
+
if (element.type === 'tag') {
|
|
315
|
+
if (element.name === 'meta'
|
|
316
|
+
&& element.attribs.name
|
|
317
|
+
&& element.attribs.content
|
|
318
|
+
) {
|
|
319
|
+
values['$' + element.attribs.name] = element.attribs.content
|
|
320
|
+
} else if (element.slots) {
|
|
321
|
+
// process component slots by creating a component dynamically.
|
|
322
|
+
const component = await this.createComponent({
|
|
323
|
+
id: element.name,
|
|
324
|
+
values,
|
|
325
|
+
element,
|
|
326
|
+
document: data.result,
|
|
327
|
+
contextId: data.path.pathname + i + element.name
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
// if the created component returns valid children, iterate over them to extract meta information.
|
|
331
|
+
if (component) {
|
|
332
|
+
for (let i = 0; i < component.children.length; i++) {
|
|
333
|
+
const element = component.children[i];
|
|
334
|
+
|
|
335
|
+
// for each child element in the component's returned HTML,
|
|
336
|
+
// check if it is a meta tag and store its metadata with a '$' prefix.
|
|
337
|
+
if (element.type === 'tag'
|
|
338
|
+
&& element.name === 'meta'
|
|
339
|
+
&& element.attribs.name
|
|
340
|
+
&& element.attribs.content
|
|
341
|
+
) {
|
|
342
|
+
values['$' + element.attribs.name] = element.attribs.content
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
302
349
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
* @param {Object} pagination - Configuration object for pagination templates
|
|
308
|
-
* @param {string} pagination.template - The template tag name used to identify pagination elements
|
|
309
|
-
* @param {Object.<string, string>} pagination.attributes - Additional attributes to merge into the template element
|
|
310
|
-
* @example parsePagination('<pagination-element></pagination-element>', {
|
|
311
|
-
* template: 'pagination-element',
|
|
312
|
-
* attributes: { class: 'custom-pagination' }
|
|
313
|
-
* })
|
|
314
|
-
*/
|
|
315
|
-
export function parsePagination (string, meta) {
|
|
316
|
-
// root element reference
|
|
317
|
-
/** @type {CoraliteDocumentRoot} */
|
|
318
|
-
const root = {
|
|
319
|
-
type: 'root',
|
|
320
|
-
children: []
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// stack to keep track of current element hierarchy
|
|
324
|
-
/** @type {CoraliteContentNode[]} */
|
|
325
|
-
const stack = [root]
|
|
326
|
-
const parser = new Parser({
|
|
327
|
-
onprocessinginstruction (name, data) {
|
|
328
|
-
root.children.push({
|
|
329
|
-
type: 'directive',
|
|
330
|
-
name,
|
|
331
|
-
data
|
|
332
|
-
})
|
|
333
|
-
},
|
|
334
|
-
onopentag (originalName, attributes) {
|
|
335
|
-
const parent = stack[stack.length - 1]
|
|
336
|
-
const element = createElement({
|
|
337
|
-
name: originalName,
|
|
338
|
-
attributes,
|
|
339
|
-
parent
|
|
340
|
-
})
|
|
341
|
-
// push element to stack as it may have children
|
|
342
|
-
stack.push(element)
|
|
343
|
-
},
|
|
344
|
-
ontext (text) {
|
|
345
|
-
const parent = stack[stack.length - 1]
|
|
346
|
-
|
|
347
|
-
createTextNode(text, parent)
|
|
348
|
-
},
|
|
349
|
-
onclosetag () {
|
|
350
|
-
const parent = stack[stack.length - 1]
|
|
351
|
-
|
|
352
|
-
if (parent.type === 'tag' && parent.name === 'head') {
|
|
353
|
-
|
|
350
|
+
// once the <head> tag is processed, return to exit the loop.
|
|
351
|
+
return
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
354
|
}
|
|
355
|
-
// remove current element from stack as we're done with its children
|
|
356
|
-
stack.pop()
|
|
357
|
-
},
|
|
358
|
-
oncomment (data) {
|
|
359
|
-
const parent = stack[stack.length - 1]
|
|
360
|
-
|
|
361
|
-
parent.children.push({
|
|
362
|
-
type: 'comment',
|
|
363
|
-
data,
|
|
364
|
-
parent
|
|
365
|
-
})
|
|
366
355
|
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
parser.end()
|
|
371
|
-
|
|
372
|
-
return root
|
|
373
|
-
}
|
|
356
|
+
},
|
|
357
|
+
templates: [join(import.meta.dirname, 'templates/coralite-pagination.html')]
|
|
358
|
+
})
|