Simplify the .comments element

This commit is contained in:
Mimi 2020-12-27 14:44:19 +08:00
parent a82212af16
commit d6f7c51f6c
10 changed files with 14 additions and 34 deletions

View File

@ -2,7 +2,7 @@
<link rel="stylesheet" href="{{ theme.vendors.gitalk_css }}">
<script>
NexT.utils.loadComments('#gitalk-container', () => {
NexT.utils.loadComments('.gitalk-container', () => {
NexT.utils.getScript('{{ theme.vendors.gitalk_js }}', () => {
var gitalk = new Gitalk({
clientID : '{{ theme.gitalk.client_id }}',
@ -18,7 +18,7 @@ NexT.utils.loadComments('#gitalk-container', () => {
{%- endif %}
distractionFreeMode: {{ theme.gitalk.distraction_free_mode }}
});
gitalk.render('gitalk-container');
gitalk.render(document.querySelector('.gitalk-container'));
}, window.Gitalk);
});
</script>

View File

@ -1,6 +1,6 @@
{%- if page.comments %}
<script>
NexT.utils.loadComments('#utterances-container', () => {
NexT.utils.loadComments('.utterances-container', () => {
const script = document.createElement('script');
script.src = 'https://utteranc.es/client.js';
script.setAttribute('repo', {{ theme.utterances.repo | safedump }});
@ -8,7 +8,7 @@ NexT.utils.loadComments('#utterances-container', () => {
script.setAttribute('theme', {{ theme.utterances.theme | safedump }});
script.crossOrigin = 'anonymous';
script.async = true;
document.querySelector('#utterances-container').appendChild(script);
document.querySelector('.utterances-container').appendChild(script);
});
</script>
{%- endif %}

View File

@ -10,11 +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', `
<div class="comments">
<div id="SOHUCS"></div>
</div>
`, {}, {cache: true});
injects.comment.raw('changyan', '<div class="comments" id="SOHUCS"></div>', {}, {cache: true});
injects.bodyEnd.file('changyan', path.join(hexo.theme_dir, 'layout/_third-party/comments/changyan.njk'));

View File

@ -11,10 +11,8 @@ hexo.extend.filter.register('theme_inject', injects => {
if (!config.enable || !config.shortname) return;
injects.comment.raw('disqus', `
<div class="comments">
<div id="disqus_thread">
<noscript>Please enable JavaScript to view the comments powered by Disqus.</noscript>
</div>
<div class="comments" id="disqus_thread">
<noscript>Please enable JavaScript to view the comments powered by Disqus.</noscript>
</div>
`, {}, {cache: true});

View File

@ -10,10 +10,8 @@ hexo.extend.filter.register('theme_inject', injects => {
if (!config.enable || !config.shortname || !config.apikey) return;
injects.comment.raw('disqusjs', `
<div class="comments">
<div id="disqus_thread">
<noscript>Please enable JavaScript to view the comments powered by Disqus.</noscript>
</div>
<div class="comments" id="disqus_thread">
<noscript>Please enable JavaScript to view the comments powered by Disqus.</noscript>
</div>
`, {}, {cache: true});

View File

@ -9,7 +9,7 @@ hexo.extend.filter.register('theme_inject', injects => {
const theme = hexo.theme.config;
if (!theme.gitalk.enable) return;
injects.comment.raw('gitalk', '<div class="comments" id="gitalk-container"></div>', {}, {cache: true});
injects.comment.raw('gitalk', '<div class="comments gitalk-container"></div>', {}, {cache: true});
injects.bodyEnd.file('gitalk', path.join(hexo.theme_dir, 'layout/_third-party/comments/gitalk.njk'));

View File

@ -9,11 +9,7 @@ hexo.extend.filter.register('theme_inject', injects => {
const theme = hexo.theme.config;
if (!theme.isso) return;
injects.comment.raw('isso', `
<div class="comments">
<div id="isso-thread"></div>
</div>
`, {}, { cache: true });
injects.comment.raw('isso', '<div class="comments" id="isso-thread"></div>', {}, { cache: true });
injects.bodyEnd.file('isso', path.join(hexo.theme_dir, 'layout/_third-party/comments/isso.njk'));

View File

@ -9,11 +9,7 @@ hexo.extend.filter.register('theme_inject', injects => {
const theme = hexo.theme.config;
if (!theme.livere_uid) return;
injects.comment.raw('livere', `
<div class="comments">
<div id="lv-container" data-id="city" data-uid="{{ theme.livere_uid }}"></div>
</div>
`, {}, {cache: true});
injects.comment.raw('livere', '<div class="comments" id="lv-container" data-id="city" data-uid="{{ theme.livere_uid }}"></div>', {}, {cache: true});
injects.bodyEnd.file('livere', path.join(hexo.theme_dir, 'layout/_third-party/comments/livere.njk'));

View File

@ -14,11 +14,7 @@ hexo.extend.filter.register('theme_inject', injects => {
return;
}
injects.comment.raw('utterances', `
<div class="comments">
<div id="utterances-container"></div>
</div>
`, {}, { cache: true });
injects.comment.raw('utterances', '<div class="comments utterances-container"></div>', {}, { cache: true });
injects.bodyEnd.file('utterances', path.join(hexo.theme_dir, 'layout/_third-party/comments/utterances.njk'));

View File

@ -67,7 +67,7 @@ document.addEventListener('DOMContentLoaded', () => {
return result;
},
empty: data => {
return `<div id="algolia-hits-empty">
return `<div class="algolia-hits-empty">
${CONFIG.i18n.empty.replace(/\$\{query}/, data.query)}
</div>`;
}