-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(theme-classic): allow specifying query string for detecting locale changes #5890
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,11 @@ export function useAlternatePageUtils(): { | |
createUrl: ({ | ||
locale, | ||
fullyQualified, | ||
queryString, | ||
}: { | ||
locale: string; | ||
fullyQualified: boolean; | ||
queryString?: string; | ||
}) => string; | ||
} { | ||
const { | ||
|
@@ -43,15 +45,21 @@ export function useAlternatePageUtils(): { | |
function createUrl({ | ||
locale, | ||
fullyQualified, | ||
queryString, | ||
}: { | ||
locale: string; | ||
// For hreflang SEO headers, we need it to be fully qualified (full protocol/domain/path...) | ||
// For locale dropdown, using a path is good enough | ||
fullyQualified: boolean; | ||
// Appends a query string parameter with the selected locale | ||
queryString?: string; | ||
}) { | ||
const queryStringSuffix = queryString | ||
? `?${queryString}=${encodeURIComponent(locale)}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need
We'd rather rename this |
||
: ''; | ||
return `${fullyQualified ? url : ''}${getLocalizedBaseUrl( | ||
locale, | ||
)}${pathnameSuffix}`; | ||
)}${pathnameSuffix}${queryStringSuffix}`; | ||
} | ||
|
||
return {createUrl}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,13 +126,15 @@ export type I18nConfig = { | |
defaultLocale: string; | ||
locales: [string, ...string[]]; | ||
localeConfigs: Record<string, Partial<I18nLocaleConfig>>; | ||
queryString?: string; | ||
}; | ||
|
||
export type I18n = { | ||
defaultLocale: string; | ||
locales: [string, ...string[]]; | ||
currentLocale: string; | ||
localeConfigs: Record<string, I18nLocaleConfig>; | ||
queryString?: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think Persisting a chosen locale in some storage is a theming concern, not a core concern. It's not all or nothing, and locale change links shouldn't necessarily have this querystring. plus a I'd rather have this as a locale dropdown config for now |
||
}; | ||
|
||
export interface DocusaurusContext { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a good place to handle that
And this code is used to generate meta SEO hreflang headers too, which should not include that querystring
https://developers.google.com/search/docs/advanced/crawling/localized-versions
And a fully qualified URL (provided as param) may already contain a querystring