Skip to content

Persist light theme on refresh #513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 3, 2025
Merged

Conversation

samcunliffe
Copy link
Member

@samcunliffe samcunliffe commented Feb 2, 2025

Fixes

... using the workaround suggested in

Worth spending a bit of thought on whether we want more lines of my hacky JS code saving the theme to local storage, which we potentially can't delete until jtd/#1223 is solved nicely upstream.

Question:

Is it worth switching build system to something that supports theme toggling and inferring theme from the browser/os settings? It feels like it's the responsibility of the doc engine/doc theme. E.g. Material for MkDocs supports it.

That said, if you're happy with these lines, I am.

@samcunliffe samcunliffe requested a review from a team February 2, 2025 20:36
@samcunliffe samcunliffe added bug Something isn't working question Further information is requested website Related to https://github-pages.arc.ucl.ac.uk/python-tooling labels Feb 2, 2025
@samcunliffe samcunliffe self-assigned this Feb 2, 2025
@samcunliffe samcunliffe linked an issue Feb 2, 2025 that may be closed by this pull request
Copy link
Collaborator

@matt-graham matt-graham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think on balance having a few lines extra JS for a more functional site in the interim is worth the tradeoff, but agree it seems that using an alternative solution for building the site like Material for MkDocs which support this out of the box would be good.

When serving this locally and viewing in Firefox the theme still does not seem to persist between page changes, which from adding some console.log statements seems to be as the "DOMContentLoaded" event listener never gets called. As far as I can tell (my JavaScript knowledge is very minimal though!) the syntax for adding the event listener is all correct, so I am not sure if this is just something specific about serving this locally?

Copy link
Member

@Saransh-cpp Saransh-cpp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on does not work for me locally - both on refreshing and changing pages

Migrating to another docs generator sounds like the best option here

@samcunliffe

This comment was marked as outdated.

@samcunliffe samcunliffe marked this pull request as draft February 3, 2025 15:00
@samcunliffe samcunliffe marked this pull request as ready for review February 3, 2025 15:18
@samcunliffe
Copy link
Member Author

Now working for me...

Screen.Recording.2025-02-03.at.15.17.38.mov

Copy link
Collaborator

@matt-graham matt-graham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why it did, but with change to comment this does now work for me locally!

@samcunliffe
Copy link
Member Author

Not sure why it did, but with change to comment this does now work for me locally!

Python is cool. Javascript is not cool.

Copy link
Member

@Saransh-cpp Saransh-cpp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Works well now!

@samcunliffe samcunliffe merged commit a3003e2 into main Feb 3, 2025
15 checks passed
@samcunliffe samcunliffe deleted the fix-light-dark-toggle-persist branch February 3, 2025 18:33
@paddyroddy
Copy link
Member

➕ for moving to https://squidfunk.github.io/mkdocs-material as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested website Related to https://github-pages.arc.ucl.ac.uk/python-tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Light mode doesn't persist on navigation/refresh
4 participants