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.

41 lines
1.4 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. templateContext["categoryID"] = posts[0].category_id;
  25. Promise.all([blogBodyRenderer.renderBatchOfPosts(requestURL, posts, page, 5, templateContext),
  26. require('./renderNextBar').main("/category" + request.url, page, 5, posts.length, templateContext)]).then(function()
  27. {
  28. resolve();
  29. });
  30. }).catch(function()
  31. {
  32. delete templateContext["posts"];
  33. reject();
  34. });
  35. });
  36. }
  37. };