coralite-plugin-aggregation 0.7.1 → 0.7.2
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/lib/index.js +11 -14
- package/package.json +7 -7
package/lib/index.js
CHANGED
|
@@ -23,7 +23,7 @@ async function aggregationMethod (options, contextInstance) {
|
|
|
23
23
|
const contextValues = contextInstance.values
|
|
24
24
|
const pagesRoot = this.options.pages
|
|
25
25
|
|
|
26
|
-
//
|
|
26
|
+
// Collect pages
|
|
27
27
|
let allPages = []
|
|
28
28
|
const uniquePaths = new Set()
|
|
29
29
|
|
|
@@ -56,7 +56,7 @@ async function aggregationMethod (options, contextInstance) {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
//
|
|
59
|
+
// Filter
|
|
60
60
|
if (typeof filter === 'function') {
|
|
61
61
|
allPages = allPages.filter(page => {
|
|
62
62
|
// Access values from result property
|
|
@@ -65,7 +65,7 @@ async function aggregationMethod (options, contextInstance) {
|
|
|
65
65
|
})
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
//
|
|
68
|
+
// Sort
|
|
69
69
|
if (typeof sort === 'function') {
|
|
70
70
|
allPages.sort((a, b) => {
|
|
71
71
|
const valA = a.result && a.result.values ? a.result.values : a.values
|
|
@@ -74,7 +74,7 @@ async function aggregationMethod (options, contextInstance) {
|
|
|
74
74
|
})
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
//
|
|
77
|
+
// Pagination
|
|
78
78
|
let startIndex = offset
|
|
79
79
|
let endIndex = allPages.length
|
|
80
80
|
|
|
@@ -108,7 +108,7 @@ async function aggregationMethod (options, contextInstance) {
|
|
|
108
108
|
// Automatically generate subsequent pagination pages if we are on the "root" page
|
|
109
109
|
// e.g., if we are on /blog/index.html (page 1), queue up /blog/page/2, /blog/page/3...
|
|
110
110
|
if (!match && currentPage === 1 && totalPages > 1 && buildId) {
|
|
111
|
-
const currentDocument = contextInstance.
|
|
111
|
+
const currentDocument = contextInstance.component
|
|
112
112
|
const currentPathname = currentDocument.path.pathname
|
|
113
113
|
const currentFilename = currentDocument.path.filename
|
|
114
114
|
const currentDirname = currentDocument.path.dirname
|
|
@@ -143,7 +143,6 @@ async function aggregationMethod (options, contextInstance) {
|
|
|
143
143
|
// If /blog/index.html, urlPathname is /blog/index.html. dirname is /blog.
|
|
144
144
|
|
|
145
145
|
if (currentFilename === 'index.html') {
|
|
146
|
-
// Correct logic for index.html url prefix
|
|
147
146
|
// If /index.html, urlPathname /index.html. dirname /. prefix /.
|
|
148
147
|
// If /blog/index.html, urlPathname /blog/index.html. dirname /blog. prefix /blog/.
|
|
149
148
|
urlPrefixBase = path.dirname(urlPathname)
|
|
@@ -183,8 +182,6 @@ async function aggregationMethod (options, contextInstance) {
|
|
|
183
182
|
}
|
|
184
183
|
|
|
185
184
|
const paginatedPages = allPages.slice(startIndex, endIndex)
|
|
186
|
-
|
|
187
|
-
// 5. Render Items
|
|
188
185
|
const resultNodes = []
|
|
189
186
|
|
|
190
187
|
for (const page of paginatedPages) {
|
|
@@ -207,10 +204,10 @@ async function aggregationMethod (options, contextInstance) {
|
|
|
207
204
|
|
|
208
205
|
// Render the item template
|
|
209
206
|
if (template) {
|
|
210
|
-
const component = await this.
|
|
207
|
+
const component = await this.createComponentElement({
|
|
211
208
|
id: template,
|
|
212
209
|
values: itemValues,
|
|
213
|
-
|
|
210
|
+
component: contextInstance.component,
|
|
214
211
|
renderContext: currentRenderContext
|
|
215
212
|
})
|
|
216
213
|
|
|
@@ -220,7 +217,7 @@ async function aggregationMethod (options, contextInstance) {
|
|
|
220
217
|
}
|
|
221
218
|
}
|
|
222
219
|
|
|
223
|
-
//
|
|
220
|
+
// Render pagination controls
|
|
224
221
|
if (pagination) {
|
|
225
222
|
const segment = pagination.segment || 'page'
|
|
226
223
|
const escapedSegment = segment.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
@@ -263,10 +260,10 @@ async function aggregationMethod (options, contextInstance) {
|
|
|
263
260
|
ellipsis: pagination.ellipsis || '...'
|
|
264
261
|
}
|
|
265
262
|
|
|
266
|
-
const component = await this.
|
|
263
|
+
const component = await this.createComponentElement({
|
|
267
264
|
id: paginationTemplateId,
|
|
268
265
|
values: paginationValues,
|
|
269
|
-
|
|
266
|
+
component: contextInstance.component,
|
|
270
267
|
renderContext: currentRenderContext
|
|
271
268
|
})
|
|
272
269
|
|
|
@@ -281,7 +278,7 @@ async function aggregationMethod (options, contextInstance) {
|
|
|
281
278
|
export const aggregation = createPlugin({
|
|
282
279
|
name: 'aggregation',
|
|
283
280
|
method: aggregationMethod,
|
|
284
|
-
|
|
281
|
+
components: [
|
|
285
282
|
path.join(import.meta.dirname, 'templates/coralite-pagination.html')
|
|
286
283
|
]
|
|
287
284
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coralite-plugin-aggregation",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "A Coralite plugin for dynamically collecting, filtering, sorting, and displaying content across multiple sources. Build database-free Coralite websites with automated content aggregation.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -39,16 +39,16 @@
|
|
|
39
39
|
"lib",
|
|
40
40
|
"types"
|
|
41
41
|
],
|
|
42
|
-
"scripts": {
|
|
43
|
-
"test": "node --test ./tests/index.spec.js"
|
|
44
|
-
},
|
|
45
42
|
"peerDependencies": {
|
|
46
|
-
"coralite": "^0.
|
|
43
|
+
"coralite": "^0.29.0"
|
|
47
44
|
},
|
|
48
45
|
"license": "AGPL-3.0-only",
|
|
49
|
-
"packageManager": "pnpm@10.30.0+sha512.2b5753de015d480eeb88f5b5b61e0051f05b4301808a82ec8b840c9d2adf7748eb352c83f5c1593ca703ff1017295bc3fdd3119abb9686efc96b9fcb18200937",
|
|
50
46
|
"devDependencies": {
|
|
51
47
|
"@stylistic/eslint-plugin-js": "^4.2.0",
|
|
52
|
-
"@stylistic/eslint-plugin-plus": "^4.2.0"
|
|
48
|
+
"@stylistic/eslint-plugin-plus": "^4.2.0",
|
|
49
|
+
"coralite": "0.29.0"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"test": "node --test ./tests/index.spec.js"
|
|
53
53
|
}
|
|
54
54
|
}
|