refactored all calls to app.build_header (in regular and auth routes)

v1.18.x
Julian Lam 12 years ago
parent d6938f4818
commit 4588745b9a

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>{title}</title>
<title>{browserTitle}</title>
{meta_tags}
<link href="{cssSrc}" rel="stylesheet" media="screen">
<link href="{relative_path}/vendor/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">

@ -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']);
});
});

@ -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) {
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<noscript>\n' + templates['noscript/header'] + templates['noscript/home'].parse(returnData) + '\n\t</noscript>' +
data.header +
'\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/home'].parse(data.categories) + '\n\t</noscript>' +
app.create_route('') +
templates['footer']
);
}, 0);
})
});
@ -196,20 +211,22 @@ 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 }
]
}) +
}, function(header) {
res.send(
header +
'\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/topic'].parse(topic) + '\n\t</noscript>' +
'\n\t<script>templates.ready(function(){ajaxify.go("topic/' + topic_url + '");});</script>' +
templates['footer']
);
});
});
});
app.get('/category/:category_id/:slug?', function(req, res) {
var cid = req.params.category_id;
@ -230,7 +247,6 @@ 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,
@ -238,16 +254,21 @@ var express = require('express'),
{ name: 'title', content: returnData.category_name },
{ name: 'description', content: returnData.category_description }
]
}) +
}, function(header) {
res.send(
header +
'\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/category'].parse(returnData) + '\n\t</noscript>' +
'\n\t<script>templates.ready(function(){ajaxify.go("category/' + category_url + '");});</script>' +
templates['footer']
);
});
});
});
app.get('/confirm/:code', function(req, res) {
res.send(app.build_header({ req: req, res: res }) + '<script>templates.ready(function(){ajaxify.go("confirm/' + req.params.code + '");});</script>' + templates['footer']);
app.build_header({ req: req, res: res }, function(header) {
res.send(header + '<script>templates.ready(function(){ajaxify.go("confirm/' + req.params.code + '");});</script>' + 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({
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');

Loading…
Cancel
Save