Only load disqus comments on button click

This commit is contained in:
Zachary Betz 2019-03-07 14:13:56 -06:00
parent 4e14faf824
commit c2a934f566
4 changed files with 33 additions and 12 deletions

View File

@ -0,0 +1,6 @@
// Remove button
var disqusButton = document.getElementById('disqus-button');
disqusButton.remove();
// Un-hide comments
var disqusComments = document.getElementById('disqus-comments');
disqusComments.style.display = 'block';

View File

@ -0,0 +1,10 @@
// Config
var disqus_config = function () {
};
// Build and append comments
var d = document;
var s = d.createElement('script');
s.async = true;
s.src = '//' + "{{ . }}" + '.disqus.com/embed.js';
s.setAttribute('data-timestamp', + new Date());
(d.head || d.body).appendChild(s);

View File

@ -1,13 +1,27 @@
<div id="disqus-container">
{{ $ctx := . }}
{{ with .Site.DisqusShortname }}
<button id="disqus-button" onclick="showComments()">Show comments</button>
<div id="disqus-comments">
{{ if eq . "yourdiscussshortname" }}
{{ $isDummyName := eq . "yourdiscussshortname" }}
{{ $isServer := $.Site.IsServer }}
{{ if or $isDummyName $isServer }}
<p>Disqus comments are disabled.</p>
<script type="application/javascript">
function showComments() {
{{ partial "disqus-js-common.js" . | safeJS }}
}
</script>
{{ else }}
{{ template "_internal/disqus.html" $ctx }}
<div id="disqus_thread">
</div>
<script type="application/javascript">
function showComments() {
{{ partial "disqus-js-main.js" . | safeJS }}
{{ partial "disqus-js-common.js" . | safeJS }}
}
</script>
{{ end }}
<noscript>Enable JavaScript to view Disqus comments.</noscript>
</div>
{{ end }}
</div>

View File

@ -131,12 +131,3 @@
}
});
}());
/* Disqus comments */
function showComments() {
var disqusButton = document.getElementById('disqus-button');
disqusButton.remove();
var disqusComments = document.getElementById('disqus-comments');
disqusComments.style.display = 'block';
}