0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00
ghost/core/server/data/xml/sitemap/handler.js
Hannah Wolfe 196bbfce18 Refactor sitemaps to use centralised events
fixes #5104, refs #4348, #2263

- Create a centralised event module
- Hook it up for posts, pages, tags and users
- Use it in sitemaps instead of direct method calls
- Use it for xmlrpc calls
- Check events are fired in model tests
- Update sitemap tests to work with new code
- Fix a bug where invited users were appearing in sitemaps
- Move sitemaps and xmlrpc into a directory together
2015-04-05 19:32:18 +01:00

38 lines
1.2 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.params.resource)) {
return res.sendStatus(404);
}
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) {
var type = req.params.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);
});
};