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.

76 lines
2.0 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. console.log(posts);
  16. console.log("^^^^");
  17. posts.forEach(function(p)
  18. {
  19. promises.push(new Promise(function(res, rej)
  20. {
  21. require("../posts/singlePost.js")
  22. .renderPost(result, p)
  23. .then(function()
  24. {
  25. res();
  26. });
  27. }));
  28. });
  29. return Promise.all(promises);
  30. }).then(function()
  31. {
  32. result.write("</div>");
  33. resolve();
  34. }).catch(function(err)
  35. {
  36. console.log(err);
  37. })
  38. });
  39. }
  40. else
  41. {
  42. return utils.print404(result);
  43. }
  44. };
  45. module.exports=
  46. {
  47. renderPostPreview: function(result, postSQLData)
  48. {
  49. },
  50. /**
  51. * Calls posts and sidebar modules to render blog contents in order
  52. *
  53. * @param res
  54. * @param fileName request url
  55. */
  56. main: function(res, requestURL, request)
  57. {
  58. console.log("category page");
  59. return new Promise(function(resolve, reject)
  60. {
  61. renderPosts(res, requestURL).then(function()
  62. {
  63. return require("../sidebar/sidebar.js").main(res)
  64. }).then(function ()
  65. {
  66. resolve();
  67. })
  68. });
  69. }
  70. }