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.

63 lines
2.0 KiB

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