const fs = require('fs') module.exports = function compile(page, fn){ switch(page.type){ case 'md': compileMD(page.file, fn) break; default: fn(-2) } } /* ============================================================= * === Markdown ================================================ * ============================================================= */ const showdown = require('showdown') const MDCompile = new showdown.Converter({tables: true}) function compileMD(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 = MDCompile.makeHtml(markdown); if(typeof fn == 'function') fn(html) else fs.writeFile(fn, html, function(err){ if(err) console.error(err) }) }) }