2014-12-01 13:43:01 +03:00
|
|
|
var _ = require('lodash'),
|
|
|
|
utils = require('../../utils'),
|
2014-10-28 03:41:18 +03:00
|
|
|
sitemap = require('./index');
|
|
|
|
|
|
|
|
// Responsible for handling requests for sitemap files
|
|
|
|
module.exports = function (blogApp) {
|
|
|
|
var resourceTypes = ['posts', 'authors', 'tags', 'pages'],
|
|
|
|
verifyResourceType = function (req, res, next) {
|
2015-02-26 10:28:37 +03:00
|
|
|
if (!_.contains(resourceTypes, req.params.resource)) {
|
2014-12-01 13:43:01 +03:00
|
|
|
return res.sendStatus(404);
|
2014-10-28 03:41:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
next();
|
|
|
|
},
|
|
|
|
getResourceSiteMapXml = function (type, page) {
|
|
|
|
return sitemap.getSiteMapXml(type, page);
|
|
|
|
};
|
|
|
|
|
|
|
|
blogApp.get('/sitemap.xml', function (req, res) {
|
|
|
|
res.set({
|
|
|
|
'Cache-Control': 'public, max-age=' + utils.ONE_HOUR_S,
|
|
|
|
'Content-Type': 'text/xml'
|
|
|
|
});
|
|
|
|
res.send(sitemap.getIndexXml());
|
|
|
|
});
|
|
|
|
|
|
|
|
blogApp.get('/sitemap-:resource.xml', verifyResourceType, function (req, res) {
|
2015-02-26 10:28:37 +03:00
|
|
|
var type = req.params.resource,
|
2014-10-28 03:41:18 +03:00
|
|
|
page = 1,
|
|
|
|
siteMapXml = getResourceSiteMapXml(type, page);
|
|
|
|
|
|
|
|
res.set({
|
|
|
|
'Cache-Control': 'public, max-age=' + utils.ONE_HOUR_S,
|
|
|
|
'Content-Type': 'text/xml'
|
|
|
|
});
|
|
|
|
res.send(siteMapXml);
|
|
|
|
});
|
|
|
|
};
|