From 17b6a0a47fb02dcda221f31cd7fb5f72b43b1a3b Mon Sep 17 00:00:00 2001 From: fatchan Date: Mon, 6 May 2019 12:01:58 +0000 Subject: [PATCH] add helper to render pug template to html file --- gulpfile.js | 2 +- helpers/writepagehtml.js | 14 ++++++++++++++ models/pages/home.js | 6 ++---- 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 helpers/writepagehtml.js diff --git a/gulpfile.js b/gulpfile.js index 49923c0f..d8792493 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -12,7 +12,7 @@ const paths = { }, images: { src: 'gulp/res/img/*', - dest: 'uploads/img/' + dest: 'static/img/' }, scripts: { src: 'gulp/res/js/*.js', diff --git a/helpers/writepagehtml.js b/helpers/writepagehtml.js new file mode 100644 index 00000000..0ca1bc46 --- /dev/null +++ b/helpers/writepagehtml.js @@ -0,0 +1,14 @@ +'use strict'; + +const util = require('util') + , fs = require('fs') + , pug = require('pug') + , path = require('path') + , writeFile = util.promisify(fs.writeFile) + , uploadDirectory = require(__dirname+'/uploadDirectory.js') + , pugDirectory = path.join(__dirname+'/../views/pages'); + +module.exports = async (htmlName, pugName, pugVars) => { + const html = pug.renderFile(`${pugDirectory}/${pugName}`, pugVars); + return writeFile(`${uploadDirectory}/htmlName`, html); +}; diff --git a/models/pages/home.js b/models/pages/home.js index cdddc7ba..f6f54c66 100644 --- a/models/pages/home.js +++ b/models/pages/home.js @@ -12,8 +12,6 @@ module.exports = async (req, res, next) => { return next(err); } - //render the page - res.render('home', { - boards: boards - }); + res.render('home', { boards }); + }