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.

52 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("<img src=\"https://www.w3schools.com/w3images/woods.jpg\" alt=\"Nature\" style=\"width:100%\">");
  20. res.write("<div class=\"w3-container\">");
  21. //title
  22. res.write("<h3><b>" + post.name + "</b></h3>");
  23. //date
  24. res.write("<h5><span class=\"w3-opacity\">" + post.published.toDateString() + "</span></h5>");
  25. res.write("</div>");
  26. res.write("<div class=\"w3-container\">");
  27. var pathName = "entries/" + post.url + ".md";
  28. try
  29. {
  30. var html = markdown.toHTML(utils.getFileContents(pathName).toString());
  31. html = html.split("<code>").join("<pre><code>");
  32. html = html.split("</code>").join("</code></pre>");
  33. res.write(html);
  34. }
  35. catch(ex)
  36. {
  37. //console.log(ex);
  38. //utils.include(res, "includes/404.html");
  39. }
  40. res.write("</div></div>");
  41. resolve()
  42. });
  43. }
  44. };