Skip to content
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

Allow (auto)switching front page between light mode and dark mode #37444

Open
sftim opened this issue Oct 22, 2022 · 37 comments · May be fixed by #49586
Open

Allow (auto)switching front page between light mode and dark mode #37444

sftim opened this issue Oct 22, 2022 · 37 comments · May be fixed by #49586
Assignees
Labels
area/web-development Issues or PRs related to the kubernetes.io's infrastructure, design, or build processes kind/feature Categorizes issue or PR as related to a new feature. priority/backlog Higher priority than priority/awaiting-more-evidence. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@sftim
Copy link
Contributor

sftim commented Oct 22, 2022

This is a Feature Request

What would you like to be added
A cut down form of #25061
Allow (auto)switching front page between light mode and dark mode

Why is this needed
Change https://kubernetes.io/ (and only that page) to support detecting the viewer's preference for either light mode or dark mode, and then honoring it.

This should use a similar technique to https://opensource.com/article/21/10/dark-themes-websites and must also play well with our custom Docsy theme.

For images, we might need a custom shortcode that renders to something like:

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="/images/blocks-dark.svg">
  <source media="(prefers-color-scheme: light)" srcset="/images/blocks-light.svg">
 <img src="/images/blocks.svg" alt="">
</picture>

Implementing that shortcode or layout would be part of the work for this issue.

Comments
This is a minimum-viable-product approach. It's much easier to make the change work for just one page, and then iterate.

Future work might also allow a mechanism to let the user specify a preference for dark or light mode that is different from what their user agent (web browser) is asserting.

After covering https://kubernetes.io/ we could look at whether there are other pages on the site where we're happy to widen the automatic switching to. For example, https://kubernetes.io/community/

Alternatively, we might work on https://kubernetes.dev/ (full site) and then come back to https://kubernetes.io/ once we've learned how to get a site working with 2 color schemes.

/area web-development
/kind feature

@sftim sftim added the kind/feature Categorizes issue or PR as related to a new feature. label Oct 22, 2022
@k8s-ci-robot k8s-ci-robot added area/web-development Issues or PRs related to the kubernetes.io's infrastructure, design, or build processes needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 22, 2022
@sachinparihar
Copy link
Contributor

/assign
I'd like to work on this.

@Ritikaa96
Copy link
Contributor

Hi @sftim is anyone working on this feature? if not then I'd like to try adding this feature.

@sachinparihar
Copy link
Contributor

Hi @sftim is anyone working on this feature? if not then I'd like to try adding this feature.

I'm not working on it right now! if you want to work on it you can.

@sachinparihar sachinparihar removed their assignment Nov 10, 2022
@tamilselvan1102
Copy link

/assign

@tamilselvan1102
Copy link

@sftim
suggest me where to place the toggle button.

k8sHomePage

@sftim
Copy link
Contributor Author

sftim commented Nov 16, 2022

How about putting the button above "Edit this page"?

This issue is about changing https://kubernetes.io/ (and only that page) so for now let's skip adding an override button, and rely on detecting the user's preference.

@sftim
Copy link
Contributor Author

sftim commented Nov 16, 2022

/triage accepted
/priority backlog

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Nov 16, 2022
@tamilselvan1102 tamilselvan1102 removed their assignment Nov 16, 2022
@Ritikaa96
Copy link
Contributor

For now i'd like to /assign it to myself and wait for a go ahead to work on it.

@Ritikaa96
Copy link
Contributor

/assign

@sftim
Copy link
Contributor Author

sftim commented Nov 16, 2022

For now i'd like to /assign it to myself and wait for a go ahead to work on it.

You (and all other contributors) don't need anyone's permission to start work.
Anyone's welcome to work on this issue, or indeed any k/website issue. If someone has already made a start, it's polite to try to sync up and collaborate with them.

@Ritikaa96
Copy link
Contributor

Thanks @sftim ,

so for now let's skip adding an override button, and rely on detecting the user's preference.

i am slightly confused by the statement.
So as much I understood we are to add this feature to the one page for now and no override button.
Am i getting this right?
where do you suggest we put the changing action for view modes?

@sftim
Copy link
Contributor Author

sftim commented Nov 16, 2022

This is a limited scope issue to get familiar with using CSS to restyle the page, and to work out what we'll do with the images / icons.

where do you suggest we put the changing action for view modes?

Someone who wants to try this out will have to set their browser to dark mode or light mode explicitly (or wait until dawn / sunset).

@sftim
Copy link
Contributor Author

sftim commented Nov 16, 2022

https://www.pcmag.com/how-to/how-to-enable-dark-mode-on-your-browser explains how to set dark mode

@Ritikaa96
Copy link
Contributor

Someone who wants to try this out will have to set their browser to dark mode or light mode explicitly (or wait until dawn / sunset).

Thanks @sftim , My first thought was that we want to add a button to help users choose which mode they prefer on the page.

This is a limited scope issue to get familiar with using CSS to restyle the page, and to work out what we'll do with the images / icons.

I might have seen a reference to go through with this. will let you know if it work out right..

@Ritikaa96
Copy link
Contributor

Hi @sftim I have written a shortcode for the <picture.. > it will look like this

{{< picture "light.svg" "dark.svg" "alt_text" >}}

where we mention the images to be used in the preferred mode.

are we looking for a similar solution?

@sftim
Copy link
Contributor Author

sftim commented Dec 1, 2022

I have written a shortcode for the <picture.. > it will look like this

{{< picture "light.svg" "dark.svg" "alt_text" >}}

where we mention the images to be used in the preferred mode.

I might call it {{< picture-light-and-dark "light.svg" "dark.svg" "alt_text" >}} so that people remember which order.
We could also make our own custom extension to https://gohugo.io/content-management/shortcodes/#figure

@sftim
Copy link
Contributor Author

sftim commented Dec 1, 2022

It'd be great to see a preview of the effect, even if it's only a draft.

@Ritikaa96
Copy link
Contributor

Ritikaa96 commented Dec 1, 2022

Sure let me confirm first , we are to add this change in : https://github.com/kubernetes/website/blob/main/content/en/_index.html
Right?

@sftim
Copy link
Contributor Author

sftim commented Feb 5, 2023

https://github.com/kubernetes/website/blob/main/content/en/_index.html is one of the places we might need to change

I think the CSS (and its SCSS source code) is more important though.

@sftim
Copy link
Contributor Author

sftim commented Feb 7, 2023

Please open a pull request to show the changes you're proposing. That's definitely the best way to collaborate here.

@Ritikaa96
Copy link
Contributor

Hi @sftim , I'll make a PR and update here then.

@coder12git
Copy link
Contributor

/assign

I am taking this, as i know how to implement this. I'll create a PR soon 🫡

@Ritikaa96 Ritikaa96 removed their assignment Dec 26, 2023
@sftim
Copy link
Contributor Author

sftim commented Feb 25, 2024

@coder12git how's this work going?

@coder12git
Copy link
Contributor

coder12git commented Feb 27, 2024

Change https://kubernetes.io/ (and only that page) to support detecting the viewer's preference for either light mode or dark mode, and then honoring it.
This should use a similar technique to https://opensource.com/article/21/10/dark-themes-websites and must also play well with our custom Docsy theme.

@sftim As mentioned here just to do this for only one page, but if i follow the other point, then when i am doing changes it's happening to all other pages, i.e not able to implement this only for one page.

@tamilselvan1102
Copy link

@coder12git
The layout is same for all the pages. so if you add dark mode toggle button in header (Documentation,Kubernetes Blog,Training, ...) it will reflect all the pages. But if we add small logic in javascript, it is possible.

@tamilselvan1102
Copy link

let me do the try
/assign

@sftim
Copy link
Contributor Author

sftim commented Feb 27, 2024

The layout is same for all the pages. so if you add dark mode toggle button in header (Documentation,Kubernetes Blog,Training, ...) it will reflect all the pages. But if we add small logic in javascript, it is possible.

I recommend using CSS. CSS is awesome 😉

See https://css-tricks.com/a-complete-guide-to-dark-mode-on-the-web/ for details, including approaches that don't require any JavaScript.

@sftim
Copy link
Contributor Author

sftim commented Feb 27, 2024

not able to implement this only for one page.

In CSS, we can use selectors to scope down our code to only apply to body.td-home.cid-home …; that should allow style changes to just the front page.

@tamilselvan1102
Copy link

i will use awesome icons

@sftim
Copy link
Contributor Author

sftim commented Aug 6, 2024

We discussed #45535 in today's SIG meeting.

@dipesh-rawat
Copy link
Member

In the long term, we might want to consider aligning with Docsy since it now supports Dark Mode (announcement here).

xref #25061 (comment)

Just cross-posting here for reference. The current progress on this issue is positive and looks great.

@Ant0wan
Copy link

Ant0wan commented Sep 16, 2024

Hi fellows,
Just for the curiosity - is there any ETA for this theme that will save my eyes ? :-)
Thanks for having done it ! See ya around at some kube conf'

@sftim
Copy link
Contributor Author

sftim commented Sep 17, 2024

ETA

No ETA I'm afraid. Most of the work on this website is done by volunteers.

@franciscojavierarceo
Copy link

Did @coder12git take this on?

@sftim
Copy link
Contributor Author

sftim commented Sep 28, 2024

Did @coder12git take this on?

The PR we have (which is ready for review) is by @tamilselvan1102

@sftim sftim linked a pull request Jan 28, 2025 that will close this issue
@sftim
Copy link
Contributor Author

sftim commented Jan 28, 2025

See #49586 for the latest PR (reviewable)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/web-development Issues or PRs related to the kubernetes.io's infrastructure, design, or build processes kind/feature Categorizes issue or PR as related to a new feature. priority/backlog Higher priority than priority/awaiting-more-evidence. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
9 participants