|
|
@ -11,6 +11,15 @@ 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) |
|
|
@ -20,13 +29,22 @@ module.exports= |
|
|
|
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 = "<div class=\"blogPost\">"; |
|
|
|
//image
|
|
|
|
if(!(post.picture_url === "n/a")) |
|
|
@ -47,6 +65,14 @@ module.exports= |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Method which renders the body of the blog post. This is responsible for getting |
|
|
|
* the contents of the markdown/latex file and rendering it into beautiful html. |
|
|
|
* |
|
|
|
* @param post |
|
|
|
* @param blocks |
|
|
|
* @returns {Promise} |
|
|
|
*/ |
|
|
|
generateBlogPostBody: function(post, blocks) |
|
|
|
{ |
|
|
|
return new Promise(function(resolve, reject) |
|
|
@ -59,7 +85,7 @@ module.exports= |
|
|
|
markDown = markDown.split("(media/").join("(" + "../blogContent/posts/" |
|
|
|
+ category[0].url + "/media/"); |
|
|
|
|
|
|
|
module.exports.convertToHTML(markDown, 1).then(function(result) |
|
|
|
module.exports.convertToHTML(markDown, blocks).then(function(result) |
|
|
|
{ |
|
|
|
|
|
|
|
result = result.split("<figcaption>").join("<figcaption style=\"visibility: hidden;\">"); |
|
|
@ -67,7 +93,7 @@ module.exports= |
|
|
|
if(blocks == -1) |
|
|
|
resolve(result); |
|
|
|
|
|
|
|
var htmlBlocks = result.split("<p>"); |
|
|
|
const htmlBlocks = result.split("<p>"); |
|
|
|
var html = ""; |
|
|
|
for(var i = 0; i < blocks; i++) |
|
|
|
{ |
|
|
@ -92,11 +118,23 @@ module.exports= |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** Method to return the footer of the html blog post. |
|
|
|
* |
|
|
|
* @returns {string} |
|
|
|
*/ |
|
|
|
generateBlogPostFooter: function() |
|
|
|
{ |
|
|
|
return "</div></div></div><br><br>"; |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Converts markdown into html. |
|
|
|
* |
|
|
|
* @param markdownContents |
|
|
|
* @param type |
|
|
|
* @returns {Promise} |
|
|
|
*/ |
|
|
|
convertToHTML: function(markdownContents, type) |
|
|
|
{ |
|
|
|
return new Promise(function(resolve, reject) |