Ghost/core/frontend/services/sitemap/manager.js
Naz Gargol df7e64fafa
Extracted frontend folder (#10780)
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
2019-06-19 11:30:28 +02:00

81 lines
2.5 KiB
JavaScript

const common = require('../../../server/lib/common'),
IndexMapGenerator = require('./index-generator'),
PagesMapGenerator = require('./page-generator'),
PostsMapGenerator = require('./post-generator'),
UsersMapGenerator = require('./user-generator'),
TagsMapGenerator = require('./tag-generator');
class SiteMapManager {
constructor(options) {
options = options || {};
this.pages = options.pages || this.createPagesGenerator(options);
this.posts = options.posts || this.createPostsGenerator(options);
this.users = this.authors = options.authors || this.createUsersGenerator(options);
this.tags = options.tags || this.createTagsGenerator(options);
this.index = options.index || this.createIndexGenerator(options);
common.events.on('router.created', (router) => {
if (router.name === 'StaticRoutesRouter') {
this.pages.addUrl(router.getRoute({absolute: true}), {id: router.identifier, staticRoute: true});
}
if (router.name === 'CollectionRouter') {
this.pages.addUrl(router.getRoute({absolute: true}), {id: router.identifier, staticRoute: false});
}
});
common.events.on('url.added', (obj) => {
this[obj.resource.config.type].addUrl(obj.url.absolute, obj.resource.data);
});
common.events.on('url.removed', (obj) => {
this[obj.resource.config.type].removeUrl(obj.url.absolute, obj.resource.data);
});
common.events.on('routers.reset', () => {
this.pages && this.pages.reset();
this.posts && this.posts.reset();
this.users && this.users.reset();
this.tags && this.tags.reset();
});
}
createIndexGenerator() {
return new IndexMapGenerator({
types: {
pages: this.pages,
posts: this.posts,
authors: this.authors,
tags: this.tags
}
});
}
createPagesGenerator(options) {
return new PagesMapGenerator(options);
}
createPostsGenerator(options) {
return new PostsMapGenerator(options);
}
createUsersGenerator(options) {
return new UsersMapGenerator(options);
}
createTagsGenerator(options) {
return new TagsMapGenerator(options);
}
getIndexXml() {
return this.index.getXml();
}
getSiteMapXml(type) {
return this[type].getXml();
}
}
module.exports = SiteMapManager;