Skip to content

Allow dark/light theme switch on user browser #2900

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 2 commits into from
Mar 16, 2025

Conversation

SijieFu
Copy link
Contributor

@SijieFu SijieFu commented Mar 13, 2025

  1. New fearture: dark/light theme toggle on the webpage with user preference. Solves toggle between dark and light mode #911.
    • html[data-theme="dark"] selector to overwrite default light theme variables.
    • localStorage to store user preference of the theme. This is for theme consistency. User preference overwrites the default theme at compile.
  2. Fix: Navigation text overflow and wide empty spaces on mobile screens (or width-limited screens).
    • Deprecated $masthead-height to position the sidebar and the main body below the navbar. When the site title is long, this causes overflow to the fixed height. $masthead-height definition is still kept as a backup.
    • The navbar height is set to fit-content and the padding-top for the sidebar and the main body is updated together with updateNav() function.
    • Minor updates to related padding/margin to fix large empty spaces.

@rjzupkoii
Copy link
Collaborator

Thanks for the pull request and hard work to get this running!

@rjzupkoii rjzupkoii merged commit 89773fc into academicpages:master Mar 16, 2025
Tatwik19 pushed a commit to Tatwik19/Tatwik19.github.io that referenced this pull request Mar 19, 2025
Allow dark/light theme switch on user browser
georgiagracetully pushed a commit to georgiagracetully/georgiagracetully.github.io that referenced this pull request May 1, 2025
Allow dark/light theme switch on user browser
KYang-N added a commit to KYang-N/KYang-N.github.io that referenced this pull request Jul 14, 2025
@Gabri110
Copy link
Contributor

Gabri110 commented Aug 4, 2025

First of all, I want to say that I love this feature! But I have a doubt: is this PR compatible with having different themes?

I have been trying to create a new file in _sass/theme/ and importing it in assets/css/main.scss, but I can't make it work. The only workaround that I have found is to directly modify the colours in the _default.scss and _dark.scss files directly. Do you know if there is another way around this?

@rjzupkoii
Copy link
Collaborator

@Gabri110 This might be better as a thread over on discussions but I think it depends if you have the updated version with all of the changes to _sass or not. That was laid out with the assumption that there can be more than just two themes (i.e., light and dark) but I just didn't implement all of the logic to select between them since we only have the two themes so far.

@Gabri110
Copy link
Contributor

Gabri110 commented Aug 4, 2025

@rjzupkoii I am working from the last release. I have opened the discussion #3235 ;)

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.

3 participants