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.

38 lines
1.2 KiB

  1. const sql = require('../utils/sql');
  2. module.exports=
  3. {
  4. /**
  5. * Responsible for querying the database and displaying all
  6. * categories that the blog has in the sidebar
  7. *
  8. * @param res
  9. * @return {*|Promise}
  10. */
  11. main: function()
  12. {
  13. return new Promise(function(resolve, reject)
  14. {
  15. var content = "<br><br><div class=\"container\">";
  16. content += "<div class=\"list-group\">";
  17. content += " <a href=\"#\" class=\"list-group-item list-group-item-action flex-column align-items-start active\">\n" +
  18. " <h5 class=\"mb-1\">Categories</h5>\n" +
  19. " </a>";
  20. sql.getCategories().then(function(categories)
  21. {
  22. categories.forEach(function(cat)
  23. {
  24. content += "<a class=\"list-group-item\" href='/category/" + cat.url + "'>" + cat.name + "<br></a>";
  25. });
  26. content += "</div></div><br>";
  27. resolve(content);
  28. }).catch(function(error)
  29. {
  30. reject(error);
  31. });
  32. });
  33. }
  34. };