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.

39 lines
1.3 KiB

  1. const Promise = require('promise');
  2. const sql = require('../utils/sql');
  3. module.exports=
  4. {
  5. /** Renders the the recent post sidebar.
  6. *
  7. * @param res
  8. * @returns {*|Promise}
  9. */
  10. main: function(res)
  11. {
  12. return new Promise(function(resolve, reject)
  13. {
  14. res.write("<div class=\"container\">");
  15. // res.write("<div class=\"\">" +
  16. // "<h4 class=\"text-center\">Recent Posts</h4></div>");
  17. res.write("<div class=\"list-group\">");
  18. res.write(" <a href=\"#\" class=\"list-group-item list-group-item-action flex-column align-items-start active\">\n" +
  19. " <h5 class=\"mb-1\">Recent Posts</h5>\n" +
  20. " </a>");
  21. sql.getRecentPosts().then(function(posts)
  22. {
  23. posts.forEach(function(p)
  24. {
  25. var url = '/' + p.category + '/' + p.url;
  26. res.write("<a class=\"list-group-item\" href='"
  27. + url + "'>" + p.name + "<br></a>");
  28. });
  29. res.write("</div></div>");
  30. resolve();
  31. })
  32. });
  33. }
  34. };