2015-08-24 12:29:06 +02:00
|
|
|
//hoewerkt.js
|
|
|
|
var fs = require('fs');
|
|
|
|
var marked = require('marked');
|
|
|
|
var articles = [
|
2015-08-24 13:09:36 +02:00
|
|
|
'inleiding:Inleiding',
|
|
|
|
'moeilijkheidsgraad:Moeilijkheidsgraad',
|
|
|
|
'inhetkort:In het kort'
|
2015-08-24 12:29:06 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
module.exports = function (req, res, next) {
|
|
|
|
if (req.url == '/') {
|
|
|
|
res.render('article', render('index'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var sub = req.url.split('/')[1];
|
|
|
|
var othersub = req.url.split('/')[2] || 'makkelijk';
|
|
|
|
for (article of articles) {
|
|
|
|
if (sub == article.split(':')[0]) {
|
2015-08-24 13:06:42 +02:00
|
|
|
res.render('article', render(sub, othersub, res))
|
2015-08-24 12:29:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res.render('404');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-24 13:06:42 +02:00
|
|
|
function render(file, difficulty, res) {
|
2015-08-24 12:29:06 +02:00
|
|
|
if (file == 'index') var content = fs.readFileSync(__dirname + '/articles/index.md').toString();
|
|
|
|
else {
|
2015-08-24 13:06:42 +02:00
|
|
|
|
2015-08-24 12:29:06 +02:00
|
|
|
var files = fs.readdirSync(__dirname + '/articles/' + file.toLowerCase()).join('\n');
|
2015-08-24 13:06:42 +02:00
|
|
|
var selected = files.match(new RegExp(difficulty + '.*'));
|
|
|
|
if (!selected) res.render('404');
|
|
|
|
var content = fs.readFileSync(__dirname + '/articles/' + file + '/' + selected[0]).toString();
|
2015-08-24 12:29:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return {'markdown': marked(content), 'articles': articles}
|
|
|
|
}
|