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.

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