在docsify中使用gitalk
作者:互联网
在index.html中添加(https://docsify.js.org/#/zh-cn/plugins?id=gitalk)
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk/dist/gitalk.css">
<script src="//cdn.jsdelivr.net/npm/docsify/lib/plugins/gitalk.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/gitalk/dist/gitalk.min.js"></script>
<script>
const gitalk = new Gitalk({
clientID: 'Github Application Client ID',
clientSecret: 'Github Application Client Secret',
repo: 'Github repo',
owner: 'Github repo owner',
admin: ['Github repo collaborators, only these guys can initialize github issues'],
// facebook-like distraction free mode
distractionFreeMode: false
})
</script>
创建github的OAuth Apps
创建GitHub Apps使用其clientID,secret存在问题的
上述URL无需域名,直接ip地址也可以
然后Generate a client
即可获取clientID和clientSecret
repo直接写repo name,不是full path
实际用例
<link rel="stylesheet" href="//unpkg.com/gitalk/dist/gitalk.css">
<script src="//unpkg.com/gitalk/dist/gitalk.min.js"></script>
<script src="//unpkg.com/docsify/lib/plugins/gitalk.min.js"></script>
<script>
var gitalk = new Gitalk({
clientID: '2eb19afceda708b27e64',
clientSecret: '36aedb5a30321626a8631689fee5fafd5929f612',
repo: 'gitalk-comment',
owner: 'yulilong',
admin: ['yulilong'],
title: location.hash.match(/#(.*?)([?]|$)/)[1],
id: location.hash.match(/#(.*?)([?]|$)/)[1],
})
// 监听URL中hash的变化,如果发现换了一个MD文件,那么刷新页面,解决整个网站使用一个gitalk评论issues的问题。
window.onhashchange = function(event){
if(event.newURL.split('?')[0] !== event.oldURL .split('?')[0]) {
location.reload()
}
}
// 由于docsify/lib/plugins/gitalk.min.js文件中已经有下面代码了,所以不需要在写一次了
// gitalk.render('gitalk-container')
</script>
标签:gitalk,Github,clientID,repo,location,使用,docsify,event 来源: https://blog.csdn.net/m0_60725291/article/details/120993395