From 2700c125c9bfebbd2c723451ece473944fdda56f Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Tue, 30 May 2023 18:33:43 -0400 Subject: [PATCH] Do a simple push for priority --- .../astro/src/core/routing/manifest/create.ts | 38 ++----------------- .../astro/test/units/routing/manifest.test.js | 4 +- 2 files changed, 6 insertions(+), 36 deletions(-) diff --git a/packages/astro/src/core/routing/manifest/create.ts b/packages/astro/src/core/routing/manifest/create.ts index 7ad6fd6d4..a19362129 100644 --- a/packages/astro/src/core/routing/manifest/create.ts +++ b/packages/astro/src/core/routing/manifest/create.ts @@ -228,30 +228,6 @@ function areSiblings(a: RouteData, b: RouteData) { return true; } -// A fast insertion method based on binary search. -function binaryInsert(sorted: T[], item: T, insertComparator: (a: T, item: T) => boolean) { - if(sorted.length === 0) { - sorted.push(item); - return 0; - } - let low = 0, high = sorted.length - 1, mid = 0; - while (low <= high) { - mid = low + (high - low >> 1); - if(insertComparator(sorted[mid], item)) { - low = mid + 1; - } else { - high = mid -1; - } - } - - if(insertComparator(sorted[mid], item)) { - mid++; - } - - sorted.splice(mid, 0, item); - return mid; -} - export interface CreateRouteManifestParams { /** Astro Settings object */ settings: AstroSettings; @@ -505,17 +481,9 @@ export function createRouteManifest( redirect: to, redirectRoute: routes.find(r => r.route === to) }; - const isSpreadRoute = isSpread(route); - - binaryInsert(routes, routeData, (a, item) => { - // If the routes are siblings and the redirect route is a spread - // Then it should come after the sibling unless it is also a spread. - // This essentially means that redirects are prioritized when *exactly* the same. - if(isSpreadRoute && areSiblings(a, item)) { - return !isSpread(a.route); - } - return true; - }); + + // Push so that redirects are selected last. + routes.push(routeData); }); return { diff --git a/packages/astro/test/units/routing/manifest.test.js b/packages/astro/test/units/routing/manifest.test.js index 5d7613e52..4a8a96175 100644 --- a/packages/astro/test/units/routing/manifest.test.js +++ b/packages/astro/test/units/routing/manifest.test.js @@ -45,7 +45,8 @@ describe('routing - createRouteManifest', () => { base: '/search', trailingSlash: 'never', redirects: { - '/blog/[...slug]': '/' + '/blog/[...slug]': '/', + '/blog/contributing': '/another', } }, root @@ -57,6 +58,7 @@ describe('routing - createRouteManifest', () => { }); expect(manifest.routes[1].route).to.equal('/blog/contributing'); + expect(manifest.routes[1].type).to.equal('page'); expect(manifest.routes[2].route).to.equal('/blog/[...slug]'); }) });