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) {
if (category) {
categoryUrls.push({ categoryUrls.push({
url: path.join('/category', category.slug), url: '/category/' + category.cid + '/' + encodeURIComponent(utils.slugify(category.name)),
changefreq: 'weekly', changefreq: 'weekly',
priority: '0.4' 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) {
if (topic) {
topicUrls.push({ topicUrls.push({
url: path.join('/topic', topic.slug), url: '/topic/' + topic.tid + '/' + encodeURIComponent(utils.slugify(topic.title)),
lastmodISO: utils.toISOString(topic.lastposttime), lastmodISO: utils.toISOString(topic.lastposttime),
changefreq: 'daily', changefreq: 'daily',
priority: '0.6' 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,8 +94,9 @@ 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) { async.parallel([sitemap.getStaticUrls, sitemap.getDynamicUrls], function(err, urls) {
urls = urls[0].concat(urls[1]); urls = urls[0].concat(urls[1]);
sitemap.obj = sm.createSitemap({ sitemap.obj = sm.createSitemap({
@ -103,7 +108,6 @@ var path = require('path'),
sitemap.obj.toXML(callback); sitemap.obj.toXML(callback);
}); });
} }
}
}; };
module.exports = sitemap; module.exports = sitemap;

Loading…
Cancel
Save