File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1
1
import InitColorSchemeScript from '@mui/material/InitColorSchemeScript' ;
2
2
import { Html , Head , Main , NextScript } from 'next/document' ;
3
3
4
+ function InitMetaThemeColorScript ( ) : React . ReactElement {
5
+ return (
6
+ < script
7
+ dangerouslySetInnerHTML = { {
8
+ __html : `
9
+ (function() {
10
+ try {
11
+ const currentTheme = document.documentElement.getAttribute('data-theme');
12
+
13
+ const matchingMetaTag = document.querySelector(
14
+ \`meta[name="theme-color"][media*="\${currentTheme}"]\`
15
+ );
16
+ if (!matchingMetaTag) return;
17
+
18
+ const metaContentColor = matchingMetaTag.getAttribute('content');
19
+ if (!metaContentColor) return;
20
+
21
+ document.querySelectorAll('meta[name="theme-color"]').forEach((meta) => {
22
+ meta.setAttribute('content', metaContentColor);
23
+ });
24
+ } catch (_) {}
25
+ })();
26
+ ` ,
27
+ } }
28
+ />
29
+ ) ;
30
+ }
31
+
4
32
export default function Document ( ) {
5
33
return (
6
34
< Html lang = "fi" >
@@ -33,6 +61,7 @@ export default function Document() {
33
61
</ Head >
34
62
< body >
35
63
< InitColorSchemeScript attribute = "data-theme" />
64
+ < InitMetaThemeColorScript />
36
65
< Main />
37
66
< NextScript />
38
67
</ body >
You can’t perform that action at this time.
0 commit comments