diff --git a/public/templates/header.tpl b/public/templates/header.tpl index b193223431..0c7ae37264 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -1,7 +1,7 @@ - {title} + {browserTitle} {meta_tags} diff --git a/src/routes/authentication.js b/src/routes/authentication.js index b03bce015e..19ac5345df 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -87,7 +87,9 @@ console.log('info: [Auth] Session ' + req.sessionID + ' logout (uid: ' + global.uid + ')'); login_module.logout(req.sessionID, function(logout) { req.logout(); - res.send(app.build_header({ req: req, res: res }) + templates['logout'] + templates['footer']); + app.build_header({ req: req, res: res }, function(header) { + res.send(header + templates['logout'] + templates['footer']); + }); }); }); @@ -121,11 +123,15 @@ app.get('/reset/:code', function(req, res) { - res.send(app.build_header({ req: req, res: res }) + templates['reset_code'].parse({ reset_code: req.params.code }) + templates['footer']); + app.build_header({ req: req, res: res }, function(header) { + res.send(header + templates['reset_code'].parse({ reset_code: req.params.code }) + templates['footer']); + }); }); app.get('/reset', function(req, res) { - res.send(app.build_header({ req: req, res: res }) + templates['reset'] + templates['footer']); + app.build_header({ req: req, res: res }, function(header) { + res.send(header + templates['reset'] + templates['footer']); + }); }); diff --git a/src/webserver.js b/src/webserver.js index 9ad69d6fcf..b0c99695da 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -26,7 +26,11 @@ var express = require('express'), (function(app) { var templates = null; - app.build_header = function(options) { + /** + * `options` object requires: req, res + * accepts: metaTags + */ + app.build_header = function(options, callback) { var defaultMetaTags = [ { name: 'viewport', content: 'width=device-width, initial-scale=1.0' }, { name: 'content-type', content: 'text/html; charset=UTF-8' }, @@ -41,11 +45,11 @@ var express = require('express'), meta_tags: metaString }; - // meta.build_title(options.title, (options.req.user ? options.req.user.uid : 0), function(err, title) { - // if (!err) templateValues.title = title; - // }); + meta.build_title(options.title, (options.req.user ? options.req.user.uid : 0), function(err, title) { + if (!err) templateValues.browserTitle = title; - return templates['header'].parse(templateValues); + callback(null, templates['header'].parse(templateValues)); + }); }; // Middlewares @@ -159,7 +163,9 @@ var express = require('express'), return; } - res.send(app.build_header({ req: req, res: res }) + app.create_route(route) + templates['footer']); + app.build_header({ req: req, res: res }, function(err, header) { + res.send(header + app.create_route(route) + templates['footer']); + }); }); }(routes[i])); } @@ -167,14 +173,23 @@ var express = require('express'), app.get('/', function(req, res) { - categories.getAllCategories(function(returnData) { + async.parallel({ + "header": function(next) { + app.build_header({ req: req, res: res }, next); + }, + "categories": function(next) { + categories.getAllCategories(function(returnData) { + next(null, returnData); + }, 0); + } + }, function(err, data) { res.send( - app.build_header({ req: req, res: res }) + - '\n\t' + + data.header + + '\n\t' + app.create_route('') + templates['footer'] ); - }, 0); + }) }); @@ -196,18 +211,20 @@ var express = require('express'), topics.getTopicWithPosts(tid, ((req.user) ? req.user.uid : 0), function(err, topic) { if (err) return res.redirect('404'); - res.send( - app.build_header({ - req: req, - res: res, - metaTags: [ - { name: "title", content: topic.topic_name } - ] - }) + - '\n\t' + - '\n\t' + - templates['footer'] - ); + app.build_header({ + req: req, + res: res, + metaTags: [ + { name: "title", content: topic.topic_name } + ] + }, function(header) { + res.send( + header + + '\n\t' + + '\n\t' + + templates['footer'] + ); + }); }); }); @@ -230,24 +247,28 @@ var express = require('express'), categories.getCategoryById(cid, 0, function(err, returnData) { if(err) return res.redirect('404'); - res.send( - app.build_header({ - req: req, - res: res, - metaTags: [ - { name: 'title', content: returnData.category_name }, - { name: 'description', content: returnData.category_description } - ] - }) + - '\n\t' + - '\n\t' + - templates['footer'] - ); + app.build_header({ + req: req, + res: res, + metaTags: [ + { name: 'title', content: returnData.category_name }, + { name: 'description', content: returnData.category_description } + ] + }, function(header) { + res.send( + header + + '\n\t' + + '\n\t' + + templates['footer'] + ); + }); }); }); app.get('/confirm/:code', function(req, res) { - res.send(app.build_header({ req: req, res: res }) + '' + templates['footer']); + app.build_header({ req: req, res: res }, function(header) { + res.send(header + '' + templates['footer']); + }); }); app.get('/sitemap.xml', function(req, res) { @@ -303,10 +324,12 @@ var express = require('express'), var url = req.url.split('?'); if (url[1]) { - res.send(app.build_header({ req: req, res: res }) + templates['outgoing'].parse({ - url: url[1], - home: global.nconf.get('url') - }) + templates['footer']); + app.build_header({ req: req, res: res }, function(header) { + res.send(header + templates['outgoing'].parse({ + url: url[1], + home: global.nconf.get('url') + }) + templates['footer']); + }); } else { res.status(404); res.redirect(global.nconf.get('relative_path') + '/404');