-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposts.js
More file actions
31 lines (24 loc) · 791 Bytes
/
posts.js
File metadata and controls
31 lines (24 loc) · 791 Bytes
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
const data = {
'html': require('./posts/html.json'),
'css': require('./posts/css.json'),
'javascript': require('./posts/javascript.json')
};
module.exports = function(app) {
app.get('/posts/:category', (req, res) => {
// In case the post category doesn't exists.
if (!data[req.params.category]) {
res.redirect('/');
return;
}
if (req.query.id && data[req.params.category].posts[req.query.id]) {
data[req.params.category].posts[req.query.id].views++;
res.render('post.ejs', {
data: data[req.params.category].posts[req.query.id]
});
return;
}
res.render('posts.ejs', {
data: data[req.params.category]
});
});
}