Browse Source

Documented the new code and fixed a bug with the table of contents.

pull/5/head
jrtechs 6 years ago
parent
commit
ac8aca4f9d
2 changed files with 42 additions and 5 deletions
  1. +1
    -2
      posts/singlePost.js
  2. +41
    -3
      utils/renderBlogPost.js

+ 1
- 2
posts/singlePost.js View File

@ -1,5 +1,4 @@
const postGenerator = require('../utils/markdownToHTML.js');
const postGenerator = require('../utils/renderBlogPost.js');
module.exports=

utils/markdownToHTML.js → utils/renderBlogPost.js View File

@ -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)

Loading…
Cancel
Save