diff --git a/includes/contact.js b/blog/contact.js similarity index 87% rename from includes/contact.js rename to blog/contact.js index d4cfe75..0caa03d 100644 --- a/includes/contact.js +++ b/blog/contact.js @@ -38,6 +38,10 @@ const CAPTCHA_SECRET = config.CAPTCHA_SECRET; const EMAIL_PASSWORD = config.EMAIL_PASSWORD; +const TEMPLATE_FILE = "blog/contact.html"; +const whiskers = require('whiskers'); + + /** * Verifies if the captcha response recieved from the post data was * valid, or are bots trying to get around the captcha @@ -142,7 +146,7 @@ const sendEmail = function(name, email, message) * @param request -- main express request * @returns {Promise} renders the html of the contact widget */ -const processContactPage = function(request) +const processContactPage = function(request, templateContext) { return new Promise(function(resolve, reject) { @@ -161,21 +165,22 @@ const processContactPage = function(request) { if(valid) { - resolve(utils.include("includes/html/messageSent.html")); - + templateContext.messageSent = true; + resolve(); sendEmail(data.name, data.email, data.message); } else { - resolve(utils.include("includes/html/invalidCaptcha.html")); + resolve(); } }); } else { - resolve(utils.include("includes/html/contact.html")); + resolve(); } + }).catch(function(err) { reject(err); @@ -198,12 +203,18 @@ module.exports = main: function(request, result) { result.writeHead(200, {'Content-Type': 'text/html'}); - Promise.all([includes.printAdminHeader(), + + console.log("eh"); + var templateContext = Object(); + Promise.all([includes.fetchTemplate(TEMPLATE_FILE), processContactPage(request), - require("../sidebar/sidebar.js").main(), - includes.printFooter()]).then(function(content) + includes.printHeader(templateContext), + includes.printFooter(templateContext), + require("./sidebar.js").main(templateContext)]) + .then(function (content) { - result.write(content.join('')); + const html = whiskers.render(content[0], templateContext); + result.write(html); result.end(); }).catch(function(err) diff --git a/sidebar/sidebar.js b/blog/sidebar.js similarity index 100% rename from sidebar/sidebar.js rename to blog/sidebar.js diff --git a/includes/html/contact.html b/includes/html/contact.html deleted file mode 100644 index 3bdd82d..0000000 --- a/includes/html/contact.html +++ /dev/null @@ -1,74 +0,0 @@ -