mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-20 19:02:33 +00:00
Optimize changyan comment (#415)
This commit is contained in:
parent
3dca98b7cf
commit
0ed5fff721
@ -10,7 +10,7 @@ hexo.extend.filter.register('theme_inject', injects => {
|
|||||||
const config = hexo.theme.config.changyan;
|
const config = hexo.theme.config.changyan;
|
||||||
if (!config.enable || !config.appid || !config.appkey) return;
|
if (!config.enable || !config.appid || !config.appkey) return;
|
||||||
|
|
||||||
injects.comment.raw('changyan', '<div class="comments" id="SOHUCS"></div>', {}, { cache: true });
|
injects.comment.raw('changyan', '<div class="comments" id="SOHUCS" sid="{{ gitalk_md5(page.path) }}"></div>', {}, {});
|
||||||
|
|
||||||
injects.bodyEnd.file('changyan', path.join(hexo.theme_dir, 'layout/_third-party/comments/changyan.njk'));
|
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 %}
|
{% if post.comments %}
|
||||||
<span class="post-meta-item">
|
<span class="post-meta-item">
|
||||||
${iconText('far fa-comment', 'changyan')}
|
${iconText('far fa-comment', 'changyan')}
|
||||||
{% if is_post() %}
|
<a title="{{ post.title }}" href="{{ url_for(post.path) }}#SOHUCS" itemprop="discussionUrl">
|
||||||
<a title="changyan" href="{{ url_for(post.path) }}#SOHUCS" itemprop="discussionUrl">
|
<span id="sourceId::{{ gitalk_md5(post.path) }}" class="cy_cmt_count" itemprop="commentCount"></span>
|
||||||
<span id="changyan_count_unit" class="post-comments-count hc-comment-count" data-xid="{{ post.path }}" itemprop="commentCount"></span>
|
</a>
|
||||||
</a>
|
|
||||||
{% else %}
|
|
||||||
<a title="changyan" href="{{ url_for(post.path) }}#SOHUCS" itemprop="discussionUrl">
|
|
||||||
<span id="url::{{ post.permalink }}" class="cy_cmt_count" data-xid="{{ post.path }}" itemprop="commentCount"></span>
|
|
||||||
</a>
|
|
||||||
{% endif %}
|
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
`, {}, {});
|
`, {}, {});
|
||||||
|
|||||||
39
source/js/third-party/comments/changyan.js
vendored
39
source/js/third-party/comments/changyan.js
vendored
@ -1,24 +1,39 @@
|
|||||||
/* global NexT, CONFIG */
|
/* global NexT, CONFIG */
|
||||||
|
|
||||||
document.addEventListener('page:loaded', () => {
|
document.addEventListener('page:loaded', () => {
|
||||||
if (CONFIG.page.isHome) {
|
const { appid, appkey } = CONFIG.changyan;
|
||||||
NexT.utils.getScript(
|
const mainJs = 'https://cy-cdn.kuaizhan.com/upload/changyan.js';
|
||||||
`https://changyan.sohu.com/upload/plugins/plugins.list.count.js?clientId=${CONFIG.changyan.appid}`,
|
const countJs = `https://cy-cdn.kuaizhan.com/upload/plugins/plugins.list.count.js?clientId=${appid}`;
|
||||||
{ attributes: { id: 'cy_cmt_num' } }
|
|
||||||
);
|
// Get the number of comments
|
||||||
} else if (CONFIG.page.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')
|
NexT.utils.loadComments('#SOHUCS')
|
||||||
.then(() => {
|
.then(() => {
|
||||||
delete window.changyan;
|
return NexT.utils.getScript(mainJs, {
|
||||||
delete window.cyan;
|
attributes: {
|
||||||
return NexT.utils.getScript('https://changyan.sohu.com/upload/changyan.js');
|
async: true
|
||||||
|
}
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
window.changyan.api.config({
|
window.changyan.api.config({
|
||||||
appid: CONFIG.changyan.appid,
|
appid,
|
||||||
conf : CONFIG.changyan.appkey
|
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');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user