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.

74 lines
1.9 KiB

  1. var Promise = require('promise');
  2. const sql = require('../utils/sql');
  3. const utils = require('../utils/utils.js');
  4. var renderPosts = function(result, resultURL)
  5. {
  6. var splitURL = resultURL.split("/");
  7. if(splitURL.length >= 3)
  8. {
  9. result.write("<div class=\"w3-col l8 s12\">\n");
  10. return new Promise(function(resolve, reject)
  11. {
  12. sql.getPostsFromCategory(splitURL[2]).then(function(posts)
  13. {
  14. var promises = [];
  15. posts.forEach(function(p)
  16. {
  17. promises.push(new Promise(function(res, rej)
  18. {
  19. require("../posts/singlePost.js")
  20. .renderPost(result, p)
  21. .then(function()
  22. {
  23. res();
  24. });
  25. }));
  26. });
  27. return Promise.all(promises);
  28. }).then(function()
  29. {
  30. result.write("</div>");
  31. resolve();
  32. }).catch(function(err)
  33. {
  34. console.log(err);
  35. })
  36. });
  37. }
  38. else
  39. {
  40. return utils.print404(result);
  41. }
  42. };
  43. module.exports=
  44. {
  45. renderPostPreview: function(result, postSQLData)
  46. {
  47. },
  48. /**
  49. * Calls posts and sidebar modules to render blog contents in order
  50. *
  51. * @param res
  52. * @param fileName request url
  53. */
  54. main: function(res, requestURL, request)
  55. {
  56. console.log("category page");
  57. return new Promise(function(resolve, reject)
  58. {
  59. renderPosts(res, requestURL).then(function()
  60. {
  61. return require("../sidebar/sidebar.js").main(res)
  62. }).then(function ()
  63. {
  64. resolve();
  65. })
  66. });
  67. }
  68. }