refactor: refactor code a bit
make a hook to abstarct logic from page changes to .prettierrc changes to a couple of imports/exports bunch of screen reader tweaks
This commit is contained in:
@@ -3,15 +3,17 @@ import Document, { Html, Head, Main, NextScript } from 'next/document';
|
||||
// for preventing Flash of inAccurate coloR Theme(fart)
|
||||
// chris coyier came up with that acronym(https://css-tricks.com/flash-of-inaccurate-color-theme-fart/)
|
||||
const setInitialTheme = `
|
||||
document.documentElement.dataset.js = true;
|
||||
document.documentElement.dataset.theme = (() => {
|
||||
(() => {
|
||||
document.documentElement.dataset.js = true;
|
||||
let theme = 'light';
|
||||
let themeColor = '#ffe5ef';
|
||||
const userPrefersTheme = window.localStorage.getItem('theme') || null;
|
||||
const browserPrefersDarkTheme = window.matchMedia(
|
||||
'(prefers-color-scheme: dark)'
|
||||
).matches;
|
||||
if (userPrefersTheme) return userPrefersTheme;
|
||||
else if (browserPrefersDarkTheme) return 'dark';
|
||||
else return 'light';
|
||||
const browserPrefersDarkTheme = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
if (userPrefersTheme) theme = userPrefersTheme;
|
||||
else if (browserPrefersDarkTheme) theme = 'dark';
|
||||
if(theme === 'dark') themeColor = '#141c2e';
|
||||
document.documentElement.dataset.theme = theme;
|
||||
document.querySelector('meta[name="theme-color"]').setAttribute('content', themeColor);
|
||||
})();
|
||||
`;
|
||||
|
||||
|
Reference in New Issue
Block a user