-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (43 loc) · 1.38 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
new function(sourcePath, port){
var express = require('express'),
haml = require('hamljs'),
fs = require('fs'),
here = require('./heredoc'),
join = require('path').join;
var app = express.createServer();
app.register('.haml', require('hamljs'));
var root = join(__dirname, "src");
app.set('views', root);
app.set('view engine', 'haml');
app.use(express.static(root));
app.get('/', function(req, res) {
res.redirect('/index.html');
});
app.get('/index.html', function(req, res) {
var source = here.parse(fs.readFileSync(sourcePath).toString());
console.log(source);
var sources = JSON.parse(source);
var pager = haml.compile(fs.readFileSync("src/page.haml").toString());
var allsources = "";
for (var i = 0; i < sources.length; i++) {
var previousPage = "#" + ((i !== 0) ? (i - 1) : sources.length - 1);
var nextPage = "#" + ((i !== sources.length - 1) ? (i + 1): 0);
var page = sources[i];
console.log(page);
allsources += pager({
index: i.toString(),
title: page.title || "",
class: page.class || "",
body: haml.render(page.source),
previous: previousPage,
next: nextPage
});
}
res.render("layout", {
'layout': false,
'pages': allsources,
});
});
app.listen(port);
console.log("server start listening on port " + port);
}('./src/source.json', process.env.PORT || 4000);