@nakedcreativity/cee-ms-node 0.3.36 → 0.3.38
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 +69 -77
- 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 () {});
|
|
@@ -538,8 +531,6 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
538
531
|
})
|
|
539
532
|
}
|
|
540
533
|
|
|
541
|
-
console.log('pagination, ', page.pagination)
|
|
542
|
-
|
|
543
534
|
var renderedRegions = {}
|
|
544
535
|
var renderedColumns = {}
|
|
545
536
|
var renderedModules = {}
|
|
@@ -550,13 +541,11 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
550
541
|
_.each(page.regions, function(region, key){
|
|
551
542
|
|
|
552
543
|
renderedRegions[key] = []
|
|
553
|
-
console.log(key)
|
|
554
544
|
|
|
555
545
|
if(region.containers){
|
|
556
546
|
|
|
557
547
|
region.containers.forEach((container, index)=>{
|
|
558
548
|
|
|
559
|
-
console.log(container)
|
|
560
549
|
if(container.module){
|
|
561
550
|
|
|
562
551
|
var html = `{% ${container.module} %}`
|
|
@@ -568,22 +557,27 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
568
557
|
container.class = 'container'
|
|
569
558
|
}
|
|
570
559
|
|
|
560
|
+
console.log(container)
|
|
561
|
+
|
|
571
562
|
var html = ''
|
|
572
563
|
if(container.wrapper){
|
|
573
|
-
html += `<div class="${container.wrapper}">`
|
|
564
|
+
html += `<div class="${container.wrapper}" data-container-id="${container._id}"><div class="${container.class}">`
|
|
565
|
+
}else {
|
|
566
|
+
html += `<div class="${container.class}" data-container-id="${container._id}">`
|
|
574
567
|
}
|
|
575
568
|
|
|
576
|
-
html += `<div class="${container.class}">`
|
|
577
569
|
|
|
578
570
|
container.rows.forEach(row=>{
|
|
579
571
|
|
|
580
|
-
html += `<div class="row ${row.class}">`
|
|
572
|
+
html += `<div class="row ${row.class}" data-row-id="${row._id}">`
|
|
581
573
|
row.columns.forEach(column=>{
|
|
582
574
|
|
|
575
|
+
console.log(column)
|
|
576
|
+
|
|
583
577
|
var modules = _.reduce(column.modules, (modules, id)=>{
|
|
584
578
|
return modules + '{% '+id+' %}'
|
|
585
579
|
}, '')
|
|
586
|
-
html += `<div class="col ${column.class}">${modules}</div>` // inserts placeholder in format {% id %}
|
|
580
|
+
html += `<div data-column-id="${column._id}" class="col ${column.class}">${modules}</div>` // inserts placeholder in format {% id %}
|
|
587
581
|
|
|
588
582
|
})
|
|
589
583
|
|
|
@@ -602,8 +596,6 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
602
596
|
})
|
|
603
597
|
}
|
|
604
598
|
|
|
605
|
-
console.log(renderedRegions)
|
|
606
|
-
|
|
607
599
|
_.each(region.modules, function(module, index){
|
|
608
600
|
|
|
609
601
|
var moduleTemplate = fs.readFileSync('./views/'+module.type+'.liquid');
|