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.

79 lines
1.9 KiB

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