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. 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. posts.forEach(function(p)
  15. {
  16. require("../posts/singlePost.js").renderPost(result, p);
  17. });
  18. }).then(function()
  19. {
  20. result.write("</div>");
  21. resolve();
  22. })
  23. });
  24. }
  25. else
  26. {
  27. return utils.print404(result);
  28. }
  29. };
  30. module.exports=
  31. {
  32. renderPostPreview: function(result, postSQLData)
  33. {
  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(res, requestURL, request)
  42. {
  43. console.log("category page");
  44. return new Promise(function(resolve, reject)
  45. {
  46. renderPosts(res, requestURL).then(function()
  47. {
  48. return require("../sidebar/sidebar.js").main(res)
  49. }).then(function ()
  50. {
  51. resolve();
  52. })
  53. });
  54. }
  55. }