Skip to content

Commit

Permalink
fix: utterances dark theme
Browse files Browse the repository at this point in the history
fix #896
  • Loading branch information
HEIGE-PCloud committed Apr 14, 2023
1 parent e912b11 commit 0ef5b0f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions assets/js/lib/utterances.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ if (window.config?.comment?.utterances) {
const iframe = document.querySelector('.utterances-frame')
iframe.contentWindow.postMessage(message, 'https://utteranc.es')
}
console.log(window.switchThemeEventSet)
window.switchThemeEventSet.add(window._utterancesOnSwitchTheme)
console.log(window.switchThemeEventSet)
}
1 change: 0 additions & 1 deletion assets/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,6 @@ function init () {
window.oldScrollTop = window.newScrollTop
window.scrollEventSet = new Set()
window.resizeEventSet = new Set()
window.switchThemeEventSet = new Set()
window.clickMaskEventSet = new Set()
if (window.objectFitImages) objectFitImages()
initSVGIcon()
Expand Down
6 changes: 3 additions & 3 deletions exampleSite/config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -389,17 +389,17 @@ cacheRemoteImages = false
# Utterances comment config (https://utteranc.es/)
# Utterances comment 评论系统设置 (https://utteranc.es/)
[page.comment.utterances]
enable = false
enable = true
# owner/repo
repo = ""
repo = "Hugo-DoIt/utterances-comments"
issueTerm = "pathname"
label = ""
lightTheme = "github-light"
darkTheme = "github-dark"
# Twikoo comment config (https://twikoo.js.org/)
# Twikoo comment 评论系统设置 (https://twikoo.js.org/)
[page.comment.twikoo]
enable = true
enable = false
envId = "https://twikoo-comments-doit.vercel.app/"
region = ""
path = ""
Expand Down
3 changes: 2 additions & 1 deletion layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
{{- /* Check theme isDark before body rendering */ -}}
{{- $theme := .Site.Params.defaulttheme -}}
<script type="text/javascript">
function setTheme(theme) {document.body.setAttribute('theme', theme); document.documentElement.style.setProperty('color-scheme', theme === 'light' ? 'light' : 'dark'); window.theme = theme; }
function setTheme(theme) {document.body.setAttribute('theme', theme); document.documentElement.style.setProperty('color-scheme', theme === 'light' ? 'light' : 'dark'); window.theme = theme; window.isDark = window.theme !== 'light' }
function saveTheme(theme) {window.localStorage && localStorage.setItem('theme', theme);}
function getMeta(metaName) {const metas = document.getElementsByTagName('meta'); for (let i = 0; i < metas.length; i++) if (metas[i].getAttribute('name') === metaName) return metas[i]; return '';}
if (window.localStorage && localStorage.getItem('theme')) {let theme = localStorage.getItem('theme');theme === 'light' || theme === 'dark' || theme === 'black' ? setTheme(theme) : (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? setTheme('dark') : setTheme('light')); } else { if ('{{ $theme }}' === 'light' || '{{ $theme }}' === 'dark' || '{{ $theme }}' === 'black') setTheme('{{ $theme }}'), saveTheme('{{ $theme }}'); else saveTheme('auto'), window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? setTheme('dark') : setTheme('light');}
let metaColors = {'light': '#f8f8f8','dark': '#252627','black': '#000000'}
getMeta('theme-color').content = metaColors[document.body.getAttribute('theme')];
window.switchThemeEventSet = new Set()
</script>
<div id="back-to-top"></div>
<div id="mask"></div>
Expand Down

1 comment on commit 0ef5b0f

@vercel
Copy link

@vercel vercel bot commented on 0ef5b0f Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.