0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

🐛Fixed sitemap duplicates after routes.yaml upload (#9957)

closes #9956

- sitemap reset was missing
This commit is contained in:
Katharina Irrgang 2018-10-08 05:29:21 +02:00 committed by Fabien O'Carroll
parent f55a9ad412
commit d699daeb35
4 changed files with 17 additions and 1 deletions

View file

@ -154,6 +154,11 @@ class BaseSiteMapGenerator {
delete this.nodeLookup[datum.id]; delete this.nodeLookup[datum.id];
delete this.nodeTimeLookup[datum.id]; delete this.nodeTimeLookup[datum.id];
} }
reset() {
this.nodeLookup = {};
this.nodeTimeLookup = {};
}
} }
module.exports = BaseSiteMapGenerator; module.exports = BaseSiteMapGenerator;

View file

@ -32,6 +32,13 @@ class SiteMapManager {
common.events.on('url.removed', (obj) => { common.events.on('url.removed', (obj) => {
this[obj.resource.config.type].removeUrl(obj.url.absolute, obj.resource.data); 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() { createIndexGenerator() {

View file

@ -1,5 +1,6 @@
const debug = require('ghost-ignition').debug('services:routing:bootstrap'); const debug = require('ghost-ignition').debug('services:routing:bootstrap');
const _ = require('lodash'); const _ = require('lodash');
const common = require('../../lib/common');
const settingsService = require('../settings'); const settingsService = require('../settings');
const StaticRoutesRouter = require('./StaticRoutesRouter'); const StaticRoutesRouter = require('./StaticRoutesRouter');
const StaticPagesRouter = require('./StaticPagesRouter'); const StaticPagesRouter = require('./StaticPagesRouter');
@ -17,6 +18,8 @@ module.exports.init = (options = {start: false}) => {
registry.resetAllRouters(); registry.resetAllRouters();
registry.resetAllRoutes(); registry.resetAllRoutes();
common.events.emit('routers.reset');
siteRouter = new ParentRouter('SiteRouter'); siteRouter = new ParentRouter('SiteRouter');
registry.setRouter('siteRouter', siteRouter); registry.setRouter('siteRouter', siteRouter);

View file

@ -62,10 +62,11 @@ describe('Unit: sitemap/manager', function () {
it('can create a SiteMapManager instance', function () { it('can create a SiteMapManager instance', function () {
should.exist(manager); should.exist(manager);
Object.keys(eventsToRemember).length.should.eql(3); Object.keys(eventsToRemember).length.should.eql(4);
should.exist(eventsToRemember['url.added']); should.exist(eventsToRemember['url.added']);
should.exist(eventsToRemember['url.removed']); should.exist(eventsToRemember['url.removed']);
should.exist(eventsToRemember['router.created']); should.exist(eventsToRemember['router.created']);
should.exist(eventsToRemember['routers.reset']);
}); });
describe('trigger url events', function () { describe('trigger url events', function () {