fix: giscus comment

This commit is contained in:
KazooTTT
2024-11-23 22:03:59 +08:00
parent 9f392106bd
commit ebcc468e7e
4 changed files with 13 additions and 4 deletions

View File

@ -6,6 +6,15 @@ import Giscus from '@giscus/react'
const id = 'inject-comments' const id = 'inject-comments'
const GiscusComment = () => { const GiscusComment = () => {
const [theme, setTheme] = React.useState('preferred_color_scheme')
React.useEffect(() => {
const savedTheme = localStorage.getItem('theme')
if (savedTheme) {
setTheme(savedTheme)
}
}, [])
return ( return (
<div id={id} className='mt-8 w-full'> <div id={id} className='mt-8 w-full'>
<Giscus <Giscus
@ -19,7 +28,7 @@ const GiscusComment = () => {
reactionsEnabled='1' reactionsEnabled='1'
emitMetadata='0' emitMetadata='0'
inputPosition='bottom' inputPosition='bottom'
theme={localStorage.getItem('theme') ?? 'preferred_color_scheme'} theme={theme}
lang='zh-CN' lang='zh-CN'
loading='lazy' loading='lazy'
/> />

View File

@ -23,5 +23,5 @@ const { Content } = await entry.render()
<PostLayout post={entry}> <PostLayout post={entry}>
<Content /> <Content />
<GiscusComment client:only='react' client:load /> <GiscusComment client:load />
</PostLayout> </PostLayout>

View File

@ -211,5 +211,5 @@ const projects = [...directProjects, ...mdProjects].slice(0, MAX_PROJECTS)
</div> </div>
</Section> </Section>
</div> </div>
<GiscusComment client:only='react' client:load /> <GiscusComment client:load />
</PageLayout> </PageLayout>

View File

@ -408,5 +408,5 @@ const DEVICES = {
<CategorySection title='Hardware Devices' categories={Object.values(DEVICES)} /> <CategorySection title='Hardware Devices' categories={Object.values(DEVICES)} />
</div> </div>
</div> </div>
<GiscusComment client:only='react' client:load /> <GiscusComment client:load />
</PageLayout> </PageLayout>