我一直觉得把自动切换日间和夜间模式的时间写成早6晚6很别扭,我想设成早8和晚10。

修改源码

找到[blogroot]\themes\butterfly\scripts\helpers\inject_head_js.js,在const { darkmode, aside } = this.theme下粘贴如下代码

1
2
const am = darkmode.am ? darkmode.am : 6
const pm = darkmode.pm ? darkmode.pm + 12 : 18

接下来搜索 const isNight = hour <= 6 || hour >= 18 改成 const isNight = hour <= ${am} || hour >= ${pm} (共有两处)

修改配置文件

打开你的主题配置文件(_config.butterfly.yml)
搜索darkmode,改成如下样式:
(就是添加最后两行的am和pm配置)

1
2
3
4
5
6
7
8
9
10
11
12
darkmode:
enable: true
# Toggle Button to switch dark/light mode
button: false
# Switch dark/light mode automatically (自動切換 dark mode和 light mode)
# autoChangeMode: 1 Following System Settings, if the system doesn't support dark mode, it will switch dark mode between 6 pm to 6 am
# autoChangeMode: 2 Switch dark mode between 6 pm to 6 am
# autoChangeMode: false
autoChangeMode: 2
# Set the switch time. The value is between 0 and 12. If not set, the default value is 6
am: 8
pm: 10

小工告成🤭