diff options
author | Makise Von <v.makise@foxmail.com> | 2022-03-27 06:20:35 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-27 06:20:35 +0300 |
commit | 1c0beeddd73f59f6c82f792d0918d961b4069792 (patch) | |
tree | 7928c51119c1287f3a0111c3b2f70783da1d3d73 | |
parent | 2a7732ffa5dc2c7b961c2724abc254272111c775 (diff) |
fix: check before loading comments (#374)
-rw-r--r-- | layouts/partials/third-party/disqus.html | 3 | ||||
-rw-r--r-- | layouts/partials/third-party/gitalk.html | 5 | ||||
-rw-r--r-- | layouts/partials/third-party/utterances.html | 3 | ||||
-rw-r--r-- | layouts/partials/third-party/valine.html | 3 |
4 files changed, 13 insertions, 1 deletions
diff --git a/layouts/partials/third-party/disqus.html b/layouts/partials/third-party/disqus.html index 6b09af2..a7b8c47 100644 --- a/layouts/partials/third-party/disqus.html +++ b/layouts/partials/third-party/disqus.html @@ -1,6 +1,9 @@ {{- $rawTitle := (partial "utils/title.html" (dict "$" . "title" .Title)).rawTitle -}} <script> function loadComments() { + if (!document.getElementById('disqus_thread')) { + return; + } if (typeof DISQUS === 'undefined') { var disqus_config = function() { {{ with .Params.disqus_url | default .Permalink }}this.page.url = '{{ . }}';{{ end }} diff --git a/layouts/partials/third-party/gitalk.html b/layouts/partials/third-party/gitalk.html index fca8c89..d050bfe 100644 --- a/layouts/partials/third-party/gitalk.html +++ b/layouts/partials/third-party/gitalk.html @@ -1,6 +1,9 @@ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css"> <script> function loadComments() { + if (!document.getElementById('gitalk-container')) { + return; + } if (typeof Gitalk === 'undefined') { var getScript = (options) => { var script = document.createElement('script'); @@ -41,4 +44,4 @@ gitalk.render('gitalk-container') } -</script>
\ No newline at end of file +</script> diff --git a/layouts/partials/third-party/utterances.html b/layouts/partials/third-party/utterances.html index 5f667dd..d057fda 100644 --- a/layouts/partials/third-party/utterances.html +++ b/layouts/partials/third-party/utterances.html @@ -2,6 +2,9 @@ function loadComments() { (function() { var utterances = document.getElementById("utterances"); + if (!utterances) { + return; + } var script = document.createElement('script'); script.src = 'https://utteranc.es/client.js'; script.async = true; diff --git a/layouts/partials/third-party/valine.html b/layouts/partials/third-party/valine.html index 7c11a3a..e372eac 100644 --- a/layouts/partials/third-party/valine.html +++ b/layouts/partials/third-party/valine.html @@ -1,5 +1,8 @@ <script> function loadComments() { + if (!document.getElementById('vcomments')) { + return; + } if (typeof Valine === 'undefined') { var getScript = (options) => { var script = document.createElement('script'); |