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.

47 lines
1.1 KiB

  1. const routes = require('express').Router();
  2. const pageBuilder = require('../../utils/pageBuilder');
  3. const utils = require('../../utils/utils');
  4. const whiskers = require('whiskers');
  5. const url = require('url');
  6. const fs = require('fs');
  7. routes.get('/', (request, result) =>
  8. {
  9. //do something later
  10. });
  11. const photosBaseDir = "blogContent/photos";
  12. photoPageBuilder = function(filename, request, templateContext)
  13. {
  14. if(fs.existsSync(photosBaseDir + filename))
  15. {
  16. templateContext.images = [];
  17. var imagePath = "/" + photosBaseDir + filename + "/";
  18. fs.readdirSync(photosBaseDir + filename).forEach(file=>
  19. {
  20. if(file.includes('.jpg')) //doesn't pick up mark down files
  21. {
  22. templateContext.images.push({full:imagePath+ file,
  23. preview:imagePath + "preview/" + file});
  24. }
  25. });
  26. }
  27. else
  28. {
  29. templateContext.error = true;
  30. }
  31. };
  32. routes.get('*', (request, result) =>
  33. {
  34. pageBuilder.buildPageWithTemplate(request, result,
  35. photoPageBuilder, "photos/photosEntry.html");
  36. });
  37. module.exports = routes;