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.

48 lines
1.5 KiB

  1. /** DB query */
  2. const sql = require('../utils/sql');
  3. /** Object used to render blog post previews */
  4. const blogBodyRenderer = require('./renderBlogPost');
  5. module.exports=
  6. {
  7. /**
  8. * Calls blog and sidebar modules to render blog contents in order
  9. *
  10. * @param requestURL
  11. * @param request
  12. * @returns {Promise}
  13. */
  14. main: function(requestURL, request, templateContext)
  15. {
  16. return new Promise(function(resolve, reject)
  17. {
  18. var page = request.query.page;
  19. const splitURL = requestURL.split("/");
  20. if(splitURL.length >= 3)
  21. {
  22. sql.getPostsFromCategory(splitURL[2]).then(function(posts)
  23. {
  24. Promise.all([blogBodyRenderer.renderBatchOfPosts(requestURL, posts, page, 5, templateContext),
  25. require('./renderNextBar').main(requestURL, page, 5, posts.length, templateContext)]).then(function()
  26. {
  27. resolve();
  28. });
  29. }).catch(function()
  30. {
  31. delete templateContext["posts"];
  32. resolve();
  33. });
  34. }
  35. else
  36. {
  37. //page is not found but, posts list will be empty
  38. // so 404 will display
  39. resolve();
  40. }
  41. });
  42. }
  43. };