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

Add support for dark mode images via JS #153

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

astroDimitrios
Copy link
Contributor

@astroDimitrios astroDimitrios commented Oct 29, 2024

Adds support for dark mode images via JS. No change is required on the end user.

The JS alters the image src to add -dark before the extension. For example:

  • test.png in light mode
  • test-dark.png in dark mode

If there is no dark mode image in the same location as the light mode version the fallback is the light mode image. There doesn't seem to be a clean way to test if a file exists and handle the responses well (unless someone else can point me to some nice JS!) so the dev console in firefox/chrome etc. will throw 404 errors when it attempts to load dark mode images that aren't available (only when choosing to switch from light to dark mode). There might be ways of suppressing the errors but these seem convoluted.

If the fallback light image is used in dark mode the img.dark-filter css rule is applied which inverts the image, and slightly reduces the saturation and brightness.

Example

git-novice lesson where the top comic strip image has a fuzzy dark mode variant for demonstration purposes.

Light Mode User Supplied Image:
image

Dark Mode User Supplied Image:
image

Light Mode SVG:
image

Dark Mode SVG - fallback to light with dark-filter:
image

Light Mode PNG:
image

Dark Mode PNG - fallback to light with dark-filter:
image

Related Issues

carpentries/instructor-training#1715
#150

@astroDimitrios astroDimitrios marked this pull request as draft October 29, 2024 19:30
@astroDimitrios astroDimitrios marked this pull request as ready for review October 29, 2024 19:40
…cific. Remove the https check at the start of an image source otherwise image sources are not modified.
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.

1 participant