0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-17 22:44:24 -05:00

[ci] format

This commit is contained in:
Luiz Ferraz 2024-01-24 00:24:13 +00:00 committed by astrobot-houston
parent 5b29550996
commit d7543d4e1b
2 changed files with 32 additions and 28 deletions

View file

@ -199,15 +199,15 @@ function routeComparator(a: ManifestRouteData, b: ManifestRouteData) {
for (let index = 0; index < commonLength; index++) { for (let index = 0; index < commonLength; index++) {
const aSegment = a.segments[index]; const aSegment = a.segments[index];
const bSegment = b.segments[index]; const bSegment = b.segments[index];
const aIsStatic = aSegment.every((part) => !part.dynamic && !part.spread); const aIsStatic = aSegment.every((part) => !part.dynamic && !part.spread);
const bIsStatic = bSegment.every((part) => !part.dynamic && !part.spread); const bIsStatic = bSegment.every((part) => !part.dynamic && !part.spread);
if (aIsStatic && bIsStatic) { if (aIsStatic && bIsStatic) {
// Both segments are static, they are sorted alphabetically if they are different // Both segments are static, they are sorted alphabetically if they are different
const aContent = aSegment.map((part) => part.content).join(''); const aContent = aSegment.map((part) => part.content).join('');
const bContent = bSegment.map((part) => part.content).join(''); const bContent = bSegment.map((part) => part.content).join('');
if (aContent !== bContent) { if (aContent !== bContent) {
return aContent.localeCompare(bContent); return aContent.localeCompare(bContent);
} }
@ -256,13 +256,17 @@ function routeComparator(a: ManifestRouteData, b: ManifestRouteData) {
if (a.isIndex) { if (a.isIndex) {
const followingBSegment = b.segments.at(a.segments.length); const followingBSegment = b.segments.at(a.segments.length);
const followingBSegmentIsStatic = followingBSegment?.every((part) => !part.dynamic && !part.spread); const followingBSegmentIsStatic = followingBSegment?.every(
(part) => !part.dynamic && !part.spread
);
return followingBSegmentIsStatic ? 1 : -1; return followingBSegmentIsStatic ? 1 : -1;
} }
const followingASegment = a.segments.at(b.segments.length); const followingASegment = a.segments.at(b.segments.length);
const followingASegmentIsStatic = followingASegment?.every((part) => !part.dynamic && !part.spread); const followingASegmentIsStatic = followingASegment?.every(
(part) => !part.dynamic && !part.spread
);
return followingASegmentIsStatic ? -1 : 1; return followingASegmentIsStatic ? -1 : 1;
} }
@ -270,12 +274,12 @@ function routeComparator(a: ManifestRouteData, b: ManifestRouteData) {
// For sorting purposes, an index route is considered to have one more segment than the URL it represents. // For sorting purposes, an index route is considered to have one more segment than the URL it represents.
const aLength = a.isIndex ? a.segments.length + 1 : a.segments.length; const aLength = a.isIndex ? a.segments.length + 1 : a.segments.length;
const bLength = b.isIndex ? b.segments.length + 1 : b.segments.length; const bLength = b.isIndex ? b.segments.length + 1 : b.segments.length;
if (aLength !== bLength){ if (aLength !== bLength) {
// Routes are equal up to the smaller of the two lengths, so the longer route is more specific // Routes are equal up to the smaller of the two lengths, so the longer route is more specific
return aLength > bLength ? -1 : 1; return aLength > bLength ? -1 : 1;
} }
// Sort endpoints before pages // Sort endpoints before pages
if ((a.type === 'endpoint') !== (b.type === 'endpoint')) { if ((a.type === 'endpoint') !== (b.type === 'endpoint')) {
return a.type === 'endpoint' ? -1 : 1; return a.type === 'endpoint' ? -1 : 1;

View file

@ -181,44 +181,44 @@ describe('routing - createRouteManifest', () => {
expect(getManifestRoutes(manifest)).to.deep.equal([ expect(getManifestRoutes(manifest)).to.deep.equal([
{ {
"route": "/", route: '/',
"type": "page", type: 'page',
}, },
{ {
"route": "/blog", route: '/blog',
"type": "page", type: 'page',
}, },
{ {
"route": "/static", route: '/static',
"type": "page", type: 'page',
}, },
{ {
"route": "/[dynamic_folder]", route: '/[dynamic_folder]',
"type": "page", type: 'page',
}, },
{ {
"route": "/[dynamic_file]", route: '/[dynamic_file]',
"type": "page", type: 'page',
}, },
{ {
"route": "/[dynamic_folder]/static", route: '/[dynamic_folder]/static',
"type": "page", type: 'page',
}, },
{ {
"route": "/[dynamic_folder]/[...rest]", route: '/[dynamic_folder]/[...rest]',
"type": "page", type: 'page',
}, },
{ {
"route": "/[...rest]/static", route: '/[...rest]/static',
"type": "page", type: 'page',
}, },
{ {
"route": "/[...rest]", route: '/[...rest]',
"type": "page", type: 'page',
}, },
{ {
"route": "/[...other]", route: '/[...other]',
"type": "page", type: 'page',
}, },
]); ]);
}); });