@nakedcreativity/cee-ms-node 0.3.36 → 0.3.37
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/index.js +60 -67
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -343,79 +343,72 @@ function ceems(config) {
|
|
|
343
343
|
})
|
|
344
344
|
|
|
345
345
|
this.engine.registerTag('blog', {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
blog.pagination = pagination
|
|
401
|
-
blog.lastPage = lastPage
|
|
402
|
-
scope.push(blog)
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
return engine.handleCache(this.match[1]+'.liquid')
|
|
346
|
+
parse: function (tagToken, remainTokens) {
|
|
347
|
+
this.match = tagToken.args.split(' ')
|
|
348
|
+
},
|
|
349
|
+
render: function (scope, hash) {
|
|
350
|
+
// get the blog set
|
|
351
|
+
var siteblog = Liquid.evalValue(this.match[0], scope);
|
|
352
|
+
if (!siteblog) {
|
|
353
|
+
siteblog = this.match[0]
|
|
354
|
+
}
|
|
355
|
+
if (!site.blogs[siteblog]) {
|
|
356
|
+
return
|
|
357
|
+
}
|
|
358
|
+
// loop over articles, push articles that match tag or pagination, into array
|
|
359
|
+
var blog = site.blogs[siteblog]
|
|
360
|
+
var articles = []
|
|
361
|
+
// if tag set, create filtered array of articles
|
|
362
|
+
if (this.match[3]) {
|
|
363
|
+
var tag = Liquid.evalValue(this.match[3], scope);
|
|
364
|
+
if (!tag) {
|
|
365
|
+
tag = Liquid.lexical.parseLiteral(this.match[3])
|
|
366
|
+
}
|
|
367
|
+
blog.articles.forEach((article) => {
|
|
368
|
+
if (article.tags && article.tags.indexOf(tag) > -1) {
|
|
369
|
+
articles.push(article)
|
|
370
|
+
}
|
|
371
|
+
})
|
|
372
|
+
} else {
|
|
373
|
+
articles = blog.articles
|
|
374
|
+
}
|
|
375
|
+
//check if articles per page is set
|
|
376
|
+
if (this.match[2]) {
|
|
377
|
+
var articlesPerPage = this.match[2]
|
|
378
|
+
} else {
|
|
379
|
+
var articlesPerPage = 10
|
|
380
|
+
}
|
|
381
|
+
var pagination = 1
|
|
382
|
+
if (scope.scopes[0].page && scope.scopes[0].page.pagination) {
|
|
383
|
+
pagination = scope.scopes[0].page.pagination
|
|
384
|
+
}
|
|
385
|
+
articlesPerPage = parseInt(articlesPerPage)
|
|
386
|
+
var start = articlesPerPage * (pagination - 1)
|
|
387
|
+
var end = start + articlesPerPage
|
|
388
|
+
var lastPage = Math.ceil(articles.length / articlesPerPage)
|
|
389
|
+
// is page greater than the number of articles?
|
|
390
|
+
// throw a 404
|
|
391
|
+
if (start >= articles.length) {
|
|
392
|
+
throw new Error('This page does not exist')
|
|
393
|
+
}
|
|
394
|
+
// slice original blog array to send just current page of articles to liquid
|
|
395
|
+
blog.articles = articles.slice(start, end)
|
|
396
|
+
blog.pagination = pagination
|
|
397
|
+
blog.lastPage = lastPage
|
|
398
|
+
scope.push(blog)
|
|
399
|
+
return engine.handleCache(this.match[1] + '.liquid')
|
|
406
400
|
.then((templates) => {
|
|
407
401
|
return engine.renderer.renderTemplates(templates, scope);
|
|
408
402
|
})
|
|
409
403
|
.then((html) => {
|
|
410
404
|
scope.pop();
|
|
411
405
|
return html;
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
})
|
|
406
|
+
})
|
|
407
|
+
.catch((error) => {
|
|
408
|
+
throw error
|
|
409
|
+
})
|
|
410
|
+
}
|
|
411
|
+
})
|
|
419
412
|
|
|
420
413
|
|
|
421
414
|
this.app.listen(config.port, function () {});
|