Skip to content

Instantly share code, notes, and snippets.

@iaminamcom
Last active February 25, 2020 16:07
Show Gist options
  • Save iaminamcom/48b852ddb8f85f8410738eea4958d66f to your computer and use it in GitHub Desktop.
Save iaminamcom/48b852ddb8f85f8410738eea4958d66f to your computer and use it in GitHub Desktop.
This is a ready to use partial for hugo to add `show comments` like functionality to avold extra load time by hindering disqus request until user really need it.
<div class="disqus-comments">
<div id="showcom">
<span>Say something or read other's ideas</span>
<button id="show-comments" type="button">Show <span class="disqus-comment-count" data-disqus-identifier="{{ .File.UniqueID }}">First article</span></button>
</div>
<div id="disqus_thread"></div>
</div>
<script id="dsq-count-scr" src="//{{.Site.DisqusShortname}}.disqus.com/count.js" async></script>
<script type="text/javascript">
var disqus_config = function () {
this.page.url = '{{ trim .Permalink "/" }}';
this.page.title = '{{ .Title }}';
this.page.identifier = '{{ .File.UniqueID }}';
};
document.getElementById('show-comments').onclick = function () {
var disqus = document.createElement('script');
disqus.type = 'text/javascript';
disqus.async = true;
disqus.src = '//' + '{{.Site.DisqusShortname}}' + '.disqus.com/embed.js';
document.body.appendChild(disqus);
var showcom = document.getElementById('showcom');
this.innerHTML += '...';
setTimeout(function () {
showcom.parentNode.removeChild(showcom);
},3000);
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment