style(pkgdown): default theme to time of day, not always dark#4
Open
truenomad wants to merge 1 commit into
Open
style(pkgdown): default theme to time of day, not always dark#4truenomad wants to merge 1 commit into
truenomad wants to merge 1 commit into
Conversation
The pre-paint inline script in template.includes.in_header was writing 'dark' to localStorage on any first visit, so every new visitor saw dark mode regardless of when they showed up. That overrode pkgdown's own default-light behaviour and made the navbar light-switch look broken on first paint. New behaviour: if the visitor has clicked the light-switch (saved 'light' or 'dark' in localStorage), respect that. Otherwise pick by local hour - 07:00 inclusive to 19:00 exclusive defaults to light, otherwise dark - and do NOT persist that choice so each visit re-evaluates until the visitor picks one explicitly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
localStorage['pkgdown-theme'] = 'dark'on a visitor's first paint.Why
The old script wrote
'dark'to localStorage on every first visit, which meant the navbar light-switch looked broken (no visible effect on a refresh, because the script kept overwriting whatever the visitor toggled if they hadn't actually persisted a choice). It also meant a daytime first-time visitor always landed on dark.Test plan