Skip to content

Add dark mode scss #1343

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 4 commits into from
Aug 26, 2024
Merged

Add dark mode scss #1343

merged 4 commits into from
Aug 26, 2024

Conversation

apiraino
Copy link
Contributor

@apiraino apiraino commented Jun 13, 2024

First attempt at avoiding being shock blinded when visiting the blog 😄

Note: this CSS applies only to the blog i.e. external links to www.rust-lang.org will take users to #fff land for now.

Preview (top)

Screenshot 2024-08-20 at 15-36-43 The Rust Programming Language Blog

Preview (bottom)

Screenshot 2024-06-13 at 20-49-34 The Rust Programming Language Blog

Example blog post

Screenshot 2024-07-29 at 17-17-31

Mobile view (simulated)

Screenshot 2024-08-20 at 15-38-06 The Rust Programming Language Blog

credits to @teohhanhui for providing 80% of this work, thanks!

@apiraino apiraino mentioned this pull request Jun 13, 2024
@apiraino
Copy link
Contributor Author

cc @Turbo87 for a review (unsure who is actually in charge for the blog)

thanks

@apiraino apiraino closed this Jul 24, 2024
@apiraino apiraino reopened this Jul 24, 2024
@apiraino apiraino force-pushed the dark-mode branch 2 times, most recently from badcba7 to 1974154 Compare July 26, 2024 15:54
@apiraino
Copy link
Contributor Author

@GuillaumeGomez I think we can now review the CSS for the dark mode. Took me a while to figure out a workflow allowing me to test all the changes ensuring that nothing in the light mode would change.

I like the colors of the dark mode (see screenshots in the first comment) but I'm open to changes. HTML var names are also a bit random, I'm happy to receive suggestions for more meaningful names.

In a follow-up patch, I'd like to add a button to switch theme. This will unfortunately make the blog not javascript-free anymore, I'm afraid 😞

Let me know your thoughts! Thanks :3

@GuillaumeGomez
Copy link
Member

Apart from the two variables with confusing names, it looks all good to me. Great job!

In a follow-up patch, I'd like to add a button to switch theme. This will unfortunately make the blog not javascript-free anymore, I'm afraid 😞

For me, the important part isn't that it's actually JS-free but rather than it works without JS and that JS only provides limited and secondary improvements. So handling themes with a button doesn't seem that bad to me (and will not require a lot of JS either).

@apiraino
Copy link
Contributor Author

apiraino commented Aug 9, 2024

ok @GuillaumeGomez I've added a theme selector 🙂 Notes:

  • The theme selector is only visible if the user agent has JavaScript enabled (since it's a JavaScript switcher, I thought it was a nice touch hiding it if it's not usable)
  • If JavaScript is disabled, we're reading the user agent preferences with no option to change it
  • Saves the theme preference in localStorage

@GuillaumeGomez
Copy link
Member

Looks all good to me, thanks! Now the big question is: who is allowed to merge in this repository? I can but not sure I should. 😅

@apiraino
Copy link
Contributor Author

ok @GuillaumeGomez: as far as I can see - we should be there. I can't think of anything else to add right now.

(I'll update the screenshots in the opening comment to reflect the latest version)

Copy link
Contributor

@senekor senekor left a comment

Choose a reason for hiding this comment

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

Looks good to me. Some non-blocking thoughts:

  • Is it possible to switch to a white version of the Rust logo? The black one is hard to see on the dark background.
  • Are there actually people who have dark mode enabled and go around manually reenabling light mode on certain websites? The javascript seems unnecessary to me, but I might be wrong.
  • The formatting changes are a bit irritating, but setting up auto-formatting and CI is something for another PR.

Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

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

Can be merged with Remo's comments addressed

@apiraino apiraino force-pushed the dark-mode branch 2 times, most recently from b5fdd8f to 069e913 Compare August 26, 2024 15:47
@apiraino apiraino force-pushed the dark-mode branch 2 times, most recently from 5f3edec to 6822157 Compare August 26, 2024 15:51
@apiraino
Copy link
Contributor Author

Looks good to me. Some non-blocking thoughts:

* Is it possible to switch to a white version of the Rust logo? The black one is hard to see on the dark background.

* Are there actually people who have dark mode enabled and go around manually reenabling light mode on certain websites? The javascript seems unnecessary to me, but I might be wrong.

* The formatting changes are a bit irritating, but setting up auto-formatting and CI is something for another PR.

hey @senekor I've fixed the Rust logo and removed the formatting to make it a clean PR.

About the JavaScript to switch theme, I kind of agree with you, I was hesitant either but every Rust site has that (rustdoc, www, not to mention clippy's that without JS is broken) 🤷‍♂️ If you feel strongly about it, happy1 to remove it.

Footnotes

  1. speaking as someone that usually keeps the NoScript extension on ;-)

@Manishearth Manishearth merged commit 21ac852 into rust-lang:master Aug 26, 2024
3 checks passed
@apiraino apiraino deleted the dark-mode branch August 26, 2024 18:47
@Turbo87
Copy link
Member

Turbo87 commented Dec 26, 2024

FWIW I was very confused when I visited the blog and it defaulted to dark mode. I double checked by system setting and it was in light mode, but changing it back and forth didn't help. It took a while until I discovered the theme switcher dropdown.

is there a reason why we don't default to the system setting?

@GuillaumeGomez
Copy link
Member

It's supposed to default to light mode as you can see defined in the CSS here and how it's handled in the JS here.

@Turbo87
Copy link
Member

Turbo87 commented Dec 26, 2024

hmm weird, I guess I must have had an old override in my localstorage somehow. I would still prefer it to follow my system setting though 😅

@GuillaumeGomez
Copy link
Member

We could always add a "system value" option like there is in rustdoc.

@apiraino
Copy link
Contributor Author

hmm weird, I guess I must have had an old override in my localstorage somehow. I would still prefer it to follow my system setting though 😅

The implementation should be:

  1. Read user preferences
  2. If no user settings, CSS defaults to system settings

You should be able to verify with a clean browser profile.

@senekor
Copy link
Contributor

senekor commented Dec 26, 2024

PR to add system setting: #1448

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.

5 participants