From c2a934f56693f9c9958ee58c1d230c1042efd870 Mon Sep 17 00:00:00 2001 From: Zachary Betz Date: Thu, 7 Mar 2019 14:13:56 -0600 Subject: [PATCH] Only load disqus comments on button click --- layouts/partials/disqus-js-common.js | 6 ++++++ layouts/partials/disqus-js-main.js | 10 ++++++++++ layouts/partials/disqus.html | 20 +++++++++++++++++--- static/js/dom-scripts.js | 9 --------- 4 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 layouts/partials/disqus-js-common.js create mode 100644 layouts/partials/disqus-js-main.js diff --git a/layouts/partials/disqus-js-common.js b/layouts/partials/disqus-js-common.js new file mode 100644 index 0000000..e709807 --- /dev/null +++ b/layouts/partials/disqus-js-common.js @@ -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'; \ No newline at end of file diff --git a/layouts/partials/disqus-js-main.js b/layouts/partials/disqus-js-main.js new file mode 100644 index 0000000..74bff17 --- /dev/null +++ b/layouts/partials/disqus-js-main.js @@ -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); \ No newline at end of file diff --git a/layouts/partials/disqus.html b/layouts/partials/disqus.html index 19305cc..1105c91 100644 --- a/layouts/partials/disqus.html +++ b/layouts/partials/disqus.html @@ -1,13 +1,27 @@
- {{ $ctx := . }} {{ with .Site.DisqusShortname }}
- {{ if eq . "yourdiscussshortname" }} + {{ $isDummyName := eq . "yourdiscussshortname" }} + {{ $isServer := $.Site.IsServer }} + {{ if or $isDummyName $isServer }}

Disqus comments are disabled.

+ {{ else }} - {{ template "_internal/disqus.html" $ctx }} +
+
+ {{ end }} +
{{ end }}
diff --git a/static/js/dom-scripts.js b/static/js/dom-scripts.js index cc5f5b8..5128836 100644 --- a/static/js/dom-scripts.js +++ b/static/js/dom-scripts.js @@ -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'; -}