@docusaurus/theme-classic 0.0.0-5590 → 0.0.0-5591
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 +20 -6
- package/package.json +14 -14
- package/src/index.ts +21 -6
package/lib/index.js
CHANGED
|
@@ -18,7 +18,10 @@ const ContextReplacementPlugin = requireFromDocusaurusCore('webpack/lib/ContextR
|
|
|
18
18
|
// Need to be inlined to prevent dark mode FOUC
|
|
19
19
|
// Make sure the key is the same as the one in `/theme/hooks/useTheme.js`
|
|
20
20
|
const ThemeStorageKey = 'theme';
|
|
21
|
+
// Support for ?docusaurus-theme=dark
|
|
21
22
|
const ThemeQueryStringKey = 'docusaurus-theme';
|
|
23
|
+
// Support for ?docusaurus-data-mode=embed&docusaurus-data-myAttr=42
|
|
24
|
+
const DataQueryStringPrefixKey = 'docusaurus-data-';
|
|
22
25
|
const noFlashColorMode = ({ defaultMode, respectPrefersColorScheme, }) =>
|
|
23
26
|
/* language=js */
|
|
24
27
|
`(function() {
|
|
@@ -30,19 +33,15 @@ const noFlashColorMode = ({ defaultMode, respectPrefersColorScheme, }) =>
|
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
function getQueryStringTheme() {
|
|
33
|
-
var theme = null;
|
|
34
36
|
try {
|
|
35
|
-
|
|
37
|
+
return new URLSearchParams(window.location.search).get('${ThemeQueryStringKey}')
|
|
36
38
|
} catch(e) {}
|
|
37
|
-
return theme;
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
function getStoredTheme() {
|
|
41
|
-
var theme = null;
|
|
42
42
|
try {
|
|
43
|
-
|
|
43
|
+
return localStorage.getItem('${ThemeStorageKey}');
|
|
44
44
|
} catch (err) {}
|
|
45
|
-
return theme;
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
var initialTheme = getQueryStringTheme() || getStoredTheme();
|
|
@@ -64,6 +63,20 @@ const noFlashColorMode = ({ defaultMode, respectPrefersColorScheme, }) =>
|
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
})();`;
|
|
66
|
+
/* language=js */
|
|
67
|
+
const DataAttributeQueryStringInlineJavaScript = `
|
|
68
|
+
(function() {
|
|
69
|
+
try {
|
|
70
|
+
const entries = new URLSearchParams(window.location.search).entries();
|
|
71
|
+
for (var [searchKey, value] of entries) {
|
|
72
|
+
if (searchKey.startsWith('${DataQueryStringPrefixKey}')) {
|
|
73
|
+
var key = searchKey.replace('${DataQueryStringPrefixKey}',"data-")
|
|
74
|
+
document.documentElement.setAttribute(key, value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
} catch(e) {}
|
|
78
|
+
})();
|
|
79
|
+
`;
|
|
67
80
|
// Duplicated constant. Unfortunately we can't import it from theme-common, as
|
|
68
81
|
// we need to support older nodejs versions without ESM support
|
|
69
82
|
// TODO: import from theme-common once we only support Node.js with ESM support
|
|
@@ -159,6 +172,7 @@ function themeClassic(context, options) {
|
|
|
159
172
|
tagName: 'script',
|
|
160
173
|
innerHTML: `
|
|
161
174
|
${noFlashColorMode(colorMode)}
|
|
175
|
+
${DataAttributeQueryStringInlineJavaScript}
|
|
162
176
|
${announcementBar ? AnnouncementBarInlineJavaScript : ''}
|
|
163
177
|
`,
|
|
164
178
|
},
|
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-5591",
|
|
4
4
|
"description": "Classic theme for Docusaurus",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/theme-classic.d.ts",
|
|
@@ -20,18 +20,18 @@
|
|
|
20
20
|
"copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@docusaurus/core": "0.0.0-
|
|
24
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
25
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
26
|
-
"@docusaurus/plugin-content-blog": "0.0.0-
|
|
27
|
-
"@docusaurus/plugin-content-docs": "0.0.0-
|
|
28
|
-
"@docusaurus/plugin-content-pages": "0.0.0-
|
|
29
|
-
"@docusaurus/theme-common": "0.0.0-
|
|
30
|
-
"@docusaurus/theme-translations": "0.0.0-
|
|
31
|
-
"@docusaurus/types": "0.0.0-
|
|
32
|
-
"@docusaurus/utils": "0.0.0-
|
|
33
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
34
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
23
|
+
"@docusaurus/core": "0.0.0-5591",
|
|
24
|
+
"@docusaurus/mdx-loader": "0.0.0-5591",
|
|
25
|
+
"@docusaurus/module-type-aliases": "0.0.0-5591",
|
|
26
|
+
"@docusaurus/plugin-content-blog": "0.0.0-5591",
|
|
27
|
+
"@docusaurus/plugin-content-docs": "0.0.0-5591",
|
|
28
|
+
"@docusaurus/plugin-content-pages": "0.0.0-5591",
|
|
29
|
+
"@docusaurus/theme-common": "0.0.0-5591",
|
|
30
|
+
"@docusaurus/theme-translations": "0.0.0-5591",
|
|
31
|
+
"@docusaurus/types": "0.0.0-5591",
|
|
32
|
+
"@docusaurus/utils": "0.0.0-5591",
|
|
33
|
+
"@docusaurus/utils-common": "0.0.0-5591",
|
|
34
|
+
"@docusaurus/utils-validation": "0.0.0-5591",
|
|
35
35
|
"@mdx-js/react": "^2.1.5",
|
|
36
36
|
"clsx": "^1.2.1",
|
|
37
37
|
"copy-text-to-clipboard": "^3.0.1",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">=16.14"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "29dfa268a45ef335b912fffe4d79ec9a40d92cf9"
|
|
66
66
|
}
|
package/src/index.ts
CHANGED
|
@@ -26,7 +26,10 @@ const ContextReplacementPlugin = requireFromDocusaurusCore(
|
|
|
26
26
|
// Need to be inlined to prevent dark mode FOUC
|
|
27
27
|
// Make sure the key is the same as the one in `/theme/hooks/useTheme.js`
|
|
28
28
|
const ThemeStorageKey = 'theme';
|
|
29
|
+
// Support for ?docusaurus-theme=dark
|
|
29
30
|
const ThemeQueryStringKey = 'docusaurus-theme';
|
|
31
|
+
// Support for ?docusaurus-data-mode=embed&docusaurus-data-myAttr=42
|
|
32
|
+
const DataQueryStringPrefixKey = 'docusaurus-data-';
|
|
30
33
|
|
|
31
34
|
const noFlashColorMode = ({
|
|
32
35
|
defaultMode,
|
|
@@ -42,19 +45,15 @@ const noFlashColorMode = ({
|
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
function getQueryStringTheme() {
|
|
45
|
-
var theme = null;
|
|
46
48
|
try {
|
|
47
|
-
|
|
49
|
+
return new URLSearchParams(window.location.search).get('${ThemeQueryStringKey}')
|
|
48
50
|
} catch(e) {}
|
|
49
|
-
return theme;
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
function getStoredTheme() {
|
|
53
|
-
var theme = null;
|
|
54
54
|
try {
|
|
55
|
-
|
|
55
|
+
return localStorage.getItem('${ThemeStorageKey}');
|
|
56
56
|
} catch (err) {}
|
|
57
|
-
return theme;
|
|
58
57
|
}
|
|
59
58
|
|
|
60
59
|
var initialTheme = getQueryStringTheme() || getStoredTheme();
|
|
@@ -77,6 +76,21 @@ const noFlashColorMode = ({
|
|
|
77
76
|
}
|
|
78
77
|
})();`;
|
|
79
78
|
|
|
79
|
+
/* language=js */
|
|
80
|
+
const DataAttributeQueryStringInlineJavaScript = `
|
|
81
|
+
(function() {
|
|
82
|
+
try {
|
|
83
|
+
const entries = new URLSearchParams(window.location.search).entries();
|
|
84
|
+
for (var [searchKey, value] of entries) {
|
|
85
|
+
if (searchKey.startsWith('${DataQueryStringPrefixKey}')) {
|
|
86
|
+
var key = searchKey.replace('${DataQueryStringPrefixKey}',"data-")
|
|
87
|
+
document.documentElement.setAttribute(key, value);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
} catch(e) {}
|
|
91
|
+
})();
|
|
92
|
+
`;
|
|
93
|
+
|
|
80
94
|
// Duplicated constant. Unfortunately we can't import it from theme-common, as
|
|
81
95
|
// we need to support older nodejs versions without ESM support
|
|
82
96
|
// TODO: import from theme-common once we only support Node.js with ESM support
|
|
@@ -205,6 +219,7 @@ export default function themeClassic(
|
|
|
205
219
|
tagName: 'script',
|
|
206
220
|
innerHTML: `
|
|
207
221
|
${noFlashColorMode(colorMode)}
|
|
222
|
+
${DataAttributeQueryStringInlineJavaScript}
|
|
208
223
|
${announcementBar ? AnnouncementBarInlineJavaScript : ''}
|
|
209
224
|
`,
|
|
210
225
|
},
|