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.

58 lines
1.5 KiB

  1. /** DB query */
  2. const sql = require('../utils/sql');
  3. /** Object used to render blog post previews */
  4. const batchPreview = require('.//renderBatchOfPreviewes');
  5. /**
  6. * Renders all blog in a single category
  7. *
  8. * @param resultURL
  9. * @returns {*}
  10. */
  11. const renderPosts = function(resultURL, page)
  12. {
  13. const splitURL = resultURL.split("/");
  14. if(splitURL.length >= 3)
  15. {
  16. return new Promise(function(resolve, reject)
  17. {
  18. sql.getPostsFromCategory(splitURL[2]).then(function(posts)
  19. {
  20. resolve(batchPreview.main(resultURL, posts, page, 5));
  21. }).catch(function(error)
  22. {
  23. reject(error);
  24. })
  25. });
  26. }
  27. else
  28. {
  29. reject("Page Not Found");
  30. }
  31. };
  32. module.exports=
  33. {
  34. /**
  35. * Calls blog and sidebar modules to render blog contents in order
  36. *
  37. * @param requestURL
  38. * @param request
  39. * @returns {Promise}
  40. */
  41. main: function(requestURL, request)
  42. {
  43. return new Promise(function(resolve, reject)
  44. {
  45. var page = request.query.page;
  46. Promise.all([renderPosts(requestURL, page),
  47. require("../sidebar/sidebar.js").main()]).then(function(content)
  48. {
  49. resolve(content.join(''));
  50. }).catch(function(err)
  51. {
  52. reject(err);
  53. })
  54. });
  55. }
  56. };