mirror of
https://github.com/fergalmoran/supanextail.git
synced 2025-12-22 09:17:54 +00:00
36 lines
931 B
JavaScript
36 lines
931 B
JavaScript
import Document, { Head, Html, Main, NextScript } from "next/document";
|
|
|
|
class MyDocument extends Document {
|
|
static async getInitialProps(ctx) {
|
|
const initialProps = await Document.getInitialProps(ctx);
|
|
return { ...initialProps };
|
|
}
|
|
|
|
render() {
|
|
// This will set the initial theme, saved in localstorage
|
|
const setInitialTheme = `
|
|
function getUserPreference() {
|
|
if(window.localStorage.getItem('theme')) {
|
|
return window.localStorage.getItem('theme')
|
|
}
|
|
return window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
? 'dark'
|
|
: 'light'
|
|
}
|
|
document.body.dataset.theme = getUserPreference();
|
|
`;
|
|
return (
|
|
<Html>
|
|
<Head />
|
|
<body>
|
|
<script dangerouslySetInnerHTML={{ __html: setInitialTheme }} />
|
|
<Main />
|
|
<NextScript />
|
|
</body>
|
|
</Html>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default MyDocument;
|