Skip to content

Commit

Permalink
Guarantee route and autogenerated sidebar sort order
Browse files Browse the repository at this point in the history
  • Loading branch information
delucis committed May 26, 2023
1 parent ed808dc commit 51fe914
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/shy-parrots-dance.md
@@ -0,0 +1,5 @@
---
"@astrojs/starlight": patch
---

Guarantee route and autogenerated sidebar sort order
5 changes: 5 additions & 0 deletions docs/src/content/docs/reference/configuration.md
Expand Up @@ -97,6 +97,11 @@ starlight({
});
```

:::note[Sorting]
Autogenerated sidebar groups are sorted by filename alphabetically.
For example, a page generated from `astro.md` would appear above the page for `starlight.md`.
:::

#### `SidebarGroup`

```ts
Expand Down
5 changes: 4 additions & 1 deletion packages/starlight/utils/routing.ts
Expand Up @@ -76,7 +76,10 @@ function getRoutes(): Route[] {
}
}

return routes;
// Sort alphabetically by page slug to guarantee order regardless of platform.
return routes.sort((a, b) =>
a.slug < b.slug ? -1 : a.slug > b.slug ? 1 : 0
);
}
export const routes = getRoutes();

Expand Down

0 comments on commit 51fe914

Please sign in to comment.