@nakedcreativity/cee-ms-node 0.3.33 → 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 (3) hide show
  1. package/.DS_Store +0 -0
  2. package/index.js +60 -11
  3. package/package.json +1 -1
package/.DS_Store ADDED
Binary file
package/index.js CHANGED
@@ -162,6 +162,12 @@ function ceems(config) {
162
162
  },
163
163
  render: function(scope, hash){
164
164
  // var filepath = Liquid.evalValue(this.match[1]+'.liquid', scope);
165
+
166
+ if(this.match[2]){
167
+ var itemsPerPage = this.match[2]
168
+ }else{
169
+ var itemsPerPage = 10
170
+ }
165
171
 
166
172
  var collectionName = Liquid.evalValue(this.match[0], scope)
167
173
 
@@ -171,6 +177,20 @@ function ceems(config) {
171
177
 
172
178
  var scopeObj = {}
173
179
  scopeObj['collection'] = collection
180
+
181
+ if(scope.scopes[0].page && scope.scopes[0].page.pagination){
182
+ scopeObj.pagination = scope.scopes[0].page.pagination
183
+ }else {
184
+ scopeObj.pagination = 1
185
+ }
186
+
187
+ scopeObj.itemsPerPage = parseInt(itemsPerPage);
188
+
189
+ scopeObj.start = itemsPerPage * (scopeObj.pagination - 1)
190
+ scopeObj.end = scopeObj.start + itemsPerPage
191
+
192
+ scopeObj.lastPage = Math.ceil(collection.data.length / itemsPerPage)
193
+
174
194
  scope.push(scopeObj)
175
195
 
176
196
  //console.log(scope)
@@ -327,32 +347,61 @@ function ceems(config) {
327
347
  this.match = tagToken.args.split(' ')
328
348
  },
329
349
  render: function(scope, hash){
330
-
331
- var articlesPerPage = 10
350
+
351
+ if(this.match[2]){
352
+ var articlesPerPage = this.match[2]
353
+ }else{
354
+ var articlesPerPage = 10
355
+ }
332
356
 
333
357
  if(!site.blogs[this.match[0]]){
334
358
  return
335
359
  }
360
+
361
+ // loop over articles, push articles that match tag or pagination, into array
362
+
336
363
  var blog = site.blogs[this.match[0]]
364
+ var pagination = 1
365
+
337
366
  if(scope.scopes[0].page && scope.scopes[0].page.pagination){
338
- blog.pagination = scope.scopes[0].page.pagination
339
- }else {
340
- blog.pagination = 1
367
+ pagination = scope.scopes[0].page.pagination
341
368
  }
342
369
 
343
- blog.start = articlesPerPage * (blog.pagination - 1)
344
- blog.end = blog.start + articlesPerPage
370
+ articlesPerPage = parseInt(articlesPerPage)
371
+ var start = articlesPerPage * (pagination - 1)
372
+ var end = start + articlesPerPage
345
373
 
346
- blog.lastPage = Math.ceil(blog.articles.length / articlesPerPage)
347
-
348
- scope.push(blog)
374
+ var lastPage = Math.ceil(blog.articles.length / articlesPerPage)
349
375
 
350
376
  // is page greater than the number of articles?
351
377
  // throw a 404
352
- if(blog.start >= blog.articles.length){
378
+ if(start >= blog.articles.length){
353
379
  throw new Error('This page does not exist')
354
380
  }
355
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
+
356
405
  return engine.handleCache(this.match[1]+'.liquid')
357
406
  .then((templates) => {
358
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.33",
3
+ "version": "0.3.35",
4
4
  "description": "Cee.ms for Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {