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.

86 lines
2.4 KiB

  1. const routes = require('express').Router();
  2. const pageBuilder = require('../../utils/pageBuilder');
  3. const renderBlogPost = require('../../blog/renderBlogPost');
  4. const utils = require('../../utils/utils');
  5. const whiskers = require('whiskers');
  6. const url = require('url');
  7. const fs = require('fs');
  8. routes.get('/', (request, result) =>
  9. {
  10. //do something later
  11. result.write("Not implemented yet.");
  12. result.end();
  13. });
  14. const photosBaseDir = "blogContent/photos";
  15. photoPageBuilder = function(filename, request, templateContext)
  16. {
  17. const imagePath = "/" + photosBaseDir + filename + "/";
  18. return new Promise((resolve, reject)=>
  19. {
  20. if(fs.existsSync(photosBaseDir + filename + "/post.md"))
  21. {
  22. var markdownContent = utils.getFileContents(
  23. photosBaseDir + filename + "/post.md");
  24. renderBlogPost.pandocWrapper(markdownContent, "-t html5")
  25. .then((html)=>
  26. {
  27. templateContext.images = [];
  28. templateContext.mainPost = html;
  29. fs.readdirSync(photosBaseDir + filename).forEach(file=>
  30. {
  31. if(file.includes('.jpg')) //doesn't pick up mark down files
  32. {
  33. templateContext.images.push({full:imagePath+ file,
  34. preview:imagePath + "preview/" + file});
  35. }
  36. });
  37. resolve();
  38. }).catch((error)=>
  39. {
  40. reject(error);
  41. })
  42. }
  43. else if(fs.existsSync(photosBaseDir + filename + "/dir.md"))
  44. {
  45. templateContext.folders = [];
  46. templateContext.directory = true;
  47. fs.readdirSync(photosBaseDir + filename).forEach(file=>
  48. {
  49. if(!file.includes('.md') && !file.includes('.jpg')) //only pick up folders
  50. {
  51. templateContext.folders.push({url: "/photos" + filename + "/" + file,
  52. img:imagePath + file + "/1.jpg"});
  53. }
  54. });
  55. resolve();
  56. }
  57. else
  58. {
  59. templateContext.error = true;
  60. resolve();
  61. }
  62. })
  63. };
  64. routes.get('*', (request, result) =>
  65. {
  66. pageBuilder.buildPageWithTemplate(request, result,
  67. photoPageBuilder, "photos/photosEntry.html");
  68. });
  69. module.exports = routes;