@docusaurus/theme-classic 3.8.1-canary-6373 → 3.8.1-canary-6375
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
|
+
import {translate} from '@docusaurus/Translate';
|
|
8
9
|
import styles from './styles.module.css';
|
|
9
10
|
// References symbol in docusaurus-theme-classic/src/inlineSvgSprites.ts
|
|
10
11
|
// See why: https://github.com/facebook/docusaurus/issues/5865
|
|
@@ -14,7 +15,11 @@ export default function IconExternalLink({width = 13.5, height = 13.5}) {
|
|
|
14
15
|
<svg
|
|
15
16
|
width={width}
|
|
16
17
|
height={height}
|
|
17
|
-
aria-
|
|
18
|
+
aria-label={translate({
|
|
19
|
+
id: 'theme.IconExternalLink.ariaLabel',
|
|
20
|
+
message: '(opens in new tab)',
|
|
21
|
+
description: 'The ARIA label for the external link icon',
|
|
22
|
+
})}
|
|
18
23
|
className={styles.iconExternalLink}>
|
|
19
24
|
<use href={svgSprite} />
|
|
20
25
|
</svg>
|
|
@@ -8,34 +8,79 @@ import React from 'react';
|
|
|
8
8
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
9
9
|
import {useAlternatePageUtils} from '@docusaurus/theme-common/internal';
|
|
10
10
|
import {translate} from '@docusaurus/Translate';
|
|
11
|
-
import {useHistorySelector} from '@docusaurus/theme-common';
|
|
11
|
+
import {mergeSearchStrings, useHistorySelector} from '@docusaurus/theme-common';
|
|
12
12
|
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
|
|
13
13
|
import IconLanguage from '@theme/Icon/Language';
|
|
14
14
|
import styles from './styles.module.css';
|
|
15
|
+
function useLocaleDropdownUtils() {
|
|
16
|
+
const {
|
|
17
|
+
siteConfig,
|
|
18
|
+
i18n: {localeConfigs},
|
|
19
|
+
} = useDocusaurusContext();
|
|
20
|
+
const alternatePageUtils = useAlternatePageUtils();
|
|
21
|
+
const search = useHistorySelector((history) => history.location.search);
|
|
22
|
+
const hash = useHistorySelector((history) => history.location.hash);
|
|
23
|
+
const getLocaleConfig = (locale) => {
|
|
24
|
+
const localeConfig = localeConfigs[locale];
|
|
25
|
+
if (!localeConfig) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`Docusaurus bug, no locale config found for locale=${locale}`,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return localeConfig;
|
|
31
|
+
};
|
|
32
|
+
const getBaseURLForLocale = (locale) => {
|
|
33
|
+
const localeConfig = getLocaleConfig(locale);
|
|
34
|
+
const isSameDomain = localeConfig.url === siteConfig.url;
|
|
35
|
+
if (isSameDomain) {
|
|
36
|
+
// Shorter paths if localized sites are hosted on the same domain
|
|
37
|
+
// This reduces HTML size a bit
|
|
38
|
+
return `pathname://${alternatePageUtils.createUrl({
|
|
39
|
+
locale,
|
|
40
|
+
fullyQualified: false,
|
|
41
|
+
})}`;
|
|
42
|
+
}
|
|
43
|
+
return alternatePageUtils.createUrl({
|
|
44
|
+
locale,
|
|
45
|
+
fullyQualified: true,
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
getURL: (locale, options) => {
|
|
50
|
+
// We have 2 query strings because
|
|
51
|
+
// - there's the current one
|
|
52
|
+
// - there's one user can provide through navbar config
|
|
53
|
+
// see https://github.com/facebook/docusaurus/pull/8915
|
|
54
|
+
const finalSearch = mergeSearchStrings(
|
|
55
|
+
[search, options.queryString],
|
|
56
|
+
'append',
|
|
57
|
+
);
|
|
58
|
+
return `${getBaseURLForLocale(locale)}${finalSearch}${hash}`;
|
|
59
|
+
},
|
|
60
|
+
getLabel: (locale) => {
|
|
61
|
+
return getLocaleConfig(locale).label;
|
|
62
|
+
},
|
|
63
|
+
getLang: (locale) => {
|
|
64
|
+
return getLocaleConfig(locale).htmlLang;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
15
68
|
export default function LocaleDropdownNavbarItem({
|
|
16
69
|
mobile,
|
|
17
70
|
dropdownItemsBefore,
|
|
18
71
|
dropdownItemsAfter,
|
|
19
|
-
queryString
|
|
72
|
+
queryString,
|
|
20
73
|
...props
|
|
21
74
|
}) {
|
|
75
|
+
const utils = useLocaleDropdownUtils();
|
|
22
76
|
const {
|
|
23
|
-
i18n: {currentLocale, locales
|
|
77
|
+
i18n: {currentLocale, locales},
|
|
24
78
|
} = useDocusaurusContext();
|
|
25
|
-
const alternatePageUtils = useAlternatePageUtils();
|
|
26
|
-
const search = useHistorySelector((history) => history.location.search);
|
|
27
|
-
const hash = useHistorySelector((history) => history.location.hash);
|
|
28
79
|
const localeItems = locales.map((locale) => {
|
|
29
|
-
const baseTo = `pathname://${alternatePageUtils.createUrl({
|
|
30
|
-
locale,
|
|
31
|
-
fullyQualified: false,
|
|
32
|
-
})}`;
|
|
33
|
-
// preserve ?search#hash suffix on locale switches
|
|
34
|
-
const to = `${baseTo}${search}${hash}${queryString}`;
|
|
35
80
|
return {
|
|
36
|
-
label:
|
|
37
|
-
lang:
|
|
38
|
-
to,
|
|
81
|
+
label: utils.getLabel(locale),
|
|
82
|
+
lang: utils.getLang(locale),
|
|
83
|
+
to: utils.getURL(locale, {queryString}),
|
|
39
84
|
target: '_self',
|
|
40
85
|
autoAddBaseUrl: false,
|
|
41
86
|
className:
|
|
@@ -58,7 +103,7 @@ export default function LocaleDropdownNavbarItem({
|
|
|
58
103
|
id: 'theme.navbar.mobileLanguageDropdown.label',
|
|
59
104
|
description: 'The label for the mobile language switcher dropdown',
|
|
60
105
|
})
|
|
61
|
-
:
|
|
106
|
+
: utils.getLabel(currentLocale);
|
|
62
107
|
return (
|
|
63
108
|
<DropdownNavbarItem
|
|
64
109
|
{...props}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-classic",
|
|
3
|
-
"version": "3.8.1-canary-
|
|
3
|
+
"version": "3.8.1-canary-6375",
|
|
4
4
|
"description": "Classic theme for Docusaurus",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/theme-classic.d.ts",
|
|
@@ -20,19 +20,19 @@
|
|
|
20
20
|
"copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@docusaurus/core": "3.8.1-canary-
|
|
24
|
-
"@docusaurus/logger": "3.8.1-canary-
|
|
25
|
-
"@docusaurus/mdx-loader": "3.8.1-canary-
|
|
26
|
-
"@docusaurus/module-type-aliases": "3.8.1-canary-
|
|
27
|
-
"@docusaurus/plugin-content-blog": "3.8.1-canary-
|
|
28
|
-
"@docusaurus/plugin-content-docs": "3.8.1-canary-
|
|
29
|
-
"@docusaurus/plugin-content-pages": "3.8.1-canary-
|
|
30
|
-
"@docusaurus/theme-common": "3.8.1-canary-
|
|
31
|
-
"@docusaurus/theme-translations": "3.8.1-canary-
|
|
32
|
-
"@docusaurus/types": "3.8.1-canary-
|
|
33
|
-
"@docusaurus/utils": "3.8.1-canary-
|
|
34
|
-
"@docusaurus/utils-common": "3.8.1-canary-
|
|
35
|
-
"@docusaurus/utils-validation": "3.8.1-canary-
|
|
23
|
+
"@docusaurus/core": "3.8.1-canary-6375",
|
|
24
|
+
"@docusaurus/logger": "3.8.1-canary-6375",
|
|
25
|
+
"@docusaurus/mdx-loader": "3.8.1-canary-6375",
|
|
26
|
+
"@docusaurus/module-type-aliases": "3.8.1-canary-6375",
|
|
27
|
+
"@docusaurus/plugin-content-blog": "3.8.1-canary-6375",
|
|
28
|
+
"@docusaurus/plugin-content-docs": "3.8.1-canary-6375",
|
|
29
|
+
"@docusaurus/plugin-content-pages": "3.8.1-canary-6375",
|
|
30
|
+
"@docusaurus/theme-common": "3.8.1-canary-6375",
|
|
31
|
+
"@docusaurus/theme-translations": "3.8.1-canary-6375",
|
|
32
|
+
"@docusaurus/types": "3.8.1-canary-6375",
|
|
33
|
+
"@docusaurus/utils": "3.8.1-canary-6375",
|
|
34
|
+
"@docusaurus/utils-common": "3.8.1-canary-6375",
|
|
35
|
+
"@docusaurus/utils-validation": "3.8.1-canary-6375",
|
|
36
36
|
"@mdx-js/react": "^3.0.0",
|
|
37
37
|
"clsx": "^2.0.0",
|
|
38
38
|
"copy-text-to-clipboard": "^3.2.0",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">=18.0"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "1892984e51e133ffb5cc066116eda647753dbfb2"
|
|
66
66
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import React, {type ReactNode} from 'react';
|
|
9
|
+
import {translate} from '@docusaurus/Translate';
|
|
9
10
|
import type {Props} from '@theme/Icon/ExternalLink';
|
|
10
11
|
|
|
11
12
|
import styles from './styles.module.css';
|
|
@@ -22,7 +23,11 @@ export default function IconExternalLink({
|
|
|
22
23
|
<svg
|
|
23
24
|
width={width}
|
|
24
25
|
height={height}
|
|
25
|
-
aria-
|
|
26
|
+
aria-label={translate({
|
|
27
|
+
id: 'theme.IconExternalLink.ariaLabel',
|
|
28
|
+
message: '(opens in new tab)',
|
|
29
|
+
description: 'The ARIA label for the external link icon',
|
|
30
|
+
})}
|
|
26
31
|
className={styles.iconExternalLink}>
|
|
27
32
|
<use href={svgSprite} />
|
|
28
33
|
</svg>
|
|
@@ -9,7 +9,7 @@ import React, {type ReactNode} from 'react';
|
|
|
9
9
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
10
10
|
import {useAlternatePageUtils} from '@docusaurus/theme-common/internal';
|
|
11
11
|
import {translate} from '@docusaurus/Translate';
|
|
12
|
-
import {useHistorySelector} from '@docusaurus/theme-common';
|
|
12
|
+
import {mergeSearchStrings, useHistorySelector} from '@docusaurus/theme-common';
|
|
13
13
|
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
|
|
14
14
|
import IconLanguage from '@theme/Icon/Language';
|
|
15
15
|
import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem';
|
|
@@ -17,31 +17,80 @@ import type {Props} from '@theme/NavbarItem/LocaleDropdownNavbarItem';
|
|
|
17
17
|
|
|
18
18
|
import styles from './styles.module.css';
|
|
19
19
|
|
|
20
|
+
function useLocaleDropdownUtils() {
|
|
21
|
+
const {
|
|
22
|
+
siteConfig,
|
|
23
|
+
i18n: {localeConfigs},
|
|
24
|
+
} = useDocusaurusContext();
|
|
25
|
+
const alternatePageUtils = useAlternatePageUtils();
|
|
26
|
+
const search = useHistorySelector((history) => history.location.search);
|
|
27
|
+
const hash = useHistorySelector((history) => history.location.hash);
|
|
28
|
+
|
|
29
|
+
const getLocaleConfig = (locale: string) => {
|
|
30
|
+
const localeConfig = localeConfigs[locale];
|
|
31
|
+
if (!localeConfig) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`Docusaurus bug, no locale config found for locale=${locale}`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return localeConfig;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const getBaseURLForLocale = (locale: string) => {
|
|
40
|
+
const localeConfig = getLocaleConfig(locale);
|
|
41
|
+
const isSameDomain = localeConfig.url === siteConfig.url;
|
|
42
|
+
if (isSameDomain) {
|
|
43
|
+
// Shorter paths if localized sites are hosted on the same domain
|
|
44
|
+
// This reduces HTML size a bit
|
|
45
|
+
return `pathname://${alternatePageUtils.createUrl({
|
|
46
|
+
locale,
|
|
47
|
+
fullyQualified: false,
|
|
48
|
+
})}`;
|
|
49
|
+
}
|
|
50
|
+
return alternatePageUtils.createUrl({
|
|
51
|
+
locale,
|
|
52
|
+
fullyQualified: true,
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
getURL: (locale: string, options: {queryString: string | undefined}) => {
|
|
58
|
+
// We have 2 query strings because
|
|
59
|
+
// - there's the current one
|
|
60
|
+
// - there's one user can provide through navbar config
|
|
61
|
+
// see https://github.com/facebook/docusaurus/pull/8915
|
|
62
|
+
const finalSearch = mergeSearchStrings(
|
|
63
|
+
[search, options.queryString],
|
|
64
|
+
'append',
|
|
65
|
+
);
|
|
66
|
+
return `${getBaseURLForLocale(locale)}${finalSearch}${hash}`;
|
|
67
|
+
},
|
|
68
|
+
getLabel: (locale: string) => {
|
|
69
|
+
return getLocaleConfig(locale).label;
|
|
70
|
+
},
|
|
71
|
+
getLang: (locale: string) => {
|
|
72
|
+
return getLocaleConfig(locale).htmlLang;
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
20
77
|
export default function LocaleDropdownNavbarItem({
|
|
21
78
|
mobile,
|
|
22
79
|
dropdownItemsBefore,
|
|
23
80
|
dropdownItemsAfter,
|
|
24
|
-
queryString
|
|
81
|
+
queryString,
|
|
25
82
|
...props
|
|
26
83
|
}: Props): ReactNode {
|
|
84
|
+
const utils = useLocaleDropdownUtils();
|
|
85
|
+
|
|
27
86
|
const {
|
|
28
|
-
i18n: {currentLocale, locales
|
|
87
|
+
i18n: {currentLocale, locales},
|
|
29
88
|
} = useDocusaurusContext();
|
|
30
|
-
const alternatePageUtils = useAlternatePageUtils();
|
|
31
|
-
const search = useHistorySelector((history) => history.location.search);
|
|
32
|
-
const hash = useHistorySelector((history) => history.location.hash);
|
|
33
|
-
|
|
34
89
|
const localeItems = locales.map((locale): LinkLikeNavbarItemProps => {
|
|
35
|
-
const baseTo = `pathname://${alternatePageUtils.createUrl({
|
|
36
|
-
locale,
|
|
37
|
-
fullyQualified: false,
|
|
38
|
-
})}`;
|
|
39
|
-
// preserve ?search#hash suffix on locale switches
|
|
40
|
-
const to = `${baseTo}${search}${hash}${queryString}`;
|
|
41
90
|
return {
|
|
42
|
-
label:
|
|
43
|
-
lang:
|
|
44
|
-
to,
|
|
91
|
+
label: utils.getLabel(locale),
|
|
92
|
+
lang: utils.getLang(locale),
|
|
93
|
+
to: utils.getURL(locale, {queryString}),
|
|
45
94
|
target: '_self',
|
|
46
95
|
autoAddBaseUrl: false,
|
|
47
96
|
className:
|
|
@@ -66,7 +115,7 @@ export default function LocaleDropdownNavbarItem({
|
|
|
66
115
|
id: 'theme.navbar.mobileLanguageDropdown.label',
|
|
67
116
|
description: 'The label for the mobile language switcher dropdown',
|
|
68
117
|
})
|
|
69
|
-
:
|
|
118
|
+
: utils.getLabel(currentLocale);
|
|
70
119
|
|
|
71
120
|
return (
|
|
72
121
|
<DropdownNavbarItem
|