v1.18.x
Julian Lam 11 years ago
parent 5546b4e04d
commit 8e0bc0257d

@ -9,6 +9,7 @@ var path = require('path'),
topics = require('./topics'), topics = require('./topics'),
utils = require('../public/src/utils'), utils = require('../public/src/utils'),
sitemap = { sitemap = {
obj: undefined,
getStaticUrls: function(callback) { getStaticUrls: function(callback) {
callback(null, [{ callback(null, [{
url: '', url: '',
@ -74,18 +75,29 @@ var path = require('path'),
}); });
}, },
render: function(callback) { render: function(callback) {
var returnSitemap = function() {
sitemap.obj.toXML(function(xml) {
callback(xml);
});
};
if (sitemap.obj !== undefined && sitemap.obj.cache.length) {
console.log('using sitemap from cache!');
returnSitemap();
} else {
console.log('generating new sitemap!', sitemap.obj);
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]);
var map = sm.createSitemap({ sitemap.obj = sm.createSitemap({
hostname: nconf.get('url'), hostname: nconf.get('url'),
cacheTime: 60*60, // Cached for 1 hour cacheTime: 1000 * 60 * 60, // Cached for 1 hour
urls: urls urls: urls
}),
xml = map.toXML(function(xml) {
callback(xml);
}); });
returnSitemap();
}); });
} }
}
}; };
module.exports = sitemap; module.exports = sitemap;

Loading…
Cancel
Save