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

Content outside markdown-style doesn't adapt to dark/light mode changes #69

Closed
Regenhardt opened this issue May 22, 2023 · 11 comments
Closed

Comments

@Regenhardt
Copy link

When the system changes from light mode to dark mode, the markdown-style element correctly switches style too.

The body itself though does not. Neither does the dark mode switch, nor the github corner (although the github corner still kinda works in dark mode like this).

I see the dark mode switcher already switches CSS variables on the body and those are used in the markdown-style element, so maybe the dark mode switcher could hook into the system event to trigger the same function there, switching everything between modes, then the markdown-style element doesn't need the hook itself (unless there's other CSS in there I haven't seen, I'm not a web dev😅).

@jaywcjlove
Copy link
Owner

@Regenhardt Follow the system to switch between light and dark themes?

@Regenhardt
Copy link
Author

Yes the operating system or browser. If the browser is set to follow the OS, the website gets the theme change event when the device (I tried Windows and Android) changes theme. The markdown-style element hooks listens to the, the rest does not.

@Regenhardt
Copy link
Author

I'd try to do that myself but I don't understand how those html strings in the ts files work, they look jumbled already.

@jaywcjlove
Copy link
Owner

@Regenhardt

$ markdown-to-html-cli --dark-mode auto
$ markdown-to-html-cli --dark-mode auto --markdown-style-theme dark
$ markdown-to-html-cli --no-dark-mode --markdown-style-theme dark
$ markdown-to-html-cli --markdown-style-theme dark
- name: Converts Markdown to HTML
  uses: jaywcjlove/markdown-to-html-cli@main
  with:
    source: README-zh.md
    output: coverage/action.html
    dark-mode: auto
    markdown-style-theme: dark
    markdown-style: "max-width: 1260px"
    github-corners: https://github.com/jaywcjlove/markdown-to-html-cli

@Regenhardt
Copy link
Author

Here's an example. I made a simple page (with --dark-mode auto) and visited it in light mode:

grafik

Now I change my PC to dark mode:

grafik

and this happens:

grafik

As you can see, the content (<markdown-style>) switches theme, the rest does not.

@jaywcjlove
Copy link
Owner

$ markdown-to-html-cli --dark-mode auto --markdown-style-theme light --no-corners

@Regenhardt I used the above command to generate the page and found no problems.

image

@Regenhardt
Copy link
Author

Ok so I did some tests and apparently this only happens when called from my custom domain (https://regenhardt.dev), but it works fine when called directly (https://regenhardt.gitlab.io). Any idea how that is possible? The custom domain literally routes to the same server as the gitlab.io domain.

@jaywcjlove
Copy link
Owner

@Regenhardt Both pages work fine on my computer. I guess it might be a browser cache issue.

@Regenhardt
Copy link
Author

Even without caching this happens. But I found out so far it only happens if I use the custom domain and only in Firefox.
As far as I can see, the only difference in the html is that the dark-mode node has another attribute permanent="" when called via the custom domain in Firefox, but I can't figure out why. It's literally the same code. There's no error in the Firefox browser console either.

Do you have an idea what else I could check or try? I'm not sure where to go from here since the permanent attribute seems to come from some js/ts code somewhere, which is jumbled to me.

@jaywcjlove
Copy link
Owner

permanent for local storage, remembers the currently selected theme. With the --dark-mode auto option, no theme selection records will be stored.
@Regenhardt

@Regenhardt
Copy link
Author

Ok I found it: Firefox still had the theme saved in local storage, so I guess that triggered part of the website keeping the theme even after reloading with clear cache. After emptying local storage for the custom domain, it now also automatically changes as a whole. Thanks for the help!

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

No branches or pull requests

2 participants