mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-22 16:30:34 +01:00
refactored parallel to waterfall in topic and category routes (to allow
for better title generation)
This commit is contained in:
@@ -207,26 +207,39 @@ var express = require('express'),
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var topic_url = tid + (req.params.slug ? '/' + req.params.slug : '');
|
async.waterfall([
|
||||||
topics.getTopicWithPosts(tid, ((req.user) ? req.user.uid : 0), function(err, topic) {
|
function(next) {
|
||||||
if (err) return res.redirect('404');
|
topics.getTopicWithPosts(tid, ((req.user) ? req.user.uid : 0), function(err, topicData) {
|
||||||
|
next(err, topicData);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(topicData, next) {
|
||||||
app.build_header({
|
app.build_header({
|
||||||
req: req,
|
req: req,
|
||||||
res: res,
|
res: res,
|
||||||
|
title: topicData.topic_name,
|
||||||
metaTags: [
|
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(
|
res.send(
|
||||||
header +
|
data.header +
|
||||||
'\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/topic'].parse(topic) + '\n\t</noscript>' +
|
'\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>' +
|
'\n\t<script>templates.ready(function(){ajaxify.go("topic/' + topic_url + '");});</script>' +
|
||||||
templates['footer']
|
templates['footer']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/category/:category_id/:slug?', function(req, res) {
|
app.get('/category/:category_id/:slug?', function(req, res) {
|
||||||
var cid = req.params.category_id;
|
var cid = req.params.category_id;
|
||||||
@@ -243,27 +256,40 @@ var express = require('express'),
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var category_url = cid + (req.params.slug ? '/' + req.params.slug : '');
|
async.waterfall([
|
||||||
categories.getCategoryById(cid, 0, function(err, returnData) {
|
function(next) {
|
||||||
if(err) return res.redirect('404');
|
categories.getCategoryById(cid, 0, function(err, categoryData) {
|
||||||
|
next(err, categoryData);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(categoryData, next) {
|
||||||
app.build_header({
|
app.build_header({
|
||||||
req: req,
|
req: req,
|
||||||
res: res,
|
res: res,
|
||||||
|
title: categoryData.category_name,
|
||||||
metaTags: [
|
metaTags: [
|
||||||
{ name: 'title', content: returnData.category_name },
|
{ name: 'title', content: categoryData.category_name },
|
||||||
{ name: 'description', content: returnData.category_description }
|
{ 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(
|
res.send(
|
||||||
header +
|
data.header +
|
||||||
'\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/category'].parse(returnData) + '\n\t</noscript>' +
|
'\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>' +
|
'\n\t<script>templates.ready(function(){ajaxify.go("category/' + category_url + '");});</script>' +
|
||||||
templates['footer']
|
templates['footer']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/confirm/:code', function(req, res) {
|
app.get('/confirm/:code', function(req, res) {
|
||||||
app.build_header({ req: req, res: res }, function(header) {
|
app.build_header({ req: req, res: res }, function(header) {
|
||||||
|
|||||||
Reference in New Issue
Block a user