v1.18.x
Barış Soner Uşaklı 10 years ago
parent 1bf6c1fd46
commit 4af8a5ec02

@ -5,6 +5,7 @@ var tagsController = {},
nconf = require('nconf'), nconf = require('nconf'),
validator = require('validator'), validator = require('validator'),
meta = require('../meta'), meta = require('../meta'),
user = require('../user'),
topics = require('../topics'), topics = require('../topics'),
helpers = require('./helpers'); helpers = require('./helpers');
@ -12,43 +13,58 @@ tagsController.getTag = function(req, res, next) {
var tag = validator.escape(req.params.tag); var tag = validator.escape(req.params.tag);
var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1; var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1;
topics.getTagTids(tag, 0, stop, function(err, tids) { async.waterfall([
function(next) {
topics.getTagTids(tag, 0, stop, next);
},
function(tids, next) {
if (Array.isArray(tids) && !tids.length) {
topics.deleteTag(tag);
return res.render('tag', {
topics: [],
tag: tag,
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[tags:tags]]', url: '/tags'}, {text: tag}])
});
}
async.parallel({
isAdmin: async.apply(user.isAdministrator, req.uid),
topics: async.apply(topics.getTopics, tids, req.uid)
}, next);
}
], function(err, results) {
if (err) { if (err) {
return next(err); return next(err);
} }
if (Array.isArray(tids) && !tids.length) { if (!results.isAdmin) {
topics.deleteTag(tag); results.topics = results.topics.filter(function(topic) {
return res.render('tag', {topics: [], tag: tag}); return topic && !topic.deleted;
});
} }
topics.getTopics(tids, req.uid, function(err, topics) { res.locals.metaTags = [
if (err) { {
return next(err); name: 'title',
content: tag
},
{
property: 'og:title',
content: tag
},
{
property: 'og:url',
content: nconf.get('url') + '/tags/' + tag
} }
];
res.locals.metaTags = [ var data = {
{ topics: results.topics,
name: 'title', tag: tag,
content: tag nextStart: stop + 1,
}, breadcrumbs: helpers.buildBreadcrumbs([{text: '[[tags:tags]]', url: '/tags'}, {text: tag}])
{ };
property: 'og:title', res.render('tag', data);
content: tag
},
{
property: 'og:url',
content: nconf.get('url') + '/tags/' + tag
}
];
var data = {
topics: topics,
tag: tag,
nextStart: stop + 1,
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[tags:tags]]', url: '/tags'}, {text: tag}])
};
res.render('tag', data);
});
}); });
}; };

Loading…
Cancel
Save