@nakedcreativity/cee-ms-node 0.3.34 → 0.3.35

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.
Files changed (2) hide show
  1. package/index.js +34 -11
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -357,28 +357,51 @@ function ceems(config) {
357
357
  if(!site.blogs[this.match[0]]){
358
358
  return
359
359
  }
360
+
361
+ // loop over articles, push articles that match tag or pagination, into array
362
+
360
363
  var blog = site.blogs[this.match[0]]
364
+ var pagination = 1
365
+
361
366
  if(scope.scopes[0].page && scope.scopes[0].page.pagination){
362
- blog.pagination = scope.scopes[0].page.pagination
363
- }else {
364
- blog.pagination = 1
367
+ pagination = scope.scopes[0].page.pagination
365
368
  }
366
369
 
367
- blog.articlesPerPage = parseInt(articlesPerPage);
370
+ articlesPerPage = parseInt(articlesPerPage)
371
+ var start = articlesPerPage * (pagination - 1)
372
+ var end = start + articlesPerPage
368
373
 
369
- blog.start = articlesPerPage * (blog.pagination - 1)
370
- blog.end = blog.start + articlesPerPage
371
-
372
- blog.lastPage = Math.ceil(blog.articles.length / articlesPerPage)
373
-
374
- scope.push(blog)
374
+ var lastPage = Math.ceil(blog.articles.length / articlesPerPage)
375
375
 
376
376
  // is page greater than the number of articles?
377
377
  // throw a 404
378
- if(blog.start >= blog.articles.length){
378
+ if(start >= blog.articles.length){
379
379
  throw new Error('This page does not exist')
380
380
  }
381
381
 
382
+ var articles = []
383
+
384
+
385
+ // if tag set, create filtered array of articles
386
+ if(this.match[3]){
387
+ var tag = Liquid.lexical.parseLiteral(this.match[3])
388
+
389
+ blog.articles.forEach((article) => {
390
+ if (article.tags && article.tags.indexOf(tag) > -1){
391
+ articles.push(article)
392
+ }
393
+ })
394
+ }else {
395
+ articles = blog.articles
396
+ }
397
+
398
+ // slice original blog array to send just current page of articles to liquid
399
+ blog.articles = articles.slice(start,end)
400
+ blog.pagination = pagination
401
+ blog.lastPage = lastPage
402
+ scope.push(blog)
403
+
404
+
382
405
  return engine.handleCache(this.match[1]+'.liquid')
383
406
  .then((templates) => {
384
407
  return engine.renderer.renderTemplates(templates, scope);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nakedcreativity/cee-ms-node",
3
- "version": "0.3.34",
3
+ "version": "0.3.35",
4
4
  "description": "Cee.ms for Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {