-
Notifications
You must be signed in to change notification settings - Fork 183
/
server.js
146 lines (95 loc) · 4.53 KB
/
server.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
var port = process.env.PORT || 4000,
app = require('./app').init(port),
utils = require('./utils'),
conf = require('./conf'),
request = require('request'),
pageSize = 20;
app.get('/', function(req, res){
var templates = require('./templates');
var starters = [], themes = [];
for (var i=0;i<templates.length;i++) {
if (templates[i].tags.indexOf("starter")!=-1) {
starters.push(templates[i]);
}
if (templates[i].tags.indexOf("theme")!=-1) {
themes.push(templates[i]);
}
}
res.render("index",{templates:templates,starters:starters,themes:themes,path:"/"});
});
app.get('/templates/:id', function(req, res){
console.log("/templates.......");
var templates = require('./templates');
var id = req.params.id;
if (typeof id==="undefined") {
return;
}
for (var i=0;i<templates.length;i++) {
var prev = (templates[i-1])||templates[templates.length-1];
var next = (templates[i+1])||templates[0];
if (templates[i].id===id) {
res.render("detail",{template:templates[i],next:next,prev:prev,title:templates[i].title+" Bootstrap template",desc:"Bootstrap " + templates[i].title + " template example. This is a free, responsive starter template and theme for Bootstrap 3 from BootstrapZero."});
return;
}
}
res.render("404",{error:"no results"});
});
app.get('/bootstrap-template/:title', function(req, res){
console.log("/template by title.......");
var templates = require('./templates');
var title = req.params.title;
if (typeof title==="undefined") {
return;
}
else {
title = title.replace(/-/g," ");
}
for (var i=0;i<templates.length;i++) {
var prev = (templates[i-1])||templates[templates.length-1];
var next = (templates[i+1])||templates[0];
if (templates[i].title.toLowerCase()===title.toLowerCase()) {
res.render("detail",{template:templates[i],next:next,prev:prev,title:"Bootstrap "+title+" template",desc:"Bootstrap " + title + " template example. This is a free, responsive starter template and theme for Bootstrap 3 from BootstrapZero.",keywords:"bootstrap,"+templates[i].tags+",free,bootstrap template"});
return;
}
}
res.render("404",{error:"no results"});
});
app.get('/api/templates', function(req, res){
var fs = require('fs');
//fs.readFile('./templates.json', 'utf8', function (err, data) {
// res.json(data);
//});
var data = require('./templates');
res.json(data);
//var fileJSON = require('./static/templates.json');
//res.send(fileJSON);
//res.writeHead(200, {"Content-Type": "application/json"});
//fs.createReadStream('templates.json',{flags:'r',encoding:'utf-8'}).pipe(res);
});
app.get('/bootstraps/:page', function(req, res){
console.log("/templates paged list all.......");
var page = (req.params.page)||1;
var templates = require('./templates').reverse();
templates = templates.slice();
res.render("list",{templates:templates,tag:"Bootstrap",title:"Free bootstrap themes and templates",desc:"Bootstrap templates and examples. A collection of free, responsive starter templates and themes for Bootstrap from BootstrapZero."});
});
app.get('/bootstrap-templates', function(req, res){
console.log("/templates list all.......");
var templates = require('./templates').reverse();
res.render("list",{templates:templates,tag:"Bootstrap",title:"Free bootstrap themes and template",desc:"Bootstrap templates and examples. A collection of free, responsive starter templates and themes for Bootstrap from BootstrapZero."});
});
app.get('/bootstrap-templates/:tag', function(req, res){
var templates = require('./templates');
var tag = req.params.tag;
var tagged = [];
for (var i=0;i<templates.length;i++) {
if (templates[i].tags.indexOf(tag)!=-1) {
tagged.push(templates[i]);
}
}
res.render("list",{templates:tagged,tag:tag,title:'Bootstrap ' + tag.replace("theme","") + ' themes and templates - BootstrapZero'});
});
/* The 404 Route (ALWAYS Keep this as the last route) */
app.get('/*', function(req, res){
res.render('404.ejs');
});