df7e64fafa
refs #10790 - Moved /core/apps into core/frontend - Moved /core/server/helpers to /core/frontend/helpers along with /core/server/services/themes - Changed helper location in overrides - Moved /core/server/services/routing to /core/frontend/services - Moved /core/server/services/url to /core/frontend/services - Moved /core/server/data/meta to /core/frontend/meta - Moved /core/server/services/rss to /core/frontend/services - Moved /core/server/data/xml to /core/frontend/services
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
const _ = require('lodash'),
|
|
xml = require('xml'),
|
|
moment = require('moment'),
|
|
urlUtils = require('../../../server/lib/url-utils'),
|
|
localUtils = require('./utils');
|
|
|
|
const XMLNS_DECLS = {
|
|
_attr: {
|
|
xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9'
|
|
}
|
|
};
|
|
|
|
class SiteMapIndexGenerator {
|
|
constructor(options) {
|
|
options = options || {};
|
|
this.types = options.types;
|
|
}
|
|
|
|
getXml() {
|
|
const urlElements = this.generateSiteMapUrlElements(),
|
|
data = {
|
|
// Concat the elements to the _attr declaration
|
|
sitemapindex: [XMLNS_DECLS].concat(urlElements)
|
|
};
|
|
|
|
// Return the xml
|
|
return localUtils.getDeclarations() + xml(data);
|
|
}
|
|
|
|
generateSiteMapUrlElements() {
|
|
return _.map(this.types, (resourceType) => {
|
|
var url = urlUtils.urlFor({relativeUrl: '/sitemap-' + resourceType.name + '.xml'}, true),
|
|
lastModified = resourceType.lastModified;
|
|
|
|
return {
|
|
sitemap: [
|
|
{loc: url},
|
|
{lastmod: moment(lastModified).toISOString()}
|
|
]
|
|
};
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = SiteMapIndexGenerator;
|