v1.18.x
barisusakli 11 years ago
parent a8760cd2bc
commit 89613d2346

@ -30,8 +30,8 @@ var path = require('path'),
getDynamicUrls: function(callback) { getDynamicUrls: function(callback) {
var returnUrls = []; var returnUrls = [];
async.parallel([ async.parallel({
function(next) { categoryUrls: function(next) {
var categoryUrls = []; var categoryUrls = [];
categories.getCategoriesByPrivilege(0, 'find', function(err, categoriesData) { categories.getCategoriesByPrivilege(0, 'find', function(err, categoriesData) {
if (err) { if (err) {
@ -39,17 +39,19 @@ var path = require('path'),
} }
categoriesData.forEach(function(category) { categoriesData.forEach(function(category) {
categoryUrls.push({ if (category) {
url: path.join('/category', category.slug), categoryUrls.push({
changefreq: 'weekly', url: '/category/' + category.cid + '/' + encodeURIComponent(utils.slugify(category.name)),
priority: '0.4' changefreq: 'weekly',
}); priority: '0.4'
});
}
}); });
next(null, categoryUrls); next(null, categoryUrls);
}); });
}, },
function(next) { topicUrls: function(next) {
var topicUrls = []; var topicUrls = [];
db.getSortedSetRevRange('topics:recent', 0, 49, function(err, tids) { db.getSortedSetRevRange('topics:recent', 0, 49, function(err, tids) {
@ -61,18 +63,20 @@ var path = require('path'),
return next(err); return next(err);
} }
topics.getTopicsFields(tids, ['slug', 'lastposttime'], function(err, topics) { topics.getTopicsFields(tids, ['tid', 'title', 'lastposttime'], function(err, topics) {
if (err) { if (err) {
return next(err); return next(err);
} }
topics.forEach(function(topic) { topics.forEach(function(topic) {
topicUrls.push({ if (topic) {
url: path.join('/topic', topic.slug), topicUrls.push({
lastmodISO: utils.toISOString(topic.lastposttime), url: '/topic/' + topic.tid + '/' + encodeURIComponent(utils.slugify(topic.title)),
changefreq: 'daily', lastmodISO: utils.toISOString(topic.lastposttime),
priority: '0.6' changefreq: 'daily',
}); priority: '0.6'
});
}
}); });
next(null, topicUrls); next(null, topicUrls);
@ -80,9 +84,9 @@ var path = require('path'),
}); });
}); });
} }
], function(err, data) { }, function(err, data) {
if (!err) { if (!err) {
returnUrls = returnUrls.concat(data[0]).concat(data[1]); returnUrls = data.categoryUrls.concat(data.topicUrls);
} }
callback(err, returnUrls); callback(err, returnUrls);
@ -90,19 +94,19 @@ var path = require('path'),
}, },
render: function(callback) { render: function(callback) {
if (sitemap.obj !== undefined && sitemap.obj.cache.length) { if (sitemap.obj !== undefined && sitemap.obj.cache.length) {
sitemap.obj.toXML(callback); return sitemap.obj.toXML(callback);
} else { }
async.parallel([sitemap.getStaticUrls, sitemap.getDynamicUrls], function(err, urls) {
urls = urls[0].concat(urls[1]);
sitemap.obj = sm.createSitemap({
hostname: nconf.get('url'),
cacheTime: 1000 * 60 * 60, // Cached for 1 hour
urls: urls
});
sitemap.obj.toXML(callback); async.parallel([sitemap.getStaticUrls, sitemap.getDynamicUrls], function(err, urls) {
urls = urls[0].concat(urls[1]);
sitemap.obj = sm.createSitemap({
hostname: nconf.get('url'),
cacheTime: 1000 * 60 * 60, // Cached for 1 hour
urls: urls
}); });
}
sitemap.obj.toXML(callback);
});
} }
}; };

Loading…
Cancel
Save