mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
818085f18c
fixes #4555 - There's no easy way to declare an XSL with the node xml module, so I needed to move the declarations to both be strings - Ideally the code to serve the XSL would also be inside the sitemap module, but I think we need to refactor a bit to get there easily - Added the XSL from #4559, with minor amends to make the tables and urls display correctly
44 lines
1.5 KiB
JavaScript
44 lines
1.5 KiB
JavaScript
var _ = require('lodash'),
|
|
utils = require('../../utils'),
|
|
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) {
|
|
if (!_.contains(resourceTypes, req.param('resource'))) {
|
|
return res.sendStatus(404);
|
|
}
|
|
|
|
next();
|
|
},
|
|
getResourceSiteMapXml = function (type, page) {
|
|
return sitemap.getSiteMapXml(type, page);
|
|
};
|
|
|
|
// Redirect normal sitemap.xml requests to sitemap-index.xml
|
|
blogApp.get('/sitemap.xml', function (req, res) {
|
|
res.set({'Cache-Control': 'public, max-age=' + utils.ONE_YEAR_S});
|
|
res.redirect(301, req.baseUrl + '/sitemap-index.xml');
|
|
});
|
|
|
|
blogApp.get('/sitemap-index.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) {
|
|
var type = req.param('resource'),
|
|
page = 1,
|
|
siteMapXml = getResourceSiteMapXml(type, page);
|
|
|
|
res.set({
|
|
'Cache-Control': 'public, max-age=' + utils.ONE_HOUR_S,
|
|
'Content-Type': 'text/xml'
|
|
});
|
|
res.send(siteMapXml);
|
|
});
|
|
};
|