-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
39 lines (31 loc) · 1.11 KB
/
server.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
/* global require __dirname */
var express = require('express')
, md = require('ghm').parse
, fs = require('fs')
, path = require('path')
, template = require('./lib/template')
var app = express.createServer( express.bodyParser() )
, required = {}
, oneYear = 31557600000
, contentRoot = path.resolve(__dirname ,'content')
app.use(express.favicon(__dirname + '/htdocs/favicon.ico'))
app.use(express.static(__dirname + '/htdocs' ,{ maxAge: oneYear }))
app.get( '/*?' ,function (req ,res) {
var path = split_params(req.params[0])
, filename = path[0] || '404'
, fileList = fs.readdirSync(contentRoot)
filename += '.md'
if (!fileList.some(function (el ,idx ,arr) { return el == filename })) {
filename = '404.md'
}
var content = fs.readFileSync(contentRoot + '/' + filename ,'utf8')
res.send(template( 'index' ,{ content: md(content)
, title: 'Site title'
, root: ''
} ))
})
function split_params (params) {
params = (params == undefined) ? '' : params
return params.split(/\//)
}
app.listen(8080)