hugo-theme-gruvbox
hugo-theme-gruvbox copied to clipboard
setting defaultTheme has no effect
Setting params.defaultTheme
in ./config/_default/config.toml has no effect.
No matter whether set to "dark" or "light", the theme is always dark.
On the other hand, setting params.themeColor
and params.themeContrast
have the desired effects.
Theme selection is a bit convoluted, I probably should add some explanations somewhere.
When the site initially loads, it will set theme
attribute of the html
properly:
https://github.com/schnerring/hugo-theme-gruvbox/blob/dbf1af452041c500e276dd6589963b081769c849/layouts/_default/baseof.html#L2-L5
Inside dark-mode.js
this behavior is overriden by the following logic:
https://github.com/schnerring/hugo-theme-gruvbox/blob/dbf1af452041c500e276dd6589963b081769c849/assets/js/dark-mode.js#L1-L31
- Check whether a preferred theme is stored inside local storage. This will always have a value after the page loaded for the first time (
Initial Load
). So if you debugged the page and setdefaultTheme
after, you'll have to delete cookies/site data. - Also, if the browser supports it, the OS theme-preference is checked which overrides
defaultTheme
. If you want to test this, disable JavaScript. - If neither (1) and (2) (
Undefined
) are true, thedefaultTheme
will be displayed.
Understood.
So in my case, it's because the brower's default theme.
Thanks for the detailed explanation. Where should it be documented?
The README or the code/config file.