Files
NodeBB/src/controllers/sitemap.js

62 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-08-12 14:11:40 +03:00
'use strict';
2017-03-01 23:19:34 +03:00
var async = require('async');
2016-08-12 14:11:40 +03:00
var sitemap = require('../sitemap');
var meta = require('../meta');
2017-03-01 23:19:34 +03:00
var sitemapController = module.exports;
2016-10-07 13:03:46 +03:00
2017-03-01 23:19:34 +03:00
sitemapController.render = function (req, res, next) {
async.waterfall([
function (next) {
sitemap.render(next);
},
function (tplData, next) {
req.app.render('sitemap', tplData, next);
},
function (xml) {
2016-08-12 14:11:40 +03:00
res.header('Content-Type', 'application/xml');
res.send(xml);
2017-03-01 23:19:34 +03:00
},
], next);
2016-08-12 14:11:40 +03:00
};
sitemapController.getPages = function (req, res, next) {
2017-03-01 23:19:34 +03:00
sendSitemap(function (callback) {
sitemap.getPages(callback);
}, res, next);
2016-08-12 14:11:40 +03:00
};
sitemapController.getCategories = function (req, res, next) {
2017-03-01 23:19:34 +03:00
sendSitemap(function (callback) {
sitemap.getCategories(callback);
}, res, next);
2016-08-12 14:11:40 +03:00
};
sitemapController.getTopicPage = function (req, res, next) {
2017-03-01 23:19:34 +03:00
sendSitemap(function (callback) {
sitemap.getTopicPage(parseInt(req.params[0], 10), callback);
}, res, next);
};
function sendSitemap(method, res, callback) {
2016-08-12 14:11:40 +03:00
if (parseInt(meta.config['feeds:disableSitemap'], 10) === 1) {
2017-03-01 23:19:34 +03:00
return callback();
2016-08-12 14:11:40 +03:00
}
2017-03-01 23:19:34 +03:00
async.waterfall([
function (next) {
method(next);
},
function (xml) {
if (!xml) {
return callback();
}
2016-08-12 14:11:40 +03:00
2017-03-01 23:19:34 +03:00
res.header('Content-Type', 'application/xml');
res.send(xml);
},
], callback);
}
2016-08-12 14:11:40 +03:00