mirror of
https://github.com/hazemKrimi/personal-website.git
synced 2026-05-01 18:00:26 +00:00
Fix color theme
This commit is contained in:
@@ -43,6 +43,36 @@ class Doc extends Document {
|
||||
`
|
||||
}}
|
||||
/>
|
||||
<script
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
function getInitialColorMode() {
|
||||
const persistedColorPreference = window.localStorage.getItem('theme');
|
||||
const hasPersistedPreference = typeof persistedColorPreference === 'string';
|
||||
|
||||
if (hasPersistedPreference) {
|
||||
return persistedColorPreference;
|
||||
}
|
||||
|
||||
const mql = window.matchMedia('(prefers-color-scheme: dark)');
|
||||
const hasMediaQueryPreference = typeof mql.matches === 'boolean';
|
||||
|
||||
if (hasMediaQueryPreference) {
|
||||
return mql.matches ? 'dark' : 'light';
|
||||
}
|
||||
|
||||
return 'light';
|
||||
}
|
||||
|
||||
(() => {
|
||||
const colorMode = getInitialColorMode();
|
||||
const root = document.documentElement;
|
||||
|
||||
root.style.setProperty('--theme', colorMode);
|
||||
})();
|
||||
`
|
||||
}}
|
||||
/>
|
||||
</Head>
|
||||
<body>
|
||||
<Main />
|
||||
|
||||
Reference in New Issue
Block a user