@@ -32,9 +32,16 @@ export default ({
3232 }
3333 // 显示广告模块
3434 pageB . style . display = 'flex'
35+
36+ integrateGitalk ( router )
3537 } , 0 )
3638 } )
3739 }
40+ try {
41+ document && integrateGitalk ( router )
42+ } catch ( e ) {
43+ console . error ( e . message )
44+ }
3845}
3946
4047function ABDetected ( ) {
@@ -53,3 +60,54 @@ function docReady(t) {
5360 ? setTimeout ( t , 1 )
5461 : document . addEventListener ( 'DOMContentLoaded' , t )
5562}
63+
64+ // 集成 Gitalk 评论插件
65+ function integrateGitalk ( router ) {
66+ const linkGitalk = document . createElement ( 'link' )
67+ linkGitalk . href = 'https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css'
68+ linkGitalk . rel = 'stylesheet'
69+ document . body . appendChild ( linkGitalk )
70+ const scriptGitalk = document . createElement ( 'script' )
71+ scriptGitalk . src = 'https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js'
72+ document . body . appendChild ( scriptGitalk )
73+
74+ router . afterEach ( ( to ) => {
75+ if ( scriptGitalk . onload ) {
76+ loadGitalk ( to )
77+ } else {
78+ scriptGitalk . onload = ( ) => {
79+ loadGitalk ( to )
80+ }
81+ }
82+ } )
83+
84+ function loadGitalk ( to ) {
85+ let commentsContainer = document . getElementById ( 'gitalk-container' )
86+ if ( ! commentsContainer ) {
87+ commentsContainer = document . createElement ( 'div' )
88+ commentsContainer . id = 'gitalk-container'
89+ commentsContainer . classList . add ( 'content' )
90+ }
91+ const $page = document . querySelector ( '.page' )
92+ if ( $page ) {
93+ $page . appendChild ( commentsContainer )
94+ if ( typeof Gitalk !== 'undefined' && Gitalk instanceof Function ) {
95+ renderGitalk ( to . fullPath )
96+ }
97+ }
98+ }
99+ function renderGitalk ( fullPath ) {
100+ console . info ( fullPath )
101+ const gitalk = new Gitalk ( {
102+ clientID : '7dd8c87a20cff437d2ed' ,
103+ clientSecret : '4e28d81a9a0280796b2b45ce2944424c6f2c1531' , // come from github development
104+ repo : 'blog' ,
105+ owner : 'dunwu' ,
106+ admin : [ 'dunwu' ] ,
107+ id : 'comment' ,
108+ distractionFreeMode : false ,
109+ language : 'zh-CN' ,
110+ } )
111+ gitalk . render ( 'gitalk-container' )
112+ }
113+ }
0 commit comments