aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages/_document.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-10-27 18:07:45 +0200
committerArmand Philippot <git@armandphilippot.com>2023-11-11 18:15:27 +0100
commit05f1dfc6896d3affa7c494a1b955f230d836a4b7 (patch)
tree3089d5c3145f241293b88b9a1bfe4bb85e8ca9e0 /src/pages/_document.tsx
parent757201fdc5c04a3f15504f74bf8ab85bb6018c2b (diff)
feat: replace next-themes with a custom ThemeProvider
To be honest, next-themes was working fine. However since I use a theme provider for Prism code blocks, some code is duplicated between this app and the library. So I prefer to use a custom Provider without the options I don't need.
Diffstat (limited to 'src/pages/_document.tsx')
-rw-r--r--src/pages/_document.tsx9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/pages/_document.tsx b/src/pages/_document.tsx
index 317d3af..7e3b5e6 100644
--- a/src/pages/_document.tsx
+++ b/src/pages/_document.tsx
@@ -16,6 +16,15 @@ export default function Document() {
// eslint-disable-next-line react/jsx-no-literals
strategy="beforeInteractive"
/>
+ <Script
+ dangerouslySetInnerHTML={{
+ __html: `!function(){const e=localStorage.getItem("${STORAGE_KEY.THEME}"),t="string"==typeof e?JSON.parse(e):void 0,o=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",c=e&&["dark","light"].includes(t)?t:o;document.documentElement.setAttribute("data-${STORAGE_KEY.THEME}",c),document.documentElement.style.colorScheme=o}();`,
+ }}
+ // eslint-disable-next-line react/jsx-no-literals
+ id="theme-hydration"
+ // eslint-disable-next-line react/jsx-no-literals
+ strategy="beforeInteractive"
+ />
</Head>
<body>
<Main />