@nakedcreativity/cee-ms-node 0.3.35 → 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.
- package/index.js +139 -72
- 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 () {});
|
|
@@ -541,12 +534,69 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
541
534
|
console.log('pagination, ', page.pagination)
|
|
542
535
|
|
|
543
536
|
var renderedRegions = {}
|
|
537
|
+
var renderedColumns = {}
|
|
538
|
+
var renderedModules = {}
|
|
539
|
+
|
|
544
540
|
var jobs = []
|
|
545
541
|
|
|
546
542
|
// load page data
|
|
547
543
|
_.each(page.regions, function(region, key){
|
|
548
544
|
|
|
549
545
|
renderedRegions[key] = []
|
|
546
|
+
console.log(key)
|
|
547
|
+
|
|
548
|
+
if(region.containers){
|
|
549
|
+
|
|
550
|
+
region.containers.forEach((container, index)=>{
|
|
551
|
+
|
|
552
|
+
console.log(container)
|
|
553
|
+
if(container.module){
|
|
554
|
+
|
|
555
|
+
var html = `{% ${container.module} %}`
|
|
556
|
+
|
|
557
|
+
}else {
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
if(!container.class) {
|
|
561
|
+
container.class = 'container'
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
var html = ''
|
|
565
|
+
if(container.wrapper){
|
|
566
|
+
html += `<div class="${container.wrapper}">`
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
html += `<div class="${container.class}">`
|
|
570
|
+
|
|
571
|
+
container.rows.forEach(row=>{
|
|
572
|
+
|
|
573
|
+
html += `<div class="row ${row.class}">`
|
|
574
|
+
row.columns.forEach(column=>{
|
|
575
|
+
|
|
576
|
+
var modules = _.reduce(column.modules, (modules, id)=>{
|
|
577
|
+
return modules + '{% '+id+' %}'
|
|
578
|
+
}, '')
|
|
579
|
+
html += `<div class="col ${column.class}">${modules}</div>` // inserts placeholder in format {% id %}
|
|
580
|
+
|
|
581
|
+
})
|
|
582
|
+
|
|
583
|
+
html += `</div>`
|
|
584
|
+
|
|
585
|
+
})
|
|
586
|
+
if(container.wrapper){
|
|
587
|
+
html += `</div>`
|
|
588
|
+
}
|
|
589
|
+
html += `</div>`
|
|
590
|
+
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
renderedRegions[key][index] = html
|
|
594
|
+
|
|
595
|
+
})
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
console.log(renderedRegions)
|
|
599
|
+
|
|
550
600
|
_.each(region.modules, function(module, index){
|
|
551
601
|
|
|
552
602
|
var moduleTemplate = fs.readFileSync('./views/'+module.type+'.liquid');
|
|
@@ -562,7 +612,7 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
562
612
|
scope.navigation = this.site.navigation
|
|
563
613
|
}
|
|
564
614
|
this.engine.parseAndRender(moduleTemplate, scope)
|
|
565
|
-
.then(
|
|
615
|
+
.then(html => {
|
|
566
616
|
|
|
567
617
|
if(req.query.edit != null){
|
|
568
618
|
var $ = cheerio.load(html);
|
|
@@ -572,10 +622,15 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
572
622
|
$.root().children().attr('data-module-id', module._id);
|
|
573
623
|
}
|
|
574
624
|
html = $.html()
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
if(region.containers){
|
|
628
|
+
renderedModules[module._id] = html
|
|
629
|
+
}else {
|
|
630
|
+
renderedRegions[key][index] = html
|
|
631
|
+
}
|
|
632
|
+
return resolve();
|
|
633
|
+
|
|
579
634
|
})
|
|
580
635
|
.catch(error=>{
|
|
581
636
|
reject(error)
|
|
@@ -583,6 +638,8 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
583
638
|
}))
|
|
584
639
|
|
|
585
640
|
}, this)
|
|
641
|
+
|
|
642
|
+
|
|
586
643
|
}, this)
|
|
587
644
|
|
|
588
645
|
// loop through each module not in a region and generate HTML
|
|
@@ -628,10 +685,20 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
628
685
|
_.each(renderedRegions, function(region, key){
|
|
629
686
|
page.regions[key] = ''
|
|
630
687
|
_.each(region, function(html){
|
|
688
|
+
|
|
689
|
+
// items in rendered columns to place
|
|
690
|
+
if(Object.keys(renderedModules).length > 0){
|
|
691
|
+
_.each(renderedModules, (moduleHtml, key)=>{
|
|
692
|
+
html = html.replace(new RegExp('{%\\s'+key+'\\s%}','g'), moduleHtml)
|
|
693
|
+
})
|
|
694
|
+
|
|
695
|
+
}
|
|
696
|
+
|
|
631
697
|
page.regions[key] += html
|
|
632
698
|
})
|
|
633
699
|
})
|
|
634
700
|
|
|
701
|
+
|
|
635
702
|
var scope = page
|
|
636
703
|
if(this.site && this.site.navigation)
|
|
637
704
|
scope.navigation = this.site.navigation
|