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.

46 lines
1.2 KiB

  1. /** DB queries */
  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. * @returns {Promise|*}
  12. */
  13. main: function(requestURL, request, templateContext)
  14. {
  15. return new Promise(function(resolve, reject)
  16. {
  17. const splitURL = requestURL.split("/");
  18. //user entered /category/name/ or /category/name
  19. if(splitURL.length == 3 || splitURL.length == 4)
  20. {
  21. sql.getPost(requestURL).then(function(posts)
  22. {
  23. if(posts.length != 0)
  24. {
  25. blogBodyRenderer.renderBatchOfPosts(requestURL, posts, 1, 1, templateContext).then(function()
  26. {
  27. resolve();
  28. });
  29. }
  30. else
  31. {
  32. resolve();
  33. }
  34. })
  35. }
  36. else
  37. {
  38. //404 will print
  39. resolve();
  40. }
  41. });
  42. }
  43. };