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.

45 lines
1.2 KiB

  1. const sql = require('../utils/sql');
  2. const batchPreview = require('../posts/renderBatchOfPreviewes');
  3. /**Renders each recent post for the homepage of the website
  4. *
  5. * @param result
  6. * @returns {*|Promise}
  7. */
  8. var renderRecentPosts = function(baseURL, page)
  9. {
  10. return new Promise(function(resolve, reject)
  11. {
  12. sql.getRecentPostSQL().then(function(posts)
  13. {
  14. resolve(batchPreview.main(baseURL, posts, page, 5));
  15. }).catch(function(error)
  16. {
  17. reject(error);
  18. })
  19. });
  20. };
  21. module.exports=
  22. {
  23. /**
  24. * Renders the previews of recent blog posts and the side bar
  25. *
  26. * @param res
  27. * @param fileName request url
  28. */
  29. main: function(requestURL, request)
  30. {
  31. var page = request.query.page;
  32. return new Promise(function(resolve, reject)
  33. {
  34. Promise.all([renderRecentPosts(requestURL, page), require("../sidebar/sidebar.js").main()]).then(function(content)
  35. {
  36. resolve(content.join(''));
  37. }).catch(function(error)
  38. {
  39. reject(error);
  40. });
  41. })
  42. }
  43. };