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.

37 lines
1.2 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. * @returns {*|Promise}
  8. */
  9. main: function()
  10. {
  11. return new Promise(function(resolve, reject)
  12. {
  13. var content = "<div class=\"container\">";
  14. content +="<div class=\"list-group\">";
  15. content +=" <a href=\"#\" class=\"list-group-item list-group-item-action flex-column align-items-start active\">\n" +
  16. " <h5 class=\"mb-1\">Recent Posts</h5>\n" +
  17. " </a>";
  18. sql.getRecentPosts().then(function(posts)
  19. {
  20. posts.forEach(function(p)
  21. {
  22. var url = '/' + p.category + '/' + p.url;
  23. content += "<a class=\"list-group-item\" href='"
  24. + url + "'>" + p.name + "<br></a>";
  25. });
  26. content +="</div></div>";
  27. resolve(content);
  28. }).catch(function(error)
  29. {
  30. reject(error);
  31. })
  32. });
  33. }
  34. };