const utils = require('../utils/utils.js'); var Promise = require('promise'); var markdown = require( "markdown" ).markdown; const sql = require('../utils/sql'); module.exports= { /** * renderPost() displays a single blog post in it's entirety * * @param res result sent to user * @param post sql data about the blog post * @return {*|Promise} */ renderPost: function(res, post) { return new Promise(function (resolve, reject) { res.write("
"); //image if(!(post.picture_url ==="n/a")) { res.write("\"Nature\""); } res.write("
"); //title res.write("

" + post.name + "

"); //date res.write("
" + post.published.toDateString() + "
"); res.write("
"); res.write("
"); try { sql.getCategory(post.category_id).then(function(category) { var pathName = "entries/" + category.url + "/" + post.url + ".md"; var html = markdown.toHTML(utils.getFileContents(pathName).toString()); html = html.split("").join("
");
                    html = html.split("").join("
"); html = html.split("\\`\\`\\`").join("```"); html = html.split("![](media/").join("![](" + "entries/" + category.url + "/media/"); res.write(html); res.write("
"); resolve() }); } catch(ex) { //console.log(ex); //utils.include(res, "includes/404.html"); } }); } };