mirror of
https://github.com/d0zingcat/nextjs-notion-starter-kit.git
synced 2026-05-13 15:09:47 +00:00
71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
import { IconContext } from '@react-icons/all-files'
|
|
import Document, { Head, Html, Main, NextScript } from 'next/document'
|
|
|
|
export default class MyDocument extends Document {
|
|
render() {
|
|
return (
|
|
<IconContext.Provider value={{ style: { verticalAlign: 'middle' } }}>
|
|
<Html lang='en'>
|
|
<Head>
|
|
<link rel='shortcut icon' href='/favicon.ico' />
|
|
<link
|
|
rel='icon'
|
|
type='image/png'
|
|
sizes='32x32'
|
|
href='favicon.png'
|
|
/>
|
|
|
|
<link rel='manifest' href='/manifest.json' />
|
|
</Head>
|
|
|
|
<body>
|
|
<script
|
|
dangerouslySetInnerHTML={{
|
|
__html: `
|
|
/** Inlined version of noflash.js from use-dark-mode */
|
|
;(function () {
|
|
var storageKey = 'darkMode'
|
|
var classNameDark = 'dark-mode'
|
|
var classNameLight = 'light-mode'
|
|
function setClassOnDocumentBody(darkMode) {
|
|
document.body.classList.add(darkMode ? classNameDark : classNameLight)
|
|
document.body.classList.remove(darkMode ? classNameLight : classNameDark)
|
|
}
|
|
var preferDarkQuery = '(prefers-color-scheme: dark)'
|
|
var mql = window.matchMedia(preferDarkQuery)
|
|
var supportsColorSchemeQuery = mql.media === preferDarkQuery
|
|
var localStorageTheme = null
|
|
try {
|
|
localStorageTheme = localStorage.getItem(storageKey)
|
|
} catch (err) {}
|
|
var localStorageExists = localStorageTheme !== null
|
|
if (localStorageExists) {
|
|
localStorageTheme = JSON.parse(localStorageTheme)
|
|
}
|
|
// Determine the source of truth
|
|
if (localStorageExists) {
|
|
// source of truth from localStorage
|
|
setClassOnDocumentBody(localStorageTheme)
|
|
} else if (supportsColorSchemeQuery) {
|
|
// source of truth from system
|
|
setClassOnDocumentBody(mql.matches)
|
|
localStorage.setItem(storageKey, mql.matches)
|
|
} else {
|
|
// source of truth from document.body
|
|
var isDarkMode = document.body.classList.contains(classNameDark)
|
|
localStorage.setItem(storageKey, JSON.stringify(isDarkMode))
|
|
}
|
|
})();
|
|
`
|
|
}}
|
|
/>
|
|
<Main />
|
|
|
|
<NextScript />
|
|
</body>
|
|
</Html>
|
|
</IconContext.Provider>
|
|
)
|
|
}
|
|
}
|