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++) {
const aSegment = a.segments[index];
const bSegment = b.segments[index];
const aIsStatic = aSegment.every((part) => !part.dynamic && !part.spread);
const bIsStatic = bSegment.every((part) => !part.dynamic && !part.spread);
if (aIsStatic && bIsStatic) {
// Both segments are static, they are sorted alphabetically if they are different
const aContent = aSegment.map((part) => part.content).join('');
const bContent = bSegment.map((part) => part.content).join('');
if (aContent !== bContent) {
return aContent.localeCompare(bContent);
}
@ -256,13 +256,17 @@ function routeComparator(a: ManifestRouteData, b: ManifestRouteData) {
if (a.isIndex) {
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;
}
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;
}
@ -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.
const aLength = a.isIndex ? a.segments.length + 1 : a.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
return aLength > bLength ? -1 : 1;
}
// Sort endpoints before pages
if ((a.type === 'endpoint') !== (b.type === 'endpoint')) {
return a.type === 'endpoint' ? -1 : 1;

View file

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