From ac8aca4f9da09d00b91ca8d2d2336ad9ac252fd7 Mon Sep 17 00:00:00 2001 From: jrtechs Date: Sun, 7 Oct 2018 11:46:17 -0400 Subject: [PATCH] Documented the new code and fixed a bug with the table of contents. --- posts/singlePost.js | 3 +- .../{markdownToHTML.js => renderBlogPost.js} | 44 +++++++++++++++++-- 2 files changed, 42 insertions(+), 5 deletions(-) rename utils/{markdownToHTML.js => renderBlogPost.js} (74%) diff --git a/posts/singlePost.js b/posts/singlePost.js index 452fdc5..97ef5c7 100644 --- a/posts/singlePost.js +++ b/posts/singlePost.js @@ -1,5 +1,4 @@ -const postGenerator = require('../utils/markdownToHTML.js'); - +const postGenerator = require('../utils/renderBlogPost.js'); module.exports= diff --git a/utils/markdownToHTML.js b/utils/renderBlogPost.js similarity index 74% rename from utils/markdownToHTML.js rename to utils/renderBlogPost.js index 60ee0a0..45d3898 100644 --- a/utils/markdownToHTML.js +++ b/utils/renderBlogPost.js @@ -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 = "
"; //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("
").join("
"); @@ -67,7 +93,7 @@ module.exports= if(blocks == -1) resolve(result); - var htmlBlocks = result.split("

"); + const htmlBlocks = result.split("

"); 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 "



"; }, + /** + * Converts markdown into html. + * + * @param markdownContents + * @param type + * @returns {Promise} + */ convertToHTML: function(markdownContents, type) { return new Promise(function(resolve, reject)