probberechts / hexo-theme-cactus

:cactus: A responsive, clean and simple theme for Hexo.
https://probberechts.github.io/hexo-theme-cactus/
MIT License
3.13k stars 776 forks source link

Disable comments on pages/posts #257

Open kmcyjm opened 3 years ago

kmcyjm commented 3 years ago

Hi,

Today I found an issue where after integrating with Disqus, adding comments: false to the front matter of my "About me" page doesn't let the comment box go away.

After digging for awhile, it is found that adding the following block to the footer.ejs solves the problem,

<% if (page.comments && config.disqus_shortname){ %>
<div id="disqus_thread"></div>
<script>
    /**
    *  RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
    *  LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables    */
    /*
    var disqus_config = function () {
    this.page.url = PAGE_URL;  // Replace PAGE_URL with your page's canonical URL variable
    this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
    };
    */
    (function() { // DON'T EDIT BELOW THIS LINE
    var d = document, s = d.createElement('script');
    s.src = 'https://<disqus-short-name.disqus.com/embed.js';
    s.setAttribute('data-timestamp', +new Date());
    (d.head || d.body).appendChild(s);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<% } %>

This is inspired by the post here https://github.com/hexojs/hexo-theme-landscape/issues/178.

I am not a JavaScript developer, hence not sure if this is the best option to solve this issue.

Please help evaluate and make updates as you see fit.

Thanks!

probberechts commented 3 years ago

This theme only adds a comment block to blog posts, not to pages. Hence, I do not understand your problem. Is your "about me" page a blog post?

If you create an "about me" page with:

$ hexo new page about

It should not contain a Disqus block.

probberechts commented 3 years ago

Apart from that, I think it is a good idea to add an option to disable comments on specific blog posts.