From 156920dea5ce3f3048c84e38b519785b4a653e83 Mon Sep 17 00:00:00 2001 From: XPoet Date: Mon, 11 Jan 2021 00:21:26 +0800 Subject: [PATCH] fix: fixed Gitalk loading error caused by clicking too fast --- layout/_partial/comment/gitalk.ejs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/layout/_partial/comment/gitalk.ejs b/layout/_partial/comment/gitalk.ejs index 6ca6b19..607f5d6 100644 --- a/layout/_partial/comment/gitalk.ejs +++ b/layout/_partial/comment/gitalk.ejs @@ -17,15 +17,21 @@ if (__gitalk__pathnameLength > __gitalk__pathnameMaxLength) { __gitalk__pathname = __gitalk__pathname.substring(0, __gitalk__pathnameMaxLength - 3) + '...'; } - Gitalk && new Gitalk({ - clientID: '<%= theme.comment.gitalk.client_id %>', - clientSecret: '<%= theme.comment.gitalk.client_secret %>', - repo: '<%= theme.comment.gitalk.repository %>', - owner: '<%= theme.comment.gitalk.github_id %>', - admin: ['<%= theme.comment.gitalk.github_id %>'], - id: __gitalk__pathname, - language: '<%= config.language %>' - }).render('gitalk-container'); + + try { + Gitalk && new Gitalk({ + clientID: '<%= theme.comment.gitalk.client_id %>', + clientSecret: '<%= theme.comment.gitalk.client_secret %>', + repo: '<%= theme.comment.gitalk.repository %>', + owner: '<%= theme.comment.gitalk.github_id %>', + admin: ['<%= theme.comment.gitalk.github_id %>'], + id: __gitalk__pathname, + language: '<%= config.language %>' + }).render('gitalk-container'); + + } catch (e) { + window.Gitalk = null; + } } if ('<%= theme.pjax.enable %>') {