File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 214214 // 添加Twikoo评论系统插件
215215 plugins : [
216216 function ( hook , vm ) {
217- // 动态插入 div#tcomment 的 dom
218- hook . mounted ( function ( ) {
219- var a = Docsify . dom ;
220- var n = a . create ( "div" ) ;
221- n . id = "tcomment" ;
222- a . appendTo ( a . find ( ".content" ) , n ) ;
223- } )
224- // 调用 twikoo 评论,正则 path,刷新当前评论
217+ // 在每次页面渲染完成后初始化评论
225218 hook . doneEach ( function ( ) {
219+ // 如果容器不存在则创建
220+ var commentContainer = document . getElementById ( 'tcomment' ) ;
221+ if ( ! commentContainer ) {
222+ var container = document . createElement ( 'div' ) ;
223+ container . id = 'tcomment' ;
224+ var content = document . querySelector ( '.content' ) ;
225+ if ( content ) {
226+ content . appendChild ( container ) ;
227+ }
228+ }
229+
230+ // 初始化 Twikoo
226231 twikoo . init ( {
227- envId : 'https://twikoo-eo-w2aubykn.edgeone.cool' , // 使用EdgeOne
232+ envId : 'https://twikoo-eo-w2aubykn.edgeone.cool' ,
228233 el : '#tcomment' ,
229- // path: location.pathname+location.hash.replace(/\?.*/,''),
230234 onCommentLoaded : function ( ) {
231235 console . log ( '评论加载完成' ) ;
232236 }
233237 } ) . then ( function ( ) {
234238 console . log ( 'Twikoo 加载完成' ) ;
235- setTimeout ( function ( ) {
236- // 通过点击刷新按钮,获取当前页评论
237- let tk_icon = document . getElementsByClassName ( "tk-icon" ) [ 0 ] ;
238- tk_icon ? tk_icon . click ( ) : undefined ;
239- } , 700 )
239+ } ) . catch ( function ( err ) {
240+ console . error ( 'Twikoo 加载失败:' , err ) ;
240241 } ) ;
241242 } )
242243 }
You can’t perform that action at this time.
0 commit comments