forked from ardgedee/enterprise-html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (43 loc) · 1.04 KB
/
app.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
process.chdir(__dirname);
require.paths.push('/usr/local/lib/node');
var express = require('express')
, hl = require("highlight").Highlight;
var app = express.createServer();
app.configure(function () {
app.use(express.methodOverride());
app.use(express.bodyDecoder());
app.use(app.router);
app.use(express.staticProvider(__dirname + '/public'));
});
// Colors
var colors = 'ff0090,ffff00,0bff00,08e3ff,ff460d'.split(',');
// Tips
var tips = require('./tips');
// Make 'em sexy
tips.forEach(function (tip) {
if (tip.example) {
tip.example = hl(tip.example.join('\n'));
}
});
// Routes
app.get('/', function (req, res) {
showTip(res, Math.ceil(Math.random() * tips.length));
});
app.get('/:permalink', function (req, res) {
var index = req.params.permalink;
if (tips[index - 1]) {
showTip(res, index);
} else {
res.redirect('/');
}
});
function showTip (res, index) {
res.render('index.jade', {
locals: {
tip: tips[index - 1],
color: colors[Math.floor(Math.random() * colors.length)],
index: index
}
});
}
app.listen(3000);