Skip to content

style(pkgdown): default theme to time of day, not always dark#4

Open
truenomad wants to merge 1 commit into
masterfrom
style/pkgdown-theme-time-of-day
Open

style(pkgdown): default theme to time of day, not always dark#4
truenomad wants to merge 1 commit into
masterfrom
style/pkgdown-theme-time-of-day

Conversation

@truenomad

Copy link
Copy Markdown
Contributor

Summary

  • Stop forcing localStorage['pkgdown-theme'] = 'dark' on a visitor's first paint.
  • Pick the initial theme by local hour instead: 07:00–18:59 → light, 19:00–06:59 → dark.
  • Visitor's explicit choice via the navbar light-switch wins (saved in localStorage as before).
  • The time-of-day default is intentionally not persisted, so each fresh visit re-evaluates until the visitor toggles.

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

  • Clear localStorage, set local clock to 12:00 → first load is light.
  • Clear localStorage, set local clock to 22:00 → first load is dark.
  • After clicking the navbar light-switch, refresh → chosen theme persists.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant