@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.
Files changed (2) hide show
  1. package/index.js +60 -67
  2. 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
- parse: function(tagToken, remainTokens) {
347
- this.match = tagToken.args.split(' ')
348
- },
349
- render: function(scope, hash){
350
-
351
- if(this.match[2]){
352
- var articlesPerPage = this.match[2]
353
- }else{
354
- var articlesPerPage = 10
355
- }
356
-
357
- if(!site.blogs[this.match[0]]){
358
- return
359
- }
360
-
361
- // loop over articles, push articles that match tag or pagination, into array
362
-
363
- var blog = site.blogs[this.match[0]]
364
- var pagination = 1
365
-
366
- if(scope.scopes[0].page && scope.scopes[0].page.pagination){
367
- pagination = scope.scopes[0].page.pagination
368
- }
369
-
370
- articlesPerPage = parseInt(articlesPerPage)
371
- var start = articlesPerPage * (pagination - 1)
372
- var end = start + articlesPerPage
373
-
374
- var lastPage = Math.ceil(blog.articles.length / articlesPerPage)
375
-
376
- // is page greater than the number of articles?
377
- // throw a 404
378
- if(start >= blog.articles.length){
379
- throw new Error('This page does not exist')
380
- }
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
-
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
- .catch((error) => {
414
- throw error
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 () {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nakedcreativity/cee-ms-node",
3
- "version": "0.3.36",
3
+ "version": "0.3.37",
4
4
  "description": "Cee.ms for Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {