From 47832083d8669f7269a6a301f79eb44247a9a5d0 Mon Sep 17 00:00:00 2001 From: "Gleb A." <94681073+gleb-kun@users.noreply.github.com> Date: Wed, 21 May 2025 13:52:47 +0300 Subject: [PATCH] refactor(comments): use `includes` instead of `indexOf` to improve readability (#1128) * fix(disqusjs): refactor local DisqusJS loading check for improved readability * fix(gitalk): refactor local Gitalk loading check for improved readability --- layouts/partials/comments/provider/disqusjs.html | 8 ++++++-- layouts/partials/comments/provider/gitalk.html | 7 ++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/layouts/partials/comments/provider/disqusjs.html b/layouts/partials/comments/provider/disqusjs.html index 967c38c..f4f4c03 100644 --- a/layouts/partials/comments/provider/disqusjs.html +++ b/layouts/partials/comments/provider/disqusjs.html @@ -21,8 +21,12 @@ } function lazyLoadDisqusJS() { - 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.'; + const excludedHosts = ["localhost", "127.0.0.1"]; + const hostname = window.location.hostname; + + if (excludedHosts.includes(hostname)) { + document.getElementById('disqus_thread').innerHTML = + 'Disqus comments not available by default when the website is previewed locally.'; return; } diff --git a/layouts/partials/comments/provider/gitalk.html b/layouts/partials/comments/provider/gitalk.html index 54bfcba..ac77fc6 100644 --- a/layouts/partials/comments/provider/gitalk.html +++ b/layouts/partials/comments/provider/gitalk.html @@ -18,9 +18,10 @@ proxy: {{- .proxy -}}, }); (function () { - if ( - ["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1 - ) { + const excludedHosts = ["localhost", "127.0.0.1"]; + const hostname = window.location.hostname; + + if (excludedHosts.includes(hostname)) { document.getElementById("gitalk-container").innerHTML = "Gitalk comments not available by default when the website is previewed locally."; return;