53 lines
1.2 KiB
JavaScript
Executable File
53 lines
1.2 KiB
JavaScript
Executable File
const showdown = require('showdown')
|
|
const express = require('express')
|
|
const fs = require('fs')
|
|
|
|
const converter = new showdown.Converter({tables: true})
|
|
|
|
function compileFile(file, fn){
|
|
fs.readFile(file, 'utf-8', function(err, markdown){
|
|
if(err){
|
|
console.error("ERROR: could not read file:", file)
|
|
if(typeof fn == 'function')
|
|
fn(-1)
|
|
}
|
|
html = converter.makeHtml(markdown);
|
|
if(typeof fn == 'function')
|
|
fn(html)
|
|
else
|
|
fs.writeFile(fn, html, function(err){
|
|
if(err)
|
|
console.error(err)
|
|
})
|
|
})
|
|
}
|
|
|
|
function compileDir(source, target){
|
|
fs.readdir(source, function(err, files){
|
|
for(f in files){
|
|
if(files[f].substr(-3) != '.md'){
|
|
continue
|
|
}
|
|
t = target + '/' + files[f].substr(0, files[f].length-2) + 'html'
|
|
compileFile(source + '/' + files[f], t)
|
|
}
|
|
})
|
|
}
|
|
|
|
compileDir('markdown', "html")
|
|
|
|
const app = express()
|
|
app.set('view engine', 'ejs');
|
|
app.set('views', __dirname + '/html')
|
|
|
|
app.get('/logboek/:lab', function(req, res, next){
|
|
res.render('logboek', { lab: req.params.lab})
|
|
})
|
|
|
|
app.use('/img', function(req, res, next){
|
|
res.sendFile(__dirname + '/img' + req.path)
|
|
})
|
|
|
|
|
|
app.listen(8080, ()=>console.log("server started"))
|