coder/layouts/partials/posts/disqus.html

27 lines
1.2 KiB
HTML
Raw Normal View History

2024-06-26 00:40:47 +03:00
{{- if and (not (eq (.Site.Config.Services.Disqus.Shortname | default "") "")) (eq (.Params.disableComments | default false) false) -}}
2024-01-03 19:09:11 +03:00
<div id="disqus_thread"></div>
<script>
window.disqus_config = function () {
{{with .Params.disqus_identifier }}this.page.identifier = '{{ . }}';{{end}}
{{with .Params.disqus_title }}this.page.title = '{{ . }}';{{end}}
{{with .Params.disqus_url }}this.page.url = '{{ . | html }}';{{end}}
};
(function() {
if (["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1) {
document.getElementById('disqus_thread').innerHTML = 'Disqus comments not available by default when the website is previewed locally.';
return;
}
var d = document, s = d.createElement('script'); s.async = true;
2024-06-26 00:40:47 +03:00
s.src = '//' + {{ .Site.Config.Services.Disqus.Shortname }} + '.disqus.com/embed.js';
2024-01-03 19:09:11 +03:00
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
// Disqus theme switching
document.addEventListener('themeChanged', function (e) {
if (document.readyState == 'complete') {
DISQUS.reset({ reload: true, config: disqus_config });
}
});
</script>
{{- end -}}