* show cms blog posts in www * remove contentlayer from www * outputFileTracingExcludes * update remotePatterns * fetch cms posts server-side with revalidation * add cms env vars to turbo.json * add www env vars to turbo.json * include cms posts in www sitemap * add migration to remove image from cms post * update cms meta image mapping in www
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect } from 'react'
|
|
import { useTheme } from 'next-themes'
|
|
import { useRouter } from 'next/compat/router'
|
|
import useDarkLaunchWeeks from '../hooks/useDarkLaunchWeeks'
|
|
|
|
export function useForceDeepDark() {
|
|
const router = useRouter()
|
|
const { resolvedTheme, theme } = useTheme()
|
|
|
|
const isDarkTheme = resolvedTheme?.includes('dark')
|
|
const forceDarkMode = useDarkLaunchWeeks()
|
|
|
|
useEffect(() => {
|
|
const handleDocumentLoad = () => {
|
|
// Update the HTML element attributes
|
|
const theme = forceDarkMode || isDarkTheme ? 'dark' : 'light'
|
|
|
|
document.documentElement.setAttribute('data-theme', theme)
|
|
document.documentElement.style.colorScheme = theme
|
|
|
|
// wait before setting the theme
|
|
setTimeout(() => {
|
|
document.documentElement.setAttribute('data-theme', theme)
|
|
document.documentElement.style.colorScheme = theme
|
|
}, 200)
|
|
|
|
// Clean up the event listener
|
|
window.removeEventListener('load', handleDocumentLoad)
|
|
}
|
|
|
|
// Check if document is already loaded
|
|
if (document.readyState === 'complete') {
|
|
handleDocumentLoad()
|
|
} else {
|
|
// Add a global load event listener
|
|
window.addEventListener('load', handleDocumentLoad)
|
|
}
|
|
|
|
// Clean up the event listener on component unmount
|
|
return () => {
|
|
window.removeEventListener('load', handleDocumentLoad)
|
|
}
|
|
}, [resolvedTheme, theme, isDarkTheme, router])
|
|
}
|