@docusaurus/theme-classic 0.0.0-4433 → 0.0.0-4438
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.
- package/lib/index.js +5 -3
- package/lib-next/theme/CodeBlock/index.js +3 -3
- package/lib-next/theme/LayoutHead/index.js +5 -9
- package/lib-next/theme/prism-include-languages.js +10 -3
- package/package.json +12 -12
- package/src/index.ts +8 -9
- package/src/theme/CodeBlock/index.tsx +3 -3
- package/src/theme/LayoutHead/index.tsx +4 -8
- package/src/theme/NavbarItem/index.tsx +1 -1
- package/src/theme/prism-include-languages.ts +10 -3
package/lib/index.js
CHANGED
|
@@ -101,8 +101,7 @@ function getInfimaCSSFile(direction) {
|
|
|
101
101
|
return `infima/dist/css/default/default${direction === 'rtl' ? '-rtl' : ''}.css`;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
function docusaurusThemeClassic(context,
|
|
105
|
-
options) {
|
|
104
|
+
function docusaurusThemeClassic(context, options) {
|
|
106
105
|
const {
|
|
107
106
|
siteConfig: {
|
|
108
107
|
themeConfig: roughlyTypedThemeConfig
|
|
@@ -178,7 +177,10 @@ options) {
|
|
|
178
177
|
configureWebpack() {
|
|
179
178
|
const prismLanguages = additionalLanguages.map(lang => `prism-${lang}`).join('|');
|
|
180
179
|
return {
|
|
181
|
-
plugins: [
|
|
180
|
+
plugins: [// This allows better optimization by only bundling those components
|
|
181
|
+
// that the user actually needs, because the modules are dynamically
|
|
182
|
+
// required and can't be known during compile time.
|
|
183
|
+
new ContextReplacementPlugin(/prismjs[\\/]components$/, new RegExp(`^./(${prismLanguages})$`))]
|
|
182
184
|
};
|
|
183
185
|
},
|
|
184
186
|
|
|
@@ -37,9 +37,9 @@ export default function CodeBlock({
|
|
|
37
37
|
|
|
38
38
|
useEffect(() => {
|
|
39
39
|
setMounted(true);
|
|
40
|
-
}, []); //
|
|
41
|
-
//
|
|
42
|
-
//
|
|
40
|
+
}, []); // We still parse the metastring in case we want to support more syntax in the
|
|
41
|
+
// future. Note that MDX doesn't strip quotes when parsing metastring:
|
|
42
|
+
// "title=\"xyz\"" => title: "\"xyz\""
|
|
43
43
|
|
|
44
44
|
const codeBlockTitle = parseCodeBlockTitle(metastring) || title;
|
|
45
45
|
const prismTheme = usePrismTheme(); // <pre> tags in markdown map to CodeBlocks and they may contain JSX children.
|
|
@@ -22,14 +22,14 @@ import {useLocation} from '@docusaurus/router'; // Useful for SEO
|
|
|
22
22
|
|
|
23
23
|
function AlternateLangHeaders() {
|
|
24
24
|
const {
|
|
25
|
-
i18n: {defaultLocale,
|
|
25
|
+
i18n: {defaultLocale, localeConfigs},
|
|
26
26
|
} = useDocusaurusContext();
|
|
27
27
|
const alternatePageUtils = useAlternatePageUtils(); // Note: it is fine to use both "x-default" and "en" to target the same url
|
|
28
28
|
// See https://www.searchviu.com/en/multiple-hreflang-tags-one-url/
|
|
29
29
|
|
|
30
30
|
return (
|
|
31
31
|
<Head>
|
|
32
|
-
{
|
|
32
|
+
{Object.entries(localeConfigs).map(([locale, {htmlLang}]) => (
|
|
33
33
|
<link
|
|
34
34
|
key={locale}
|
|
35
35
|
rel="alternate"
|
|
@@ -37,7 +37,7 @@ function AlternateLangHeaders() {
|
|
|
37
37
|
locale,
|
|
38
38
|
fullyQualified: true,
|
|
39
39
|
})}
|
|
40
|
-
hrefLang={
|
|
40
|
+
hrefLang={htmlLang}
|
|
41
41
|
/>
|
|
42
42
|
))}
|
|
43
43
|
<link
|
|
@@ -84,12 +84,8 @@ export default function LayoutHead(props) {
|
|
|
84
84
|
const {metadata, image: defaultImage} = useThemeConfig();
|
|
85
85
|
const {title, description, image, keywords, searchMetadata} = props;
|
|
86
86
|
const faviconUrl = useBaseUrl(favicon);
|
|
87
|
-
const pageTitle = useTitleFormatter(title);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const htmlLang = currentLocale; // should we allow the user to override htmlLang with localeConfig?
|
|
91
|
-
|
|
92
|
-
const htmlDir = localeConfigs[currentLocale].direction;
|
|
87
|
+
const pageTitle = useTitleFormatter(title);
|
|
88
|
+
const {htmlLang, direction: htmlDir} = localeConfigs[currentLocale];
|
|
93
89
|
return (
|
|
94
90
|
<>
|
|
95
91
|
<Head>
|
|
@@ -10,12 +10,19 @@ import siteConfig from '@generated/docusaurus.config';
|
|
|
10
10
|
const prismIncludeLanguages = (PrismObject) => {
|
|
11
11
|
if (ExecutionEnvironment.canUseDOM) {
|
|
12
12
|
const {
|
|
13
|
-
themeConfig: {prism
|
|
13
|
+
themeConfig: {prism},
|
|
14
14
|
} = siteConfig;
|
|
15
|
-
const {additionalLanguages
|
|
15
|
+
const {additionalLanguages} = prism; // Prism components work on the Prism instance on the window, while
|
|
16
|
+
// prism-react-renderer uses its own Prism instance. We temporarily mount
|
|
17
|
+
// the instance onto window, import components to enhance it, then remove it
|
|
18
|
+
// to avoid polluting global namespace.
|
|
19
|
+
// You can mutate this object: registering plugins, deleting languages... As
|
|
20
|
+
// long as you don't re-assign it
|
|
21
|
+
|
|
16
22
|
window.Prism = PrismObject;
|
|
17
23
|
additionalLanguages.forEach((lang) => {
|
|
18
|
-
|
|
24
|
+
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
25
|
+
require(`prismjs/components/prism-${lang}`);
|
|
19
26
|
});
|
|
20
27
|
delete window.Prism;
|
|
21
28
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-classic",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4438",
|
|
4
4
|
"description": "Classic theme for Docusaurus",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/theme-classic.d.ts",
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
"update-code-translations": "node -e 'require(\"./update-code-translations.js\").run()'"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@docusaurus/core": "0.0.0-
|
|
27
|
-
"@docusaurus/plugin-content-blog": "0.0.0-
|
|
28
|
-
"@docusaurus/plugin-content-docs": "0.0.0-
|
|
29
|
-
"@docusaurus/plugin-content-pages": "0.0.0-
|
|
30
|
-
"@docusaurus/theme-common": "0.0.0-
|
|
31
|
-
"@docusaurus/theme-translations": "0.0.0-
|
|
32
|
-
"@docusaurus/utils": "0.0.0-
|
|
33
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
26
|
+
"@docusaurus/core": "0.0.0-4438",
|
|
27
|
+
"@docusaurus/plugin-content-blog": "0.0.0-4438",
|
|
28
|
+
"@docusaurus/plugin-content-docs": "0.0.0-4438",
|
|
29
|
+
"@docusaurus/plugin-content-pages": "0.0.0-4438",
|
|
30
|
+
"@docusaurus/theme-common": "0.0.0-4438",
|
|
31
|
+
"@docusaurus/theme-translations": "0.0.0-4438",
|
|
32
|
+
"@docusaurus/utils": "0.0.0-4438",
|
|
33
|
+
"@docusaurus/utils-validation": "0.0.0-4438",
|
|
34
34
|
"@mdx-js/mdx": "^1.6.21",
|
|
35
35
|
"@mdx-js/react": "^1.6.21",
|
|
36
36
|
"clsx": "^1.1.1",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"rtlcss": "^3.3.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
49
|
-
"@docusaurus/types": "0.0.0-
|
|
48
|
+
"@docusaurus/module-type-aliases": "0.0.0-4438",
|
|
49
|
+
"@docusaurus/types": "0.0.0-4438",
|
|
50
50
|
"@types/mdx-js__react": "^1.5.4",
|
|
51
51
|
"@types/parse-numeric-range": "^0.0.1",
|
|
52
52
|
"@types/rtlcss": "^3.1.1",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"engines": {
|
|
62
62
|
"node": ">=14"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "57921f1d0dcfba6d734f8617b34e495ccb1622b0"
|
|
65
65
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,11 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {
|
|
9
|
-
DocusaurusContext,
|
|
10
|
-
Plugin,
|
|
11
|
-
PostCssOptions,
|
|
12
|
-
} from '@docusaurus/types';
|
|
8
|
+
import type {LoadContext, Plugin, PostCssOptions} from '@docusaurus/types';
|
|
13
9
|
import type {ThemeConfig} from '@docusaurus/theme-common';
|
|
14
10
|
import {getTranslationFiles, translateThemeConfig} from './translations';
|
|
15
11
|
import path from 'path';
|
|
@@ -18,13 +14,13 @@ import type {Plugin as PostCssPlugin} from 'postcss';
|
|
|
18
14
|
import rtlcss from 'rtlcss';
|
|
19
15
|
import {readDefaultCodeTranslationMessages} from '@docusaurus/theme-translations';
|
|
20
16
|
import type {Options} from '@docusaurus/theme-classic';
|
|
17
|
+
import type webpack from 'webpack';
|
|
21
18
|
|
|
22
19
|
const requireFromDocusaurusCore = createRequire(
|
|
23
20
|
require.resolve('@docusaurus/core/package.json'),
|
|
24
21
|
);
|
|
25
|
-
const ContextReplacementPlugin =
|
|
26
|
-
'webpack/lib/ContextReplacementPlugin'
|
|
27
|
-
);
|
|
22
|
+
const ContextReplacementPlugin: typeof webpack.ContextReplacementPlugin =
|
|
23
|
+
requireFromDocusaurusCore('webpack/lib/ContextReplacementPlugin');
|
|
28
24
|
|
|
29
25
|
// Need to be inlined to prevent dark mode FOUC
|
|
30
26
|
// Make sure that the 'storageKey' is the same as the one in `/theme/hooks/useTheme.js`
|
|
@@ -95,7 +91,7 @@ function getInfimaCSSFile(direction: string) {
|
|
|
95
91
|
}
|
|
96
92
|
|
|
97
93
|
export default function docusaurusThemeClassic(
|
|
98
|
-
context:
|
|
94
|
+
context: LoadContext,
|
|
99
95
|
options: Options,
|
|
100
96
|
): Plugin<void> {
|
|
101
97
|
const {
|
|
@@ -172,6 +168,9 @@ export default function docusaurusThemeClassic(
|
|
|
172
168
|
|
|
173
169
|
return {
|
|
174
170
|
plugins: [
|
|
171
|
+
// This allows better optimization by only bundling those components
|
|
172
|
+
// that the user actually needs, because the modules are dynamically
|
|
173
|
+
// required and can't be known during compile time.
|
|
175
174
|
new ContextReplacementPlugin(
|
|
176
175
|
/prismjs[\\/]components$/,
|
|
177
176
|
new RegExp(`^./(${prismLanguages})$`),
|
|
@@ -44,9 +44,9 @@ export default function CodeBlock({
|
|
|
44
44
|
setMounted(true);
|
|
45
45
|
}, []);
|
|
46
46
|
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
//
|
|
47
|
+
// We still parse the metastring in case we want to support more syntax in the
|
|
48
|
+
// future. Note that MDX doesn't strip quotes when parsing metastring:
|
|
49
|
+
// "title=\"xyz\"" => title: "\"xyz\""
|
|
50
50
|
const codeBlockTitle = parseCodeBlockTitle(metastring) || title;
|
|
51
51
|
const prismTheme = usePrismTheme();
|
|
52
52
|
|
|
@@ -25,7 +25,7 @@ import {useLocation} from '@docusaurus/router';
|
|
|
25
25
|
// See https://github.com/facebook/docusaurus/issues/3317
|
|
26
26
|
function AlternateLangHeaders(): JSX.Element {
|
|
27
27
|
const {
|
|
28
|
-
i18n: {defaultLocale,
|
|
28
|
+
i18n: {defaultLocale, localeConfigs},
|
|
29
29
|
} = useDocusaurusContext();
|
|
30
30
|
const alternatePageUtils = useAlternatePageUtils();
|
|
31
31
|
|
|
@@ -33,7 +33,7 @@ function AlternateLangHeaders(): JSX.Element {
|
|
|
33
33
|
// See https://www.searchviu.com/en/multiple-hreflang-tags-one-url/
|
|
34
34
|
return (
|
|
35
35
|
<Head>
|
|
36
|
-
{
|
|
36
|
+
{Object.entries(localeConfigs).map(([locale, {htmlLang}]) => (
|
|
37
37
|
<link
|
|
38
38
|
key={locale}
|
|
39
39
|
rel="alternate"
|
|
@@ -41,7 +41,7 @@ function AlternateLangHeaders(): JSX.Element {
|
|
|
41
41
|
locale,
|
|
42
42
|
fullyQualified: true,
|
|
43
43
|
})}
|
|
44
|
-
hrefLang={
|
|
44
|
+
hrefLang={htmlLang}
|
|
45
45
|
/>
|
|
46
46
|
))}
|
|
47
47
|
<link
|
|
@@ -91,11 +91,7 @@ export default function LayoutHead(props: Props): JSX.Element {
|
|
|
91
91
|
const {title, description, image, keywords, searchMetadata} = props;
|
|
92
92
|
const faviconUrl = useBaseUrl(favicon);
|
|
93
93
|
const pageTitle = useTitleFormatter(title);
|
|
94
|
-
|
|
95
|
-
// See https://github.com/facebook/docusaurus/issues/3317#issuecomment-754661855
|
|
96
|
-
// const htmlLang = currentLocale.split('-')[0];
|
|
97
|
-
const htmlLang = currentLocale; // should we allow the user to override htmlLang with localeConfig?
|
|
98
|
-
const htmlDir = localeConfigs[currentLocale].direction;
|
|
94
|
+
const {htmlLang, direction: htmlDir} = localeConfigs[currentLocale];
|
|
99
95
|
|
|
100
96
|
return (
|
|
101
97
|
<>
|
|
@@ -16,7 +16,7 @@ import type {Types, Props} from '@theme/NavbarItem';
|
|
|
16
16
|
|
|
17
17
|
const NavbarItemComponents: Record<
|
|
18
18
|
Exclude<Types, undefined>,
|
|
19
|
-
//
|
|
19
|
+
// Not really worth typing, as we pass all props down immediately
|
|
20
20
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
21
|
() => (props: any) => JSX.Element
|
|
22
22
|
> = {
|
|
@@ -12,14 +12,21 @@ import type * as PrismNamespace from 'prismjs';
|
|
|
12
12
|
const prismIncludeLanguages = (PrismObject: typeof PrismNamespace): void => {
|
|
13
13
|
if (ExecutionEnvironment.canUseDOM) {
|
|
14
14
|
const {
|
|
15
|
-
themeConfig: {prism
|
|
15
|
+
themeConfig: {prism},
|
|
16
16
|
} = siteConfig;
|
|
17
|
-
const {additionalLanguages
|
|
17
|
+
const {additionalLanguages} = prism as {additionalLanguages: string[]};
|
|
18
18
|
|
|
19
|
+
// Prism components work on the Prism instance on the window, while
|
|
20
|
+
// prism-react-renderer uses its own Prism instance. We temporarily mount
|
|
21
|
+
// the instance onto window, import components to enhance it, then remove it
|
|
22
|
+
// to avoid polluting global namespace.
|
|
23
|
+
// You can mutate this object: registering plugins, deleting languages... As
|
|
24
|
+
// long as you don't re-assign it
|
|
19
25
|
window.Prism = PrismObject;
|
|
20
26
|
|
|
21
27
|
additionalLanguages.forEach((lang) => {
|
|
22
|
-
|
|
28
|
+
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
29
|
+
require(`prismjs/components/prism-${lang}`);
|
|
23
30
|
});
|
|
24
31
|
|
|
25
32
|
delete (window as Window & {Prism?: typeof PrismNamespace}).Prism;
|