-
Notifications
You must be signed in to change notification settings - Fork 35
/
app.js
101 lines (76 loc) · 2.72 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
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
var fs = require('fs'),
moment = require('moment'),
express = require('express'),
haroo = require('./lib/haroopress/index'),
config = require('./config'),
routes = require('./source/routes'),
path = require('path');
var theme = path.resolve(config.themeDir, config.theme.name );
var data = haroo.getMainData();
data.config.meta.pageTitle = '';
var app = express();
app.configure(function() {
app.set('views', theme +'/views');
app.set('view engine', 'ejs');
app.use(express.static(theme +'/public'));
app.use('/_asserts', express.static(process.cwd()+'/lib/shower'));
//app.use('/slides', express.static(process.cwd()+'/source/data/slides'))
//app.use(express.logger());
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
//app.use(pass.initialize());
//app.use(pass.session());
});
app.get('/', function(req, res) {
res.render('main', data);
});
app.get('/post/:title', function(req, res) {
data.archive = data.archives[req.params.title];
data.config.meta.pageTitle = data.archive.head.title +' | ';
res.render('archive', data);
});
/* category main page */
app.get('/category', function(req, res) {
res.render('categories', data);
});
app.get('/category/:cate', function(req, res) {
data.cates = data.categories[req.params.cate];
res.render('cate', data);
});
/* category main page */
app.get('/authors', function(req, res) {
res.render('authors', data);
});
app.get('/authors/:name', function(req, res) {
data.author = data.authors[req.params.name];
data.config.meta.pageTitle = data.author.head.name +'\'s articles | ';
res.render('author', data);
});
app.get('/archives', function(req, res) {
res.render('archives', data);
});
app.get('/slides', function(req, res) {
var _layout = data.layout;
data.layout = '../layout';
res.render('slide/list', data);
data.layout = _layout;
});
app.get('/slides/:title', function(req, res) {
data.slide = data.slides[req.params.title];
data.config.meta.pageTitle = data.slide.head.title +' | ';
res.render('slide/main', data);
});
app.get('/tags', function(req, res) {
var tags = fs.readFileSync(__dirname +'/source/_tags.json', 'utf8');
tags = JSON.parse(tags);
res.render('tags', { config: config, plugins: config.plugins, tags: tags });
});
app.get('/tags/:tag', function(req, res) {
var tags = fs.readFileSync(__dirname +'/source/_tags.json', 'utf8');
tags = JSON.parse(tags);
res.render('tag', { config: config, plugins: config.plugins, articles: tags[req.params.tag] });
});
app.listen(config.defaultPort);
console.log('Start at http://localhost:' + config.defaultPort);