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.

66 lines
1.7 KiB

  1. const sql = require('../utils/sql');
  2. const TEMPLATE_FILE = "blog/sideBar.html";
  3. const includes = require('../includes/includes.js');
  4. const getInformationForRecentPosts = function(templateContext)
  5. {
  6. return new Promise(function(resolve, reject)
  7. {
  8. sql.getRecentPosts().then(function(posts)
  9. {
  10. posts.forEach(function(p)
  11. {
  12. p.url = '/' + p.category + '/' + p.url;
  13. });
  14. templateContext.recentPosts = posts;
  15. resolve();
  16. }).catch(function(error)
  17. {
  18. reject(error);
  19. })
  20. });
  21. };
  22. const getInformationForCategories = function(templateContext)
  23. {
  24. return new Promise(function(resolve, reject)
  25. {
  26. sql.getCategories().then(function(categories)
  27. {
  28. categories.forEach(function(cat)
  29. {
  30. cat.url = "/category/" + cat.url;
  31. });
  32. templateContext.categories = categories;
  33. resolve();
  34. }).catch(function(error)
  35. {
  36. reject(error);
  37. });
  38. });
  39. };
  40. module.exports=
  41. {
  42. main: function(templateContext)
  43. {
  44. return new Promise(function(resolve, reject)
  45. {
  46. Promise.all([includes.fetchTemplate(TEMPLATE_FILE),
  47. getInformationForRecentPosts(templateContext),
  48. getInformationForCategories(templateContext)])
  49. .then(function(content)
  50. {
  51. templateContext.sideBar = content[0];
  52. resolve();
  53. }).catch(function(error)
  54. {
  55. reject(error);
  56. });
  57. })
  58. }
  59. };