binokochumolvarghese / lightbi-hugo

Lightbi is a minimal and clean blog theme for Hugo.
https://lightbi-hugo-theme.netlify.app/
MIT License
64 stars 36 forks source link

Improve dark mode handling #46

Closed palant closed 6 months ago

palant commented 6 months ago

Currently, when using dark mode and loading the page the light background flashes briefly before dark mode is enabled. That’s because of the script switching on dark mode loads only at the end of the page. That doesn’t have to be if color theme is determined by an attribute on the <html> tag. Additional advantage here: no separate request to load dark mode CSS, it can be part of the main CSS file.

This pull request addresses a few more minor issues:

Ideally, user’s dark mode preferences should be respected even if JavaScript is disabled. However, without CSS processing (e.g. via Sass) this would become too messy – the CSS code is already messy as it is with :root[data-theme="dark"] spelled out multiple times.