@nakedcreativity/cee-ms-node 0.3.9 → 0.3.10
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 +44 -13
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -70,23 +70,17 @@ function ceems(config) {
|
|
|
70
70
|
var page = scope.scopes[0]
|
|
71
71
|
|
|
72
72
|
if(page.path && this.match[0] == 'page.path[0]' && site.navigation[page.path[0]]){
|
|
73
|
-
console.log('navigation exists for ', this.match[0])
|
|
74
73
|
scope.push(site.navigation[page.path[0]]);
|
|
75
74
|
}else if(page.path && this.match[0] == 'page.path[1]' && site.navigation[page.path[1]]){
|
|
76
|
-
console.log('navigation exists for ', this.match[0])
|
|
77
75
|
scope.push(site.navigation[page.path[1]]);
|
|
78
76
|
}else if(site.navigation[this.match[0]]){
|
|
79
77
|
scope.push(site.navigation[this.match[0]]);
|
|
80
78
|
}else {
|
|
81
79
|
return
|
|
82
80
|
}
|
|
83
|
-
// look for navigation that match the name of any part of the path?
|
|
84
|
-
|
|
85
|
-
console.log('render ',this.match[1]+'.liquid')
|
|
86
81
|
|
|
87
82
|
return engine.handleCache(this.match[1]+'.liquid')
|
|
88
83
|
.then((templates) => {
|
|
89
|
-
|
|
90
84
|
return engine.renderer.renderTemplates(templates, scope);
|
|
91
85
|
})
|
|
92
86
|
.then((html) => {
|
|
@@ -96,6 +90,50 @@ function ceems(config) {
|
|
|
96
90
|
}
|
|
97
91
|
});
|
|
98
92
|
|
|
93
|
+
this.engine.registerTag('page', {
|
|
94
|
+
parse: function(tagToken, remainTokens) {
|
|
95
|
+
this.match = tagToken.args.split(' '); // name // path[0] == navigation name
|
|
96
|
+
},
|
|
97
|
+
render: function(scope, hash){
|
|
98
|
+
// var filepath = Liquid.evalValue(this.match[1]+'.liquid', scope);
|
|
99
|
+
var page = scope.scopes[0]
|
|
100
|
+
|
|
101
|
+
console.log('look for page with handle', this.match[0])
|
|
102
|
+
var site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
|
|
103
|
+
console.log(site)
|
|
104
|
+
|
|
105
|
+
if(site.pages[this.match[0]]){
|
|
106
|
+
var page = site.pages[this.match[0]]
|
|
107
|
+
console.log(page)
|
|
108
|
+
if(page.redirect){
|
|
109
|
+
res.redirect(parseInt(page.redirect.type), page.redirect.to)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
var page = JSON.parse(fs.readFileSync('./pages/'+page._id+'.json', 'utf8'));
|
|
113
|
+
page.fullpath = site.pages[this.match[0]].url
|
|
114
|
+
page.path = page.fullpath.split('/')
|
|
115
|
+
|
|
116
|
+
scope.push(page)
|
|
117
|
+
|
|
118
|
+
return engine.handleCache(this.match[1]+'.liquid')
|
|
119
|
+
.then((templates) => {
|
|
120
|
+
return engine.renderer.renderTemplates(templates, scope);
|
|
121
|
+
})
|
|
122
|
+
.then((html) => {
|
|
123
|
+
scope.pop();
|
|
124
|
+
return html;
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
}else {
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
|
|
99
137
|
this.app.listen(config.port, function () {});
|
|
100
138
|
|
|
101
139
|
this.app.use((req, res, next)=>{
|
|
@@ -154,8 +192,6 @@ ceems.prototype.load = function(req, res){
|
|
|
154
192
|
|
|
155
193
|
var page = JSON.parse(fs.readFileSync('./pages/'+page._id+'.json', 'utf8'));
|
|
156
194
|
page.fullpath = this.site.pages[path].url
|
|
157
|
-
console.log(this.site.pages[path])
|
|
158
|
-
console.log('full path is', this.site.pages[path].url)
|
|
159
195
|
page.path = page.fullpath.split('/')
|
|
160
196
|
return page
|
|
161
197
|
|
|
@@ -174,7 +210,6 @@ ceems.prototype.load = function(req, res){
|
|
|
174
210
|
|
|
175
211
|
ceems.prototype.render = function(req, res, page=null) {
|
|
176
212
|
|
|
177
|
-
console.log('render fn')
|
|
178
213
|
if(!page){
|
|
179
214
|
page = this.load(req, res)
|
|
180
215
|
}
|
|
@@ -226,7 +261,6 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
226
261
|
this.engine.parseAndRender(moduleTemplate, scope)
|
|
227
262
|
.then(function(html){
|
|
228
263
|
|
|
229
|
-
|
|
230
264
|
if(req.query.edit != null){
|
|
231
265
|
var $ = cheerio.load(html);
|
|
232
266
|
|
|
@@ -234,8 +268,6 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
234
268
|
if(module._id){
|
|
235
269
|
$.root().children().attr('data-module-id', module._id);
|
|
236
270
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
271
|
html = $.html()
|
|
240
272
|
}
|
|
241
273
|
|
|
@@ -291,7 +323,6 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
291
323
|
})
|
|
292
324
|
})
|
|
293
325
|
|
|
294
|
-
console.log('render finished page')
|
|
295
326
|
var scope = page
|
|
296
327
|
if(this.site && this.site.navigation)
|
|
297
328
|
scope.navigation = this.site.navigation
|