Skip to content

Commit

Permalink
✨ feat: add dual image support for switching themes
Browse files Browse the repository at this point in the history
  • Loading branch information
welpo committed Feb 25, 2023
1 parent 1496f0c commit b3dc539
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
13 changes: 12 additions & 1 deletion content/shortcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@ tags = ["showcase", "shortcodes"]

## Image shortcodes

### Dual theme images

Useful if you want to use a different image for the light and dark themes:

{{ dual_theme_image(light_src="$BASE_URL/img/paris_day.webp", dark_src="$BASE_URL/img/paris_night.webp" alt="The Eiffel tower") }}

Usage:
```
{{/* dual_theme_image(light_src="$BASE_URL/img/paris_day.webp", dark_src="$BASE_URL/img/paris_night.webp" alt="The Eiffel tower") */}}
```

### Invertible image

You can use this shortcode for graphs, line drawings, diagrams…
Good for graphs, line drawings, diagrams… Inverts the colours of the image. The source image will be used for the light theme.

{{ invertible_image(src="$BASE_URL/img/graph.webp", alt="Invertible graph") }}

Expand Down
13 changes: 13 additions & 0 deletions sass/parts/_image.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,16 @@ figure h4::before {
svg {
max-height: 15px;
}

.img-dark {
display: none;
}

[data-theme="dark"] {
.img-dark {
display: block;
}
.img-light {
display: none;
}
}
Binary file added static/img/paris_day.webp
Binary file not shown.
Binary file added static/img/paris_night.webp
Binary file not shown.
2 changes: 2 additions & 0 deletions templates/shortcodes/dual_theme_image.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<img src="{{ light_src | safe | replace(from="$BASE_URL" , to=config.base_url) }}" {% if alt %}alt="{{ alt }}" {% endif %} class="img-light">
<img src="{{ dark_src | safe | replace(from="$BASE_URL" , to=config.base_url) }}" {% if alt %}alt="{{ alt }}" {% endif %} class="img-dark">

0 comments on commit b3dc539

Please sign in to comment.