-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
157 lines (142 loc) · 3.31 KB
/
index.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
147
148
149
150
151
152
153
154
155
156
157
var express = require('express'),
app = express(),
Poet = require('poet');
/**
* Instantiate and hook Poet into Express.js
*/
var poet = Poet(app, {
postsPerPage: 10,
posts: './content/posts/',
metaFormat: 'json',
readMoreLink: function (post) {
var anchor = '<a href="' + post.url + '" title="Read more of ' + post.title + '">› read more</a>';
return '<p class="readmore">' + anchor + '</p>';
},
routes: {
'/articles/:post': 'post',
'/tags/:tag': 'tag'
}
});
/**
* Configure Express.js
*/
app.set('view engine', 'jade');
app.set('view options', { layout: false });
app.set('views', __dirname + '/views');
app.use(express.static(__dirname + '/www'));
/**
* Initialize poet and clear poet cache
*
* @return {void}
*/
poet.init().then(function () {
poet.clearCache();
});
/**
* Route Tags | Render article page if exists, otherwise 404
*
* @param {Object} req Poet request parameter
* @param {Object} res Poet response parameter
* @return {void}
*/
poet.addRoute('/articles/:post', function (req, res) {
var post = poet.helpers.getPost(req.params.post);
if (post) {
res.render('post', {
post: post,
css: req.css
});
} else {
res.status(404);
res.render('4o4.jade', {
url: req.url,
css: req.css
});
}
});
/**
* Route Tags | Render page with tagged posts
*
* @param {Object} req Poet request parameter
* @param {Object} res Poet response parameter
* @return {void}
*/
poet.addRoute('/tag/:tag', function (req, res) {
var taggedPosts = poet.helpers.postsWithTag(req.params.tag);
if (taggedPosts.length) {
res.render('tag', {
posts: taggedPosts,
tag: req.params.tag,
css: req.css
});
}
});
/**
* Route Legal | Render imprint page
*
* @param {Object} req Express request parameter
* @param {Object} res Express response parameter
* @return {void}
*/
app.get('/legal', function (req, res) {
res.render('page-legal', {
title: 'Imprint',
css: req.css
});
});
/**
* Route RSS | Render 5 latest posts
*
* @param {Object} req Express request parameter
* @param {Object} res Express response parameter
* @return {void}
*/
app.get('/rss', function (req, res) {
var posts = poet.helpers.getPosts(0, 5);
res.setHeader('Content-Type', 'application/rss+xml');
res.render('rss', {
posts: posts,
css: req.css
});
});
/**
* Route Startpage
*
* @param {Object} req Express request parameter
* @param {Object} res Express response parameter
* @return {void}
*/
app.get('/', function (req, res) {
res.render('index', {
css: req.css
});
});
/**
* Route About
*
* @param {Object} req Express request parameter
* @param {Object} res Express response parameter
* @return {void}
*/
// app.get( '/about', function (req, res) {
// res.render( 'page-about', {
// title: 'About me',
// css: req.css
// });
// });
//
/**
* Route 404
*
* @param {Object} req Express request parameter
* @param {Object} res Express response parameter
* @return {void}
*/
app.use(function (req, res) {
res.status(404);
res.render('4o4.jade', {
url: req.url,
css: req.css
});
});
app.listen(process.env.PORT || 3322);