Personal blog written from scratch using Node.js, Bootstrap, and MySQL. https://jrtechs.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.7 KiB

  1. module.exports=
  2. {
  3. /**
  4. * Calls posts and sidebar modules to render blog contents in order
  5. *
  6. * @param res
  7. * @param fileName request url
  8. */
  9. main: function(baseURL, posts, currentPage, numOfPosts)
  10. {
  11. if(typeof currentPage == "undefined")
  12. {
  13. currentPage = 1;
  14. }
  15. else
  16. {
  17. currentPage = Number(currentPage);
  18. }
  19. return new Promise(function(resolve, reject)
  20. {
  21. const promises = [];
  22. for(var i = (currentPage-1) * numOfPosts; i < (currentPage-1) * numOfPosts + numOfPosts; i++)
  23. {
  24. if(i < posts.length)
  25. {
  26. promises.push(new Promise(function(res, rej)
  27. {
  28. require("../posts/singlePost.js")
  29. .renderPreview(posts[i]).then(function(html)
  30. {
  31. res(html);
  32. }).catch(function(error)
  33. {
  34. rej(error);
  35. })
  36. }));
  37. }
  38. }
  39. promises.push(require('../posts/renderNextBar').main(baseURL, currentPage, numOfPosts, posts.length));
  40. Promise.all(promises).then(function(content)
  41. {
  42. resolve("<div class='col-md-8'>" + content.join('') + "</div>");
  43. }).catch(function(error)
  44. {
  45. reject(error);
  46. });
  47. });
  48. }
  49. };