fi3ework / hexo-theme-archer

🎯 A smart and modern theme for Hexo.
https://fi3ework.github.io/hexo-theme-archer
MIT License
1.49k stars 274 forks source link

默认dark mode没有奏效 #390

Closed Bachamht closed 6 months ago

Bachamht commented 6 months ago

查看源码中关于light/dark mode的部分,发现代码:

// 初始化切换主题颜色模式功能
const initThemeModeSwitchButton = function () {
  setThemeModeSwitchBtnActive(false)

  // 默认情况下,加载暗色主题
  // 若用户偏好浅色主题,则切换主题颜色模式

  if (getPreferredThemeMode() === 'light') {
    switchThemeMode(window.siteMeta.root)
  }
  $themeModeSwitchBtn.click(function () {
    switchThemeMode(window.siteMeta.root)
  })

  setThemeModeSwitchBtnActive(true)
}

似乎这段代码并没有执行,默认模式是light 但添加的点击事件成功运行,切换主题颜色功能正常

Stark-X commented 6 months ago

实际上是根据你的系统主题偏好来的。 你可以试一下先切换成浅色主题,再打开浏览器的“隐身模式”,然后打开 demo 站点的主页。 关闭隐身模式之后,切换成深色主题,再打开网页看看。

Bachamht commented 6 months ago

了解了,但是我想设置成忽视系统主题偏好,一律为dark mode 于是注释掉了下面的代码:


  if (getPreferredThemeMode() === 'light') {
    switchThemeMode(window.siteMeta.root)
  }

然后执行

hexo clean && hexo generate --deploy

在清除了浏览器缓存之后访问重新部署后的站点,它还是light mode 有什么办法设置成固定的mode吗, 万分感谢🙏

LolipopJ commented 6 months ago

参考 https://github.com/fi3ework/hexo-theme-archer/blob/master/docs%2Fdevelop-guide-zh.md ,对脚本文件的还需要执行编译操作。

Bachamht commented 6 months ago

好的 谢谢bro