Skip to content

Commit 4783208

Browse files
authored
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
1 parent d9acd77 commit 4783208

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

layouts/partials/comments/provider/disqusjs.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@
2121
}
2222

2323
function lazyLoadDisqusJS() {
24-
if (["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1) {
25-
document.getElementById('disqus_thread').innerHTML = 'Disqus comments not available by default when the website is previewed locally.';
24+
const excludedHosts = ["localhost", "127.0.0.1"];
25+
const hostname = window.location.hostname;
26+
27+
if (excludedHosts.includes(hostname)) {
28+
document.getElementById('disqus_thread').innerHTML =
29+
'Disqus comments not available by default when the website is previewed locally.';
2630
return;
2731
}
2832

layouts/partials/comments/provider/gitalk.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
proxy: {{- .proxy -}},
1919
});
2020
(function () {
21-
if (
22-
["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1
23-
) {
21+
const excludedHosts = ["localhost", "127.0.0.1"];
22+
const hostname = window.location.hostname;
23+
24+
if (excludedHosts.includes(hostname)) {
2425
document.getElementById("gitalk-container").innerHTML =
2526
"Gitalk comments not available by default when the website is previewed locally.";
2627
return;

0 commit comments

Comments
 (0)