You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2 KiB
JavaScript

'use strict';
8 years ago
var async = require('async');
var sitemap = require('../sitemap');
var meta = require('../meta');
8 years ago
var sitemapController = module.exports;
8 years ago
sitemapController.render = function (req, res, next) {
async.waterfall([
function (next) {
sitemap.render(next);
},
function (tplData, next) {
req.app.render('sitemap', tplData, next);
},
function (xml) {
res.header('Content-Type', 'application/xml');
res.send(xml);
8 years ago
},
], next);
};
sitemapController.getPages = function (req, res, next) {
sendSitemap(sitemap.getPages, res, next);
};
sitemapController.getCategories = function (req, res, next) {
sendSitemap(sitemap.getCategories, res, next);
};
sitemapController.getTopicPage = function (req, res, next) {
8 years ago
sendSitemap(function (callback) {
sitemap.getTopicPage(parseInt(req.params[0], 10), callback);
}, res, next);
};
function sendSitemap(method, res, callback) {
if (parseInt(meta.config['feeds:disableSitemap'], 10) === 1) {
8 years ago
return callback();
}
8 years ago
async.waterfall([
function (next) {
method(next);
},
function (xml) {
if (!xml) {
return callback();
}
8 years ago
res.header('Content-Type', 'application/xml');
res.send(xml);
},
], callback);
}