From 51fe91468fea125ec33cb6d6b1b66f147302fdc0 Mon Sep 17 00:00:00 2001 From: Chris Swithinbank Date: Fri, 26 May 2023 10:43:02 +0200 Subject: [PATCH] Guarantee route and autogenerated sidebar sort order --- .changeset/shy-parrots-dance.md | 5 +++++ docs/src/content/docs/reference/configuration.md | 5 +++++ packages/starlight/utils/routing.ts | 5 ++++- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .changeset/shy-parrots-dance.md diff --git a/.changeset/shy-parrots-dance.md b/.changeset/shy-parrots-dance.md new file mode 100644 index 0000000000..2687b9e06a --- /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 8a43abf973..06381c8665 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 e8d56254a9..ab8344f003 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();