I recently added disqus comments to one of my themes (and my site, which uses the theme). I didn’t like how the comments were displayed by default. So I hid them, then added a button to show them on click. A short GIF below.
One thing to note: the disqus iframes when initially loaded had a huge height, like 1,000px plus, and it made my page look weird with all the empty space. So I set a max-height on the comment div and iframes. Not the most elegant but it does the job.
disqus.html partial
<div id="disqus-container">
{{ $ctx := . }}
{{ with .Site.DisqusShortname }}
<button id="disqus-button" onclick="showComments()">Show comments</button>
<div id="disqus-comments">
{{ if eq . "yourdiscussshortname" }}
<p>Disqus comments are disabled.</p>
{{ else }}
{{ template "_internal/disqus.html" $ctx }}
{{ end }}
</div>
{{ end }}
</div>
the disqus iframe s when initially loaded had a huge height, like 1,000px plus
I hope it’s ok if I plug a Disqus alternative I’ve built then? 1) It resizes its iframe properly, so the iframe is not larger than needed. (I wonder why Disqus didn’t do that properly in you case? Is it something with this particular Hugo blog, or is it always like that, with Disqus? )
And 2) it looks quite different from Disqus; maybe you like it better? (If not, would be interesting to hear what could be changed.) Scroll down here for screenshots: https://www.talkyard.io/blog-comments
(B.t.w. interested to see how you hide the comments, … for different reasons — namely to not load the comments, until one has scrolled down so they would be visible. That’d save some bandwidth, in the cases when people don’t scroll down to the comments.)
Thanks for sharing. I’ll look into this when I have time.
Not sure. Something I did notice, once I made the change to only load the disqus JS on click, the iframe sizing problem went away. My fuzzy guess is it was all the various calls disqus was making while the rest of the page was being rendered.
By default disqus depends on lazyloading but when built with Hugo’s template things become annoying as Hugo(AFAIK) compile it along with other content and disqus lazyload waste away
Thank you, let me try again, for some reason it wouldn’t disapper. But now it does, added a button class to theme it. But turns out it was the one causing issues
The “load Disqus JS only if the show comment buttons is pressed” should be supported by default by Hugo in its mobile version (kind of how Youtube’s website works).
Anyone surfing the net (1990! yeah!) with 4G need to be able to have the choice available.