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.

70 lines
1.6 KiB

  1. const utils = require('../utils/utils.js');
  2. var Promise = require('promise');
  3. var markdown = require( "markdown" ).markdown;
  4. module.exports=
  5. {
  6. /**
  7. * renderPost() displays a single blog post in it's entirety
  8. *
  9. * @param res result sent to user
  10. * @param post sql data about the blog post
  11. * @return {*|Promise}
  12. */
  13. renderPost: function(res, post)
  14. {
  15. return new Promise(function (resolve, reject)
  16. {
  17. res.write("<div class=\"w3-card-4 w3-margin w3-white\">");
  18. //image
  19. res.write("<div class=\"w3-container\">");
  20. //title
  21. res.write("<h3><b>" + post.name + "</b></h3>");
  22. //date
  23. res.write("<h5><span class=\"w3-opacity\">" + post.date + "</span></h5>");
  24. res.write("</div>");
  25. res.write("<div class=\"w3-container\">");
  26. var pathName = "entries/" + post.url + ".md";
  27. try
  28. {
  29. res.write(markdown.toHTML(utils.getFileContents(pathName)));
  30. }
  31. catch(ex)
  32. {
  33. console.log(ex);
  34. //utils.include(res, "includes/404.html");
  35. }
  36. res.write("</div></div>");
  37. resolve()
  38. });
  39. }
  40. };
  41. /*
  42. <div class="w3-card-4 w3-margin w3-white">
  43. <img src="/w3images/woods.jpg" alt="Nature" style="width:100%">
  44. <div class="w3-container">
  45. <h3><b>TITLE HEADING</b></h3>
  46. <h5>Title description, <span class="w3-opacity">Date</span></h5>
  47. </div>
  48. <div class="w3-container">
  49. content
  50. </div>
  51. </div>
  52. */