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.

40 lines
1.3 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. console.log(requestURL);
  17. return new Promise(function(resolve, reject)
  18. {
  19. var page = request.query.page;
  20. const category = requestURL.split("/").join("");
  21. templateContext["title"] = category;
  22. sql.getPostsFromCategory(category).then(function(posts)
  23. {
  24. Promise.all([blogBodyRenderer.renderBatchOfPosts(requestURL, posts, page, 5, templateContext),
  25. require('./renderNextBar').main("/category" + request.url, page, 5, posts.length, templateContext)]).then(function()
  26. {
  27. resolve();
  28. });
  29. }).catch(function()
  30. {
  31. delete templateContext["posts"];
  32. reject();
  33. });
  34. });
  35. }
  36. };