@nakedcreativity/cee-ms-node 0.3.25 → 0.3.27
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 -23
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -114,8 +114,6 @@ function ceems(config) {
|
|
|
114
114
|
path = this.match[0]
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
|
|
119
117
|
if(site.pages[path]){
|
|
120
118
|
var page = site.pages[path]
|
|
121
119
|
|
|
@@ -325,15 +323,31 @@ function ceems(config) {
|
|
|
325
323
|
},
|
|
326
324
|
render: function(scope, hash){
|
|
327
325
|
|
|
328
|
-
|
|
329
|
-
console.log(site.blogs[this.match[0]])
|
|
326
|
+
var articlesPerPage = 10
|
|
330
327
|
|
|
331
328
|
if(!site.blogs[this.match[0]]){
|
|
332
|
-
console.log('no match')
|
|
333
329
|
return
|
|
334
330
|
}
|
|
335
|
-
|
|
336
|
-
scope.
|
|
331
|
+
var blog = site.blogs[this.match[0]]
|
|
332
|
+
if(scope.scopes[0].page && scope.scopes[0].page.pagination){
|
|
333
|
+
blog.pagination = scope.scopes[0].page.pagination
|
|
334
|
+
}else {
|
|
335
|
+
blog.pagination = 1
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
blog.start = articlesPerPage * (blog.pagination - 1)
|
|
339
|
+
blog.end = blog.start + articlesPerPage
|
|
340
|
+
|
|
341
|
+
blog.lastPage = Math.ceil(blog.articles.length / articlesPerPage)
|
|
342
|
+
|
|
343
|
+
scope.push(blog)
|
|
344
|
+
|
|
345
|
+
// is page greater than the number of articles?
|
|
346
|
+
// throw a 404
|
|
347
|
+
if(blog.start >= blog.articles.length){
|
|
348
|
+
throw new Error('This page does not exist')
|
|
349
|
+
}
|
|
350
|
+
|
|
337
351
|
return engine.handleCache(this.match[1]+'.liquid')
|
|
338
352
|
.then((templates) => {
|
|
339
353
|
return engine.renderer.renderTemplates(templates, scope);
|
|
@@ -341,7 +355,10 @@ function ceems(config) {
|
|
|
341
355
|
.then((html) => {
|
|
342
356
|
scope.pop();
|
|
343
357
|
return html;
|
|
344
|
-
|
|
358
|
+
})
|
|
359
|
+
.catch((error) => {
|
|
360
|
+
throw error
|
|
361
|
+
})
|
|
345
362
|
}
|
|
346
363
|
|
|
347
364
|
})
|
|
@@ -400,6 +417,16 @@ ceems.prototype.load = function(req, res){
|
|
|
400
417
|
|
|
401
418
|
site = this.site //????
|
|
402
419
|
|
|
420
|
+
// this may be better in middleware?
|
|
421
|
+
// test if path matches a pagination url
|
|
422
|
+
var regex = new RegExp("(.+)(\/[0-9]{1,})$")
|
|
423
|
+
if(regex.test(path)){
|
|
424
|
+
// looks like a blog url
|
|
425
|
+
var matches = path.match(regex)
|
|
426
|
+
var path = matches[1]
|
|
427
|
+
var pagination = parseInt(matches[2].substring(1))
|
|
428
|
+
}
|
|
429
|
+
|
|
403
430
|
if(this.site.pages[path]){
|
|
404
431
|
var page = this.site.pages[path]
|
|
405
432
|
|
|
@@ -410,6 +437,10 @@ ceems.prototype.load = function(req, res){
|
|
|
410
437
|
var page = JSON.parse(fs.readFileSync('./pages/'+page._id+'.json', 'utf8'));
|
|
411
438
|
page.fullpath = this.site.pages[path].url
|
|
412
439
|
page.path = page.fullpath.split('/')
|
|
440
|
+
|
|
441
|
+
if(pagination)
|
|
442
|
+
page.pagination = pagination
|
|
443
|
+
|
|
413
444
|
return page
|
|
414
445
|
|
|
415
446
|
}
|
|
@@ -431,17 +462,17 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
431
462
|
page = this.load(req, res)
|
|
432
463
|
}
|
|
433
464
|
// get any external data, and save this into the page
|
|
434
|
-
if(page.external){
|
|
435
|
-
|
|
465
|
+
// if(page.external){
|
|
466
|
+
// _.each(page.external, function(ext, key){
|
|
436
467
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
468
|
+
// try {
|
|
469
|
+
// page.external[key].data = JSON.parse(fs.readFileSync('./'+ext.file, 'utf8'));
|
|
470
|
+
// }catch(error){
|
|
471
|
+
// console.log(error)
|
|
472
|
+
// }
|
|
442
473
|
|
|
443
|
-
|
|
444
|
-
}
|
|
474
|
+
// })
|
|
475
|
+
// }
|
|
445
476
|
|
|
446
477
|
// if there are whitelisted cookies, add these to the page so they can be rendered
|
|
447
478
|
if(this.config.whitelistedCookies){
|
|
@@ -452,7 +483,8 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
452
483
|
}
|
|
453
484
|
})
|
|
454
485
|
}
|
|
455
|
-
|
|
486
|
+
|
|
487
|
+
console.log('pagination, ', page.pagination)
|
|
456
488
|
|
|
457
489
|
var renderedRegions = {}
|
|
458
490
|
var jobs = []
|
|
@@ -490,7 +522,10 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
490
522
|
|
|
491
523
|
renderedRegions[key][index] = html
|
|
492
524
|
return resolve();
|
|
493
|
-
|
|
525
|
+
})
|
|
526
|
+
.catch(error=>{
|
|
527
|
+
reject(error)
|
|
528
|
+
})
|
|
494
529
|
}))
|
|
495
530
|
|
|
496
531
|
}, this)
|
|
@@ -525,7 +560,10 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
525
560
|
page.modules[key] = html
|
|
526
561
|
return resolve();
|
|
527
562
|
|
|
528
|
-
|
|
563
|
+
})
|
|
564
|
+
.catch(error=>{
|
|
565
|
+
reject(error)
|
|
566
|
+
})
|
|
529
567
|
}))
|
|
530
568
|
|
|
531
569
|
}, this)
|
|
@@ -554,11 +592,10 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
554
592
|
res.send(html)
|
|
555
593
|
})
|
|
556
594
|
|
|
557
|
-
}, reason => {
|
|
558
|
-
console.log(reason)
|
|
559
595
|
}).catch(error=>{
|
|
596
|
+
console.log('error in')
|
|
560
597
|
console.log(error)
|
|
561
|
-
res.status(500).send(
|
|
598
|
+
res.status(500).send(error.message);
|
|
562
599
|
})
|
|
563
600
|
}
|
|
564
601
|
|