const pandoc = require('node-pandoc'); const utils = require('../utils/utils.js'); const sql = require('../utils/sql'); const argsFull = '-S --base-header-level=1 --toc --toc-depth=3 -N --normalize -s --mathjax -t html5'; const argsPreview = '-S --normalize -s --mathjax -t html5'; module.exports= { /** * Renders the entire blog post based on the sql data pulled * from the database. * * @param post sql data which has title, date, and header img location * @param blocks number of blocks to display for a preview or -1 for * all the blocks * @returns {Promise} async call which renders the entire blog post. */ generateBlogPost: function(post, blocks) { return new Promise(function(resolve, reject) { Promise.all([module.exports.generateBlogPostHeader(post), module.exports.generateBlogPostBody(post, blocks), module.exports.generateBlogPostFooter()]).then(function(content) { resolve(content.join('')); }).catch(function(error) { reject(error); }) }); }, /** * Renders the header of the blog post which contains the header image, and date * published. * * @param post sql data * @returns {string} */ generateBlogPostHeader: function(post) { var htmlHead = "
"); var html = ""; for(var i = 0; i < blocks; i++) { html += "
" + htmlBlocks[i]; } html += "
");
resolve(html);
};
if(type == -1)
{
pandoc(markdownContents, argsFull, callback);
}
else
{
pandoc(markdownContents, argsPreview, callback);
}
});
},
}