fix: add disqus comment counter after posts have loaded

This commit is contained in:
Oliver Booth 2023-08-10 16:14:30 +01:00
parent 8a3061f23a
commit 4244f9f014
Signed by: oliverbooth
GPG Key ID: 725DB725A0D9EE61
3 changed files with 14 additions and 3 deletions

View File

@ -23,7 +23,7 @@
{{#if post.enable_comments}} {{#if post.enable_comments}}
<span> &bull; </span> <span> &bull; </span>
<a href="{{post.url}}#disqus_thread" data-disqus-identifier="{{post.disqus_identifier}}"> <a href="{{post.url}}#disqus_thread" data-disqus-identifier="{{post.disqus_identifier}}">
0 Comments Loading comment count &hellip;
</a> </a>
{{/if}} {{/if}}
</p> </p>
@ -39,5 +39,3 @@
{{/if}} {{/if}}
</div> </div>
</script> </script>
<script id="dsq-count-scr" src="https://oliverbooth-dev.disqus.com/count.js" async></script>

View File

@ -10,6 +10,17 @@ class UI {
return document.querySelector("#blog-post-template"); return document.querySelector("#blog-post-template");
} }
/**
* Creates a <script> element that loads the Disqus comment counter.
*/
public static createDisqusCounterScript(): HTMLScriptElement {
const script = document.createElement("script");
script.id = "dsq-count-scr";
script.src = "https://oliverbooth-dev.disqus.com/count.js";
script.async = true;
return script;
}
/** /**
* Forces all UI elements to update. * Forces all UI elements to update.
*/ */

View File

@ -47,6 +47,8 @@ declare const Handlebars: any;
i += 4; i += 4;
} }
document.body.appendChild(UI.createDisqusCounterScript());
const spinner = document.querySelector("#blog-loading-spinner"); const spinner = document.querySelector("#blog-loading-spinner");
if (spinner) { if (spinner) {
spinner.classList.add("removed"); spinner.classList.add("removed");