forked from tangly1024/NotionNext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ValineComponent.js
59 lines (52 loc) · 1.87 KB
/
ValineComponent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { siteConfig } from '@/lib/config'
import { loadExternalResource } from '@/lib/utils'
import { useEffect } from 'react'
const ValineComponent = ({ path }) => {
const loadValine = async () => {
try {
await loadExternalResource(siteConfig('COMMENT_VALINE_CDN'), 'js')
const Valine = window.Valine
// eslint-disable-next-line no-unused-vars
const valine = new Valine({
el: '#valine', // 容器元素
lang: siteConfig('LANG'), // 用于手动设定评论区语言,支持的语言列表 https://github.com/imaegoo/twikoo/blob/main/src/client/utils/i18n/index.js
appId: siteConfig('COMMENT_VALINE_APP_ID'),
appKey: siteConfig('COMMENT_VALINE_APP_KEY'),
avatar: '',
path,
recordIP: true,
placeholder: siteConfig('COMMENT_VALINE_PLACEHOLDER'),
serverURLs: siteConfig('COMMENT_VALINE_SERVER_URLS'),
visitor: true
})
} catch (error) {
console.error('twikoo 加载失败', error)
}
}
useEffect(() => {
loadValine()
}, [])
return <div id="valine"></div>
// const updateValine = url => {
// // 移除旧的评论区,否则会重复渲染。
// const wrapper = document.getElementById('v-wrapper')
// const comments = document.getElementById('v-comments')
// wrapper.removeChild(comments)
// const newComments = document.createElement('div')
// newComments.id = 'v-comments'
// newComments.name = new Date()
// wrapper.appendChild(newComments)
// initValine(url)
// }
// useEffect(() => {
// initValine()
// router.events.on('routeChangeComplete', updateValine)
// return () => {
// router.events.off('routeChangeComplete', updateValine)
// }
// }, [])
// return <div id='v-wrapper'>
// <div id='v-comments'></div>
// </div>
}
export default ValineComponent