Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
48 lines (47 sloc) 1.99 KB
{{ if and (not (eq .Site.DisqusShortname "")) (and (not .Params.disable_comments) (or (eq .Kind "404") (and (not .IsHome) .Content))) }}
<section class="comments">
<div id="disqus_thread"></div>
<script>
var disqus_config = function () {
{{ with .Site.Params.disqusURL }}
this.page.url = "{{ . }}" +{{ if eq $.Kind "404" }} "/404.html" {{ else }} location.pathname{{ end }};
{{ end }}
};
(function() {
var inIFrame = function() {
var iframe = true;
try { iframe = window.self !== window.top; } catch (e) {}
return iframe;
};
if (inIFrame()) return;
var disqus_js = '//{{ .Site.DisqusShortname }}.disqus.com/embed.js';
var d = document, s = d.createElement('script');
s.src = disqus_js; s.async = true;
s.setAttribute('data-timestamp', +new Date());
var b = false, l = function() {
if (b) return;
(d.head || d.body).appendChild(s); b = true;
}
var t = d.getElementById('disqus_thread');
s.onerror = function(e) {
if (sessionStorage.getItem('failure-note')) return;
t.innerText = 'Sorry, but you cannot make comments because Disqus failed to load for some reason. It is known to be blocked in China. If you are sure it is not blocked in your region, please refresh the page. 中国大陆地区读者需要翻墙才能发表评论。';
t.style.border = '1px dashed';
t.style.padding = '.5em';
t.style.background = 'lightyellow';
sessionStorage.setItem('failure-note', true);
};
// show comments when the hash means to jump to a comment
if (location.hash.match(/^#comment/)) return l();
var c = function() {
if (b) return;
var rect = t.getBoundingClientRect();
if (rect.top < window.innerHeight && rect.bottom >= 0) l();
};
window.addEventListener('load', c);
d.addEventListener('scroll', c);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</section>
{{ end }}