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.

60 lines
1.5 KiB

  1. //DB query
  2. const sql = require('../utils/sql');
  3. //file IO
  4. const utils = require('../utils/utils.js');
  5. const batchPreview = require('../posts/renderBatchOfPreviewes');
  6. /**
  7. * Renders all posts in a single category
  8. *
  9. * @param resultURL
  10. * @returns {*}
  11. */
  12. const renderPosts = function(resultURL, page)
  13. {
  14. const splitURL = resultURL.split("/");
  15. if(splitURL.length >= 3)
  16. {
  17. return new Promise(function(resolve, reject)
  18. {
  19. sql.getPostsFromCategory(splitURL[2]).then(function(posts)
  20. {
  21. resolve(batchPreview.main(resultURL, posts, page, 5));
  22. }).catch(function(error)
  23. {
  24. reject(error);
  25. })
  26. });
  27. }
  28. else
  29. {
  30. reject("Page Not Found");
  31. }
  32. };
  33. module.exports=
  34. {
  35. /**
  36. * Calls posts and sidebar modules to render blog contents in order
  37. *
  38. * @param res
  39. * @param fileName request url
  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. };