Browse Source

Updated categories page to work with the template engine.

pull/41/head
jrtechs 6 years ago
parent
commit
c19c9f77ec
2 changed files with 26 additions and 36 deletions
  1. +25
    -35
      blog/category.js
  2. +1
    -1
      blog/renderBlogPost.js

+ 25
- 35
blog/category.js View File

@ -2,35 +2,8 @@
const sql = require('../utils/sql');
/** Object used to render blog post previews */
const batchPreview = require('.//renderBatchOfPreviewes');
const blogBodyRenderer = require('./renderBlogPost');
/**
* Renders all blog in a single category
*
* @param resultURL
* @returns {*}
*/
const renderPosts = function(resultURL, page)
{
const splitURL = resultURL.split("/");
if(splitURL.length >= 3)
{
return new Promise(function(resolve, reject)
{
sql.getPostsFromCategory(splitURL[2]).then(function(posts)
{
resolve(batchPreview.main(resultURL, posts, page, 5));
}).catch(function(error)
{
reject(error);
})
});
}
else
{
reject("Page Not Found");
}
};
module.exports=
{
@ -41,19 +14,36 @@ module.exports=
* @param request
* @returns {Promise}
*/
main: function(requestURL, request)
main: function(requestURL, request, templateContext)
{
return new Promise(function(resolve, reject)
{
var page = request.query.page;
Promise.all([renderPosts(requestURL, page),
require("../sidebar/sidebar.js").main()]).then(function(content)
const splitURL = requestURL.split("/");
if(splitURL.length >= 3)
{
resolve(content.join(''));
}).catch(function(err)
sql.getPostsFromCategory(splitURL[2]).then(function(posts)
{
blogBodyRenderer.renderBatchOfPosts(requestURL, posts, page, 5, templateContext).then(function()
{
console.log("good");
resolve();
});
}).catch(function()
{
delete templateContext["posts"];
resolve();
});
}
else
{
reject(err);
})
//page is not found but, posts list will be empty
// so 404 will display
resolve();
}
});
}
};

+ 1
- 1
blog/renderBlogPost.js View File

@ -95,7 +95,7 @@ module.exports=
var markDown = utils.getFileContents(pathName).toString();
console.log(pathName);
console.log(markDown);
// console.log(markDown);
markDown = markDown.split("(media/").join("(" + "../blogContent/posts/"
+ categoryURL + "/media/");

Loading…
Cancel
Save