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.
 
 

68 lines
1.8 KiB

const routes = require('express').Router();
const pageBuilder = require('../../utils/pageBuilder');
const renderBlogPost = require('../../blog/renderBlogPost');
const utils = require('../../utils/utils');
const whiskers = require('whiskers');
const url = require('url');
const fs = require('fs');
routes.get('/', (request, result) =>
{
//do something later
});
const photosBaseDir = "blogContent/photos";
photoPageBuilder = function(filename, request, templateContext)
{
return new Promise((resolve, reject)=>
{
if(fs.existsSync(photosBaseDir + filename + "/post.md"))
{
var markdownContent = utils.getFileContents(
photosBaseDir + filename + "/post.md");
renderBlogPost.pandocWrapper(markdownContent, "-t html5")
.then((html)=>
{
templateContext.images = [];
templateContext.mainPost = html;
var imagePath = "/" + photosBaseDir + filename + "/";
fs.readdirSync(photosBaseDir + filename).forEach(file=>
{
if(file.includes('.jpg')) //doesn't pick up mark down files
{
templateContext.images.push({full:imagePath+ file,
preview:imagePath + "preview/" + file});
}
});
resolve();
}).catch((error)=>
{
reject(error);
})
}
else
{
templateContext.error = true;
resolve();
}
})
};
routes.get('*', (request, result) =>
{
pageBuilder.buildPageWithTemplate(request, result,
photoPageBuilder, "photos/photosEntry.html");
});
module.exports = routes;