-
Notifications
You must be signed in to change notification settings - Fork 6
/
handlebars.js
59 lines (51 loc) · 1.8 KB
/
handlebars.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
let handlebars = require('express-handlebars').create(
{
defaultLayout:'main',
helpers: {
title: function(object,n){
if(object == undefined || object[n] == undefined){
return "<ARTICLE NOT FOUND>";
}
return object[n]['title'];
},
image: function(object,n){
if(object == undefined || object[n] == undefined){
return "";
}
return object[n]['urlToImage'];
},
desc: function(object,n){
if(object == undefined || object[n] == undefined || object[n]['description'] == null){
return "No description available";
}
return object[n]['description'];
},
author: function(object,n){
if(object == undefined || object[n] == undefined || object[n]['author'] == null){
return "";
}
return object[n]['author'];
},
link: function(object,n){
if(object == undefined || object[n] == undefined){
return "";
}
return object[n]['url'];
},
date: function(object,n){
if(object == undefined || object[n] == undefined || object[n]['publishedAt'] == null){
return "";
}
return object[n]['publishedAt'].replace(/\T(.*)/g,'');
},
times: function(n,block){
let accum = '';
for(let i = 0; i < n; ++i){
accum += block.fn(i);
}
return accum;
}
}
}
);
module.exports = handlebars;