mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-13 22:41:32 -05:00
2cfa18475a
Closes #623 - Add basic init and eventing scaffold - Add sitemap-index.xml generation - Broke out generators to individual files, added request handler - Add page, author and tag xml files; add index mapping - Add SiteMapManager unit tests - Add Generators tests - Cache invalidation headers for sitemap-*.xml - Redirect sitemap.xml to index and rename to sitemap-index - Handle page convert and publish/draft changes - Add very basic functional test for route existence - Add cache headers to sitemap routes
44 lines
1.4 KiB
JavaScript
44 lines
1.4 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.send(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, '/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);
|
|
});
|
|
};
|