mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
829e8ed010
- Having these as destructured from the same package is hindering refactoring now - Events should really only ever be used server-side - i18n should be a shared module for now so it can be used everywhere until we figure out something better - Having them seperate also allows us to lint them properly
81 lines
2.5 KiB
JavaScript
81 lines
2.5 KiB
JavaScript
const events = require('../../../server/lib/common/events');
|
|
const IndexMapGenerator = require('./index-generator');
|
|
const PagesMapGenerator = require('./page-generator');
|
|
const PostsMapGenerator = require('./post-generator');
|
|
const UsersMapGenerator = require('./user-generator');
|
|
const 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);
|
|
|
|
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});
|
|
}
|
|
});
|
|
|
|
events.on('url.added', (obj) => {
|
|
this[obj.resource.config.type].addUrl(obj.url.absolute, obj.resource.data);
|
|
});
|
|
|
|
events.on('url.removed', (obj) => {
|
|
this[obj.resource.config.type].removeUrl(obj.url.absolute, obj.resource.data);
|
|
});
|
|
|
|
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;
|