summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Swithinbank2023-05-26 10:43:02 +0200
committerChris Swithinbank2023-05-26 10:43:02 +0200
commit51fe91468fea125ec33cb6d6b1b66f147302fdc0 (patch)
treef4aa6105728cb8ce9bfc681f0e547bcc190b6504
parented808dc5bc92354488dbd9d45253fb498c933489 (diff)
downloadIT.starlight-51fe91468fea125ec33cb6d6b1b66f147302fdc0.tar.gz
IT.starlight-51fe91468fea125ec33cb6d6b1b66f147302fdc0.tar.bz2
IT.starlight-51fe91468fea125ec33cb6d6b1b66f147302fdc0.zip
Guarantee route and autogenerated sidebar sort order
-rw-r--r--.changeset/shy-parrots-dance.md5
-rw-r--r--docs/src/content/docs/reference/configuration.md5
-rw-r--r--packages/starlight/utils/routing.ts5
3 files changed, 14 insertions, 1 deletions
diff --git a/.changeset/shy-parrots-dance.md b/.changeset/shy-parrots-dance.md
new file mode 100644
index 00000000..2687b9e0
--- /dev/null
+++ b/.changeset/shy-parrots-dance.md
@@ -0,0 +1,5 @@
+---
+"@astrojs/starlight": patch
+---
+
+Guarantee route and autogenerated sidebar sort order
diff --git a/docs/src/content/docs/reference/configuration.md b/docs/src/content/docs/reference/configuration.md
index 8a43abf9..06381c86 100644
--- a/docs/src/content/docs/reference/configuration.md
+++ b/docs/src/content/docs/reference/configuration.md
@@ -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
diff --git a/packages/starlight/utils/routing.ts b/packages/starlight/utils/routing.ts
index e8d56254..ab8344f0 100644
--- a/packages/starlight/utils/routing.ts
+++ b/packages/starlight/utils/routing.ts
@@ -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();