mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -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
54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
var _ = require('lodash'),
|
|
xml = require('xml'),
|
|
moment = require('moment'),
|
|
config = require('../../config'),
|
|
RESOURCES,
|
|
XMLNS_DECLS;
|
|
|
|
RESOURCES = ['pages', 'posts', 'authors', 'tags'];
|
|
|
|
XMLNS_DECLS = {
|
|
_attr: {
|
|
xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9'
|
|
}
|
|
};
|
|
|
|
function SiteMapIndexGenerator(opts) {
|
|
// Grab the other site map generators from the options
|
|
_.extend(this, _.pick(opts, RESOURCES));
|
|
}
|
|
|
|
_.extend(SiteMapIndexGenerator.prototype, {
|
|
getIndexXml: function () {
|
|
var urlElements = this.generateSiteMapUrlElements(),
|
|
data = {
|
|
// Concat the elements to the _attr declaration
|
|
sitemapindex: [XMLNS_DECLS].concat(urlElements)
|
|
};
|
|
|
|
// Return the xml
|
|
return xml(data, {
|
|
declaration: true
|
|
});
|
|
},
|
|
|
|
generateSiteMapUrlElements: function () {
|
|
var self = this;
|
|
|
|
return _.map(RESOURCES, function (resourceType) {
|
|
var url = config.urlFor({
|
|
relativeUrl: '/sitemap-' + resourceType + '.xml'
|
|
}, true),
|
|
lastModified = self[resourceType].lastModified;
|
|
|
|
return {
|
|
sitemap: [
|
|
{loc: url},
|
|
{lastmod: moment(lastModified).toISOString()}
|
|
]
|
|
};
|
|
});
|
|
}
|
|
});
|
|
|
|
module.exports = SiteMapIndexGenerator;
|