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

inline svg images to fix darkmode in darkreader browser extension #487

Open
milahu opened this issue Sep 26, 2022 · 1 comment
Open

inline svg images to fix darkmode in darkreader browser extension #487

milahu opened this issue Sep 26, 2022 · 1 comment

Comments

@milahu
Copy link

milahu commented Sep 26, 2022

with darkreader, the svg images become invisible (black on black)

actual

<img src="/svg/toc.svg" class="book-icon" alt="Table of Contents">

expected: svg images are inlined. done in my fork milahu@39517ea

<svg class="book-icon" alt="Table of Contents" viewBox="...">
  <!-- ... -->
</svg>

the svg's have just a few bytes

$ du -b static/svg/*
248     static/svg/calendar.svg
287     static/svg/edit.svg
185     static/svg/menu.svg
228     static/svg/toc.svg
434     static/svg/translate.svg

also set fill="black" on the svg paths

also use transparent grey, like in 0c59cb3

to inline svg's

{{ readFile "/static/img/filename.svg" | safeHTML }}

gohugoio/hugo#10330

@milahu milahu changed the title inline svg images to fix dark mode in darkreader browser extension inline svg images to fix darkmode in darkreader browser extension Sep 26, 2022
@milahu
Copy link
Author

milahu commented Sep 29, 2022

alternative: css filter invert

<img class="darkmode-invert" src="path/to/image.svg">
/* light mode */
:root { --fg: black; --bg: white; }

/* dark mode */
@media screen {
  @media (prefers-color-scheme: dark) { 
    :root { --fg: white; --bg: black; } 
    .darkmode-invert {
      filter: invert();
    }
  }
  /* darkreader extension */
  :root[data-darkreader-mode="dynamic"] {
    --fg: white; --bg: black;
  }
  :root[data-darkreader-mode="dynamic"] .darkmode-invert {
    filter: invert();
  }
}

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

1 participant