mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 15:09:22 +00:00
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
import BLOG from '@/blog.config'
|
|
import { useEffect } from 'react'
|
|
|
|
/**
|
|
* 评论插件
|
|
* @param issueTerm
|
|
* @param layout
|
|
* @returns {JSX.Element}
|
|
* @constructor
|
|
*/
|
|
const Utterances = ({ issueTerm, layout }) => {
|
|
useEffect(() => {
|
|
const theme =
|
|
BLOG.appearance === 'auto'
|
|
? 'preferred-color-scheme'
|
|
: BLOG.appearance === 'light'
|
|
? 'github-light'
|
|
: 'github-dark'
|
|
const script = document.createElement('script')
|
|
const anchor = document.getElementById('comments')
|
|
script.setAttribute('src', 'https://utteranc.es/client.js')
|
|
script.setAttribute('crossorigin', 'anonymous')
|
|
script.setAttribute('async', true)
|
|
script.setAttribute('repo', BLOG.comment.utterancesConfig.repo)
|
|
script.setAttribute('issue-term', issueTerm)
|
|
script.setAttribute('theme', theme)
|
|
anchor.appendChild(script)
|
|
return () => {
|
|
anchor.innerHTML = ''
|
|
}
|
|
})
|
|
return (
|
|
<>
|
|
<div
|
|
id="comments"
|
|
className={layout && layout === 'fullWidth' ? '' : 'md:-ml-16'}
|
|
>
|
|
<div className="utterances-frame"></div>
|
|
</div>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default Utterances
|