-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add media querys to markdown images
Signed-off-by: lennartrommeiss <lennart.rommeiss@deutschebahn.com>
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
themes/fiptheme/layouts/_default/_markup/render-image.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{{ $myTitle := .Title | default (i18n "image not found") }} | ||
|
||
{{/* Prüfen, ob .Destination (also die Bildquelle) mit http:// oder https:// beginnt */}} | ||
{{ if and .Destination (or (strings.HasPrefix .Destination "http://") (strings.HasPrefix .Destination "https://")) }} | ||
<!-- Remote Bild: Direkt ausgeben ohne Bildverarbeitung --> | ||
{{ $remoteImage := resources.GetRemote .Destination }} | ||
<p class="md-image"> | ||
<img src="{{ $remoteImage.Permalink }}" alt="{{ .Title }}" title="{{ .Title }}" /> | ||
</p> | ||
{{ else }} | ||
{{/* Lokales Bild: Mit Bildverarbeitung */}} | ||
{{ $originalImage := resources.Get "images/glider.png" }} | ||
{{ with .Destination }} | ||
{{ $myTitle = $.Title }} | ||
<!-- Zunächst im Seitenkontext nach Ressourcen suchen --> | ||
{{ with $.Page.Resources.Get . }} | ||
{{ $originalImage = . }} | ||
{{ else }} | ||
<!-- Dann in den statischen Ressourcen suchen --> | ||
{{ with resources.Get . }} | ||
{{ $originalImage = . }} | ||
{{ end }} | ||
{{ end }} | ||
{{ end }} | ||
|
||
<p class="md-image"> | ||
<picture> | ||
{{ $width := $originalImage.Width }} | ||
|
||
{{ if gt $width 2200 }} | ||
{{ with $originalImage.Resize "2200x" }} | ||
<source media="(min-width:2200px)" srcset="{{ .RelPermalink | safeURL }}" /> | ||
{{ end }} | ||
{{ end }} | ||
|
||
{{ if gt $width 1500 }} | ||
{{ with $originalImage.Resize "1500x" }} | ||
<source media="(min-width:1500px)" srcset="{{ .RelPermalink | safeURL }}" /> | ||
{{ end }} | ||
{{ end }} | ||
|
||
{{ if gt $width 1200 }} | ||
{{ with $originalImage.Resize "1200x" }} | ||
<source media="(min-width:1200px)" srcset="{{ .RelPermalink | safeURL }}" /> | ||
{{ end }} | ||
{{ end }} | ||
|
||
{{ if gt $width 800 }} | ||
{{ with $originalImage.Resize "800x" }} | ||
<source media="(min-width:800px)" srcset="{{ .RelPermalink | safeURL }}" /> | ||
{{ end }} | ||
{{ end }} | ||
|
||
{{ $tinyImage := $originalImage }} | ||
{{ if gt $width 500 }} | ||
{{ $tinyImage = $originalImage.Resize "500x" }} | ||
{{ end }} | ||
<img src="{{ $tinyImage.RelPermalink | safeURL }}" alt="{{ $myTitle }}" title="{{ $myTitle }}" /> | ||
</picture> | ||
</p> | ||
{{ end }} |