Fixed Disqus integration with instant loading

This commit is contained in:
squidfunk 2021-10-02 13:48:23 +02:00
parent 2d3354bd0e
commit e71b129433
2 changed files with 26 additions and 11 deletions

View File

@ -8,5 +8,5 @@
{% if not page.is_homepage and disqus %}
<h2 id="__comments">{{ lang.t("meta.comments") }}</h2>
<div id="disqus_thread"></div>
<script>var disqus_config=function(){this.page.url="{{ page.canonical_url }}",this.page.identifier="{{ page.canonical_url | replace(config.site_url, '') }}"};window.addEventListener("load",function(){var e=document,i=e.createElement("script");i.src="//{{ disqus }}.disqus.com/embed.js",i.setAttribute("data-timestamp",+new Date),(e.head||e.body).appendChild(i)})</script>
<script>var script,disqus_config=function(){this.page.url="{{ page.canonical_url }}",this.page.identifier="{{ page.canonical_url | replace(config.site_url, '') }}"};"undefined"==typeof DISQUS?((script=document.createElement("script")).async=!0,script.src="https://{{ disqus }}.disqus.com/embed.js",script.setAttribute("data-timestamp",Date.now()),document.body.appendChild(script)):DISQUS.reset({reload:!0,config:function(){this.page.identifier="{{ page.title }}",this.page.url="{{ page.canonical_url }}"}})</script>
{% endif %}

View File

@ -31,16 +31,31 @@
<h2 id="__comments">{{ lang.t("meta.comments") }}</h2>
<div id="disqus_thread"></div>
<script>
var disqus_config = function () {
this.page.url = "{{ page.canonical_url }}";
var disqus_config = function() {
this.page.url = "{{ page.canonical_url }}"
this.page.identifier =
"{{ page.canonical_url | replace(config.site_url, '') }}";
};
window.addEventListener("load", function() {
var d = document, s = d.createElement("script");
s.src = "//{{ disqus }}.disqus.com/embed.js";
s.setAttribute("data-timestamp", +new Date());
(d.head || d.body).appendChild(s);
})
"{{ page.canonical_url | replace(config.site_url, '') }}"
}
/* Set up for the first time */
if (typeof DISQUS === "undefined") {
var script = document.createElement("script")
script.async = true
script.src = "https://{{ disqus }}.disqus.com/embed.js"
script.setAttribute("data-timestamp", Date.now())
/* Inject script tag */
document.body.appendChild(script)
/* Set up on navigation (instant loading) */
} else {
DISQUS.reset({
reload: true,
config: function () {
this.page.identifier = "{{ page.title }}"
this.page.url = "{{ page.canonical_url }}"
}
})
}
</script>
{% endif %}