website/themes/terminal-plus-minus/layouts/partials/optional/comments.html
2019-09-03 15:00:42 +08:00

33 lines
1.6 KiB
HTML

{{- if $.Site.DisqusShortname -}}
<div class="site__comments">
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_config = function () {
this.page.url = "{{ .Permalink }}"; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = "{{ .Permalink }}"; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
function loadDisqus() {
// Don't ever inject Disqus on localhost--it creates unwanted
// discussions from 'localhost:1313' on your Disqus account...
if (window.location.hostname == "localhost") {
const devWarning = "You're in a development environment. Disqus will not load here.";
const disqusThread = document.querySelector("#disqus_thread");
console.log(devWarning);
disqusThread.textContent = devWarning;
return;
}
const dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
const disqus_shortname = '{{ $.Site.DisqusShortname }}';
dsq.src = "https://" + disqus_shortname + ".disqus.com/embed.js";
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
};
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<button onclick="toggleVisibilityEvent({ event, oneTime: true, callback: loadDisqus })">
Load comments
</button>
</div>
{{ end }}