diff --git a/src/theme/BlogPostItem/index.js b/src/theme/BlogPostItem/index.js index 64c787d966..367abdd1be 100644 --- a/src/theme/BlogPostItem/index.js +++ b/src/theme/BlogPostItem/index.js @@ -1,32 +1,46 @@ import { useBlogPost } from '@docusaurus/theme-common/internal'; import BlogPostItem from '@theme-original/BlogPostItem'; -import React from 'react'; +import React, { useEffect, useState } from 'react'; +import BrowserOnly from '@docusaurus/BrowserOnly'; +import useIsBrowser from '@docusaurus/useIsBrowser'; export default function BlogPostItemWrapper(props) { const { metadata, isBlogPostPage } = useBlogPost(); + const isBrowser = useIsBrowser(); + const [theme, setTheme] = useState('light'); + + useEffect(() => { + if (isBrowser) { + setTheme(document.documentElement.getAttribute('data-theme') !== 'dark' ? 'light' : 'dark'); + } + }, [isBrowser]); return ( <> {props.children} {isBlogPostPage && ( -
-