From 2757ef70fad0123b76f4b00a246610de77c5b3b8 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Tue, 27 Aug 2024 17:31:08 +0200 Subject: [PATCH] =?UTF-8?q?Revert=20"=F0=9F=90=9B=20Fixed=20frontend=20rou?= =?UTF-8?q?ting=20prioritizing=20collections=20over=20built=20in=20routes?= =?UTF-8?q?=20(#20765)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs https://app.incident.io/ghost/incidents/102 - this reverts commit c0471f0c287317cdfbc94f427e5868461bd4d881 --- .../services/routing/RouterManager.js | 14 ++++---- .../test/e2e-frontend/custom_routes.test.js | 33 ------------------- .../fixtures/settings/edgecaseroutes.yaml | 10 ------ ghost/core/test/utils/index.js | 7 ---- 4 files changed, 7 insertions(+), 57 deletions(-) delete mode 100644 ghost/core/test/utils/fixtures/settings/edgecaseroutes.yaml diff --git a/ghost/core/core/frontend/services/routing/RouterManager.js b/ghost/core/core/frontend/services/routing/RouterManager.js index 1e92eaa2fa..7960be6117 100644 --- a/ghost/core/core/frontend/services/routing/RouterManager.js +++ b/ghost/core/core/frontend/services/routing/RouterManager.js @@ -126,13 +126,6 @@ class RouterManager { this.registry.setRouter(staticRoutesRouter.identifier, staticRoutesRouter); }); - _.each(routerSettings.taxonomies, (value, key) => { - const taxonomyRouter = new TaxonomyRouter(key, value, RESOURCE_CONFIG, this.routerCreated.bind(this)); - this.siteRouter.mountRouter(taxonomyRouter.router()); - - this.registry.setRouter(taxonomyRouter.identifier, taxonomyRouter); - }); - _.each(routerSettings.collections, (value, key) => { const collectionRouter = new CollectionRouter(key, value, RESOURCE_CONFIG, this.routerCreated.bind(this)); this.siteRouter.mountRouter(collectionRouter.router()); @@ -144,6 +137,13 @@ class RouterManager { this.registry.setRouter('staticPagesRouter', staticPagesRouter); + _.each(routerSettings.taxonomies, (value, key) => { + const taxonomyRouter = new TaxonomyRouter(key, value, RESOURCE_CONFIG, this.routerCreated.bind(this)); + this.siteRouter.mountRouter(taxonomyRouter.router()); + + this.registry.setRouter(taxonomyRouter.identifier, taxonomyRouter); + }); + const appRouter = new ParentRouter('AppsRouter'); this.siteRouter.mountRouter(appRouter.router()); diff --git a/ghost/core/test/e2e-frontend/custom_routes.test.js b/ghost/core/test/e2e-frontend/custom_routes.test.js index fa1d1eab06..7c4977662c 100644 --- a/ghost/core/test/e2e-frontend/custom_routes.test.js +++ b/ghost/core/test/e2e-frontend/custom_routes.test.js @@ -80,36 +80,3 @@ describe('Custom Frontend routing', function () { .expect(assertCorrectFrontendHeaders); }); }); - -describe('Custom frontend routing - edge cases', function () { - let request; - - before(async function () { - const routesFilePath = path.join(configUtils.config.get('paths:appRoot'), 'test/utils/fixtures/settings/edgecaseroutes.yaml'); - await configUtils.restore(); - await testUtils.stopGhost(); - - await testUtils.startGhost({ - forceStart: true, - routesFilePath, - subdir: false - }); - - request = supertest.agent(configUtils.config.get('url')); - }); - - after(async function () { - await testUtils.stopGhost(); - }); - - it('should prioritize taxonomies over collections', async function () { - // Create a tag and a post with the same slug - const slug = 'cheese'; - await testUtils.createTag({tag: {slug}}); - await testUtils.createPost({post: {tags: [{slug}], slug}}); - - // Test that the tag route takes precedence - await request.get(`/tag/${slug}/`) - .expect(200); - }); -}); diff --git a/ghost/core/test/utils/fixtures/settings/edgecaseroutes.yaml b/ghost/core/test/utils/fixtures/settings/edgecaseroutes.yaml deleted file mode 100644 index d4a8a4b133..0000000000 --- a/ghost/core/test/utils/fixtures/settings/edgecaseroutes.yaml +++ /dev/null @@ -1,10 +0,0 @@ -routes: - -collections: - /: - permalink: /{primary_tag}/{slug}/ - template: index - -taxonomies: - tag: /tag/{slug}/ - author: /author/{slug}/ \ No newline at end of file diff --git a/ghost/core/test/utils/index.js b/ghost/core/test/utils/index.js index 6e4fd34cfa..b43d59bc6f 100644 --- a/ghost/core/test/utils/index.js +++ b/ghost/core/test/utils/index.js @@ -79,12 +79,6 @@ const createPost = function createPost(options) { return models.Post.add(post, context.internal); }; -const createTag = function createTag(options) { - const tag = DataGenerator.forKnex.createTag(options.tag); - - return models.Tag.add(tag, context.internal); -}; - const createEmail = function createEmail(options) { const email = DataGenerator.forKnex.createEmail(options.email); return models.Email.add(email, context.internal); @@ -109,7 +103,6 @@ module.exports = { setup: setup, createUser: createUser, createPost: createPost, - createTag: createTag, createEmailedPost, /**