refactored parallel to waterfall in topic and category routes (to allow

for better title generation)
v1.18.x
Julian Lam 12 years ago
parent 931beecc21
commit ce769a87ef

@ -207,26 +207,39 @@ var express = require('express'),
return;
}
var topic_url = tid + (req.params.slug ? '/' + req.params.slug : '');
topics.getTopicWithPosts(tid, ((req.user) ? req.user.uid : 0), function(err, topic) {
if (err) return res.redirect('404');
async.waterfall([
function(next) {
topics.getTopicWithPosts(tid, ((req.user) ? req.user.uid : 0), function(err, topicData) {
next(err, topicData);
});
},
function(topicData, next) {
app.build_header({
req: req,
res: res,
title: topicData.topic_name,
metaTags: [
{ name: "title", content: topic.topic_name }
{ name: "title", content: topicData.topic_name }
]
}, function(header) {
}, function(err, header) {
next(err, {
header: header,
topics: topicData
});
});
},
], function(err, data) {
if (err) return res.redirect('404');
var topic_url = tid + (req.params.slug ? '/' + req.params.slug : '');
res.send(
header +
'\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/topic'].parse(topic) + '\n\t</noscript>' +
data.header +
'\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/topic'].parse(data.topics) + '\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;
@ -243,27 +256,40 @@ var express = require('express'),
return;
}
var category_url = cid + (req.params.slug ? '/' + req.params.slug : '');
categories.getCategoryById(cid, 0, function(err, returnData) {
if(err) return res.redirect('404');
async.waterfall([
function(next) {
categories.getCategoryById(cid, 0, function(err, categoryData) {
next(err, categoryData);
});
},
function(categoryData, next) {
app.build_header({
req: req,
res: res,
title: categoryData.category_name,
metaTags: [
{ name: 'title', content: returnData.category_name },
{ name: 'description', content: returnData.category_description }
{ name: 'title', content: categoryData.category_name },
{ name: 'description', content: categoryData.category_description }
]
}, function(header) {
}, function(err, header) {
next(err, {
header: header,
categories: categoryData
});
});
}
], function(err, data) {
if(err) return res.redirect('404');
var category_url = cid + (req.params.slug ? '/' + req.params.slug : '');
res.send(
header +
'\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/category'].parse(returnData) + '\n\t</noscript>' +
data.header +
'\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/category'].parse(data.categories) + '\n\t</noscript>' +
'\n\t<script>templates.ready(function(){ajaxify.go("category/' + category_url + '");});</script>' +
templates['footer']
);
});
});
});
app.get('/confirm/:code', function(req, res) {
app.build_header({ req: req, res: res }, function(header) {

Loading…
Cancel
Save