diff --git a/scripts/filters/comment/changyan.js b/scripts/filters/comment/changyan.js index 4b64d6a..b0ee8bf 100644 --- a/scripts/filters/comment/changyan.js +++ b/scripts/filters/comment/changyan.js @@ -10,7 +10,7 @@ hexo.extend.filter.register('theme_inject', injects => { const config = hexo.theme.config.changyan; if (!config.enable || !config.appid || !config.appkey) return; - injects.comment.raw('changyan', '
', {}, { cache: true }); + injects.comment.raw('changyan', '', {}, {}); injects.bodyEnd.file('changyan', path.join(hexo.theme_dir, 'layout/_third-party/comments/changyan.njk')); @@ -25,15 +25,9 @@ hexo.extend.filter.register('theme_inject', injects => { {% if post.comments %} {% endif %} `, {}, {}); diff --git a/source/js/third-party/comments/changyan.js b/source/js/third-party/comments/changyan.js index 7d5a859..18a1be4 100644 --- a/source/js/third-party/comments/changyan.js +++ b/source/js/third-party/comments/changyan.js @@ -1,24 +1,39 @@ /* global NexT, CONFIG */ document.addEventListener('page:loaded', () => { - if (CONFIG.page.isHome) { - NexT.utils.getScript( - `https://changyan.sohu.com/upload/plugins/plugins.list.count.js?clientId=${CONFIG.changyan.appid}`, - { attributes: { id: 'cy_cmt_num' } } - ); - } else if (CONFIG.page.comments) { + const { appid, appkey } = CONFIG.changyan; + const mainJs = 'https://cy-cdn.kuaizhan.com/upload/changyan.js'; + const countJs = `https://cy-cdn.kuaizhan.com/upload/plugins/plugins.list.count.js?clientId=${appid}`; + + // Get the number of comments + setTimeout(() => { + return NexT.utils.getScript(countJs, { + attributes: { + async: true, + id : 'cy_cmt_num' + } + }); + }, 0); + + // When scroll to comment section + if (CONFIG.page.comments && !CONFIG.page.isHome) { NexT.utils.loadComments('#SOHUCS') .then(() => { - delete window.changyan; - delete window.cyan; - return NexT.utils.getScript('https://changyan.sohu.com/upload/changyan.js'); + return NexT.utils.getScript(mainJs, { + attributes: { + async: true + } + }); }) .then(() => { window.changyan.api.config({ - appid: CONFIG.changyan.appid, - conf : CONFIG.changyan.appkey + appid, + conf: appkey }); + }) + .catch(error => { + // eslint-disable-next-line no-console + console.error('Failed to load Changyan', error); }); - NexT.utils.getScript('https://assets.changyan.sohu.com/upload/plugins/plugins.count.js'); } });