Add defaultTheme option to override OS choice #302
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduction
This is a PR that re-adds the (optional!) ability to have a defaultTheme, as before the new theming rework.
Behavior
If defaultTheme is not set, the behavior is unchanged from the current master branch.
If defaultTheme is set to "light" or "dark", that will be used before the OS theme.
Order of priority:
Documentation
I've added documentation to both exampleSite's config and updated the primary README to account for this feature.
Bonus
As a side effect, the Table of Contents was regenerated to be fully accurate to the README by my tooling, and I threw in a bonus spelling fix on License.
Compatibility
This should be fully compatible with current configurations with no changes, with one caveat: if a user still has "defaultTheme" in their configuration, it will begin to work again.
Breaking Changes
There is one very minor feature that was dropped because I'm not quite sure the best way to implement it.
These two listeners are now gone - my understanding is these would only update the theme if the OS Color theme changed while the site was open. This seems like a fairly rare edge case, and given it's a static site I'm not sure users would expect the website's theme to update dynamically.
Of course, this could be edited back in, if you can think of an elegant way to implement it (the problem is I can't think of a good check for if the current theme is set by the site config, user, or OS - this code should only be present in the last case).
Demo
This is in use at https://abyss.dev if you want to demo - it is set to have a defaultTheme of "dark", with themeToggle set to true.
Conclusion
Of course, this is a fairly substantial change, so feel free to tweak the commits or give feedback as needed. :)