-
-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: fallback to default locale in project without a root locale for pages not matching the default locale slug * Update changeset * refactor: remove duplicated `slugToLocale()` --------- Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
- Loading branch information
Showing
6 changed files
with
49 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/starlight': patch | ||
--- | ||
|
||
Fixes a URL localization edge case. In projects without a root locale configured, slugs without a locale prefix did not fall back to the default locale as expected. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { StarlightConfig } from '../../types'; | ||
|
||
/** | ||
* Get the “locale” of a slug. This is the base path at which a language is served. | ||
* For example, if French docs are in `src/content/docs/french/`, the locale is `french`. | ||
* Root locale slugs will return `undefined`. | ||
* @param slug A collection entry slug | ||
*/ | ||
export function slugToLocale( | ||
slug: string | undefined, | ||
config: Pick<StarlightConfig, 'defaultLocale' | 'locales'> | ||
): string | undefined { | ||
const localesConfig = config.locales ?? {}; | ||
const baseSegment = slug?.split('/')[0]; | ||
if (baseSegment && localesConfig[baseSegment]) return baseSegment; | ||
if (!localesConfig.root) return config.defaultLocale.locale; | ||
return undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters