diff options
author | zzossig <zzossig@gmail.com> | 2020-06-11 09:14:08 +0300 |
---|---|---|
committer | zzossig <zzossig@gmail.com> | 2020-06-11 09:14:08 +0300 |
commit | 6ae0e3a583958234ba3ff523788c3f76c26543fb (patch) | |
tree | 31b568e8c1b3f0b8cd9f134eba61a109d3eb7161 | |
parent | 59c481b068d0a53d443ab9e3514c2ab995b47de6 (diff) |
[bug fix] utterances default theme
fix #260
-rw-r--r-- | layouts/partials/comments/utterances.html | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/layouts/partials/comments/utterances.html b/layouts/partials/comments/utterances.html index 6a22588..33e9e0c 100644 --- a/layouts/partials/comments/utterances.html +++ b/layouts/partials/comments/utterances.html @@ -2,14 +2,27 @@ <noscript>Please enable JavaScript to view the <a href="https://github.com/utterance">comments powered by utterances.</a></noscript> <script> document.addEventListener('DOMContentLoaded', function () { + function checkTheme(local, base) { + if (local === "dark" || base === "dark") { + return "photon-dark"; + } else if (local === "hacker" || base === "hacker") { + return "photon-dark"; + } else if (local === "kimbie" || base === "kimbie") { + return "github-dark-orange"; + } else { + return "github-light"; + } + } + try { {{ $owner:= .Site.Params.utterances.owner }} var owner = JSON.parse({{ $owner | jsonify }}); {{ $repo:= .Site.Params.utterances.repo }} var repo = JSON.parse({{ $repo | jsonify }}); + {{ $baseTheme:= index .Site.Params.themeOptions 0 }} + var baseTheme = JSON.parse({{ $baseTheme | jsonify }}); var localTheme = localStorage.getItem('theme'); - var utterTheme = localTheme === "dark" || localTheme === "hacker" ? 'photon-dark' : localTheme === 'kimbie' ? 'github-dark-orange' : 'github-light' - + var utterTheme = checkTheme(localTheme, baseTheme); var myScript = document.createElement('script'); myScript.setAttribute('src', 'https://utteranc.es/client.js'); myScript.setAttribute('repo', `${owner}/${repo}`); @@ -21,6 +34,8 @@ myScript.onload = function() { } + + document.getElementById('utterances').appendChild(myScript); } catch (err) { console.log(err); |