Recently I’ve switched from Jekyll to Hugo. On my old site, I figured out a hacky way to have two themes for the static site that was pretty close to what was described in the post above.
However, because the difference between the ‘dark’ theme and the ‘light’ theme is one css file name (theme-light.css vs theme-dark.css), I’m hoping there’s some way to switch between the two that doesn’t involve maintaining two sites (even if that maintenance is just copying or linking the entire tree for the second site.)
Thanks! I guess I wasn’t using the right keywords in my searches.
Even when using the VanillaJS version, I’m seeing the flash of unstyled content mentioned before the javascript can load the styles. I also noticed the dates for those solutions are a bit dated.
I was able to cut down the FOUC to a quick blink of a blank white screen (rather than a slower flash of unstyled content) with Jeff’s solution in the the link below (it uses css to hide with 0 opacity), but I was really hoping not to even have that. – But that solution is much better than what I had, so I can live with it, if that’s not the case.
A little late to the party, but I have implemented night mode switch on my Hugo website without light flash! You can see a live implementation of this in the following tutorial: Add Dark Mode to Hugo. Basically, you need to inline all the code inside one partial and it works flowlessly.