disqus.html 1.2 KB

1234567891011121314151617181920212223242526
  1. {{- if and (not (eq (.Site.Config.Services.Disqus.Shortname | default "") "")) (eq (.Params.disableComments | default false) false) -}}
  2. <div id="disqus_thread"></div>
  3. <script>
  4. window.disqus_config = function () {
  5. {{with .Params.disqus_identifier }}this.page.identifier = '{{ . }}';{{end}}
  6. {{with .Params.disqus_title }}this.page.title = '{{ . }}';{{end}}
  7. {{with .Params.disqus_url }}this.page.url = '{{ . | html }}';{{end}}
  8. };
  9. (function() {
  10. if (["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1) {
  11. document.getElementById('disqus_thread').innerHTML = 'Disqus comments not available by default when the website is previewed locally.';
  12. return;
  13. }
  14. var d = document, s = d.createElement('script'); s.async = true;
  15. s.src = '//' + {{ .Site.Config.Services.Disqus.Shortname }} + '.disqus.com/embed.js';
  16. s.setAttribute('data-timestamp', +new Date());
  17. (d.head || d.body).appendChild(s);
  18. })();
  19. // Disqus theme switching
  20. document.addEventListener('themeChanged', function (e) {
  21. if (document.readyState == 'complete') {
  22. DISQUS.reset({ reload: true, config: disqus_config });
  23. }
  24. });
  25. </script>
  26. {{- end -}}