fix-featimage-ratio (#127)

fix #10

Reviewed-on: #127
Co-authored-by: paspo <paolo@asperti.com>
Co-committed-by: paspo <paolo@asperti.com>
This commit is contained in:
Paolo Asperti 2024-07-17 21:37:18 +00:00 committed by Paolo Asperti
parent f8bb05f12e
commit 0603f5df69
3 changed files with 10 additions and 8 deletions

View File

@ -39,7 +39,3 @@
padding-right: 1em;
font-size: 1rem;
}
#content article img {
width: 100%;
}

View File

@ -3,7 +3,11 @@
{{- if not $u.IsAbs -}}
{{- $path := strings.TrimPrefix "./" $u.Path }}
{{- with or (.PageInner.Resources.Get $path) (resources.Get $path) -}}
{{- $src = (.Resize "1400x jpg q50").RelPermalink -}}
{{- if gt .Width 1400 -}}
{{- $src = (.Resize "1400x webp q50").RelPermalink -}}
{{- else -}}
{{- $src = (.Process "webp q50").RelPermalink -}}
{{- end -}}
{{- with $u.RawQuery -}}
{{- $src = printf "%s?%s" $src . -}}
{{- end -}}

View File

@ -26,10 +26,12 @@
<span class="image featured">
{{- if in $rasters $img.MediaType.SubType -}}
{{- $img = $img.Resize (printf "x%d" $maxHeight) -}}
<img src="{{ $img.RelPermalink }}" alt="{{ .Params.image_alt }}" style="max-height: {{ $maxHeight }}px;" />
{{- if gt $img.Height $maxHeight -}}
{{- $img = $img.Resize (printf "x%d webp q50" $maxHeight) -}}
{{- end -}}
<img src="{{ $img.RelPermalink }}" alt="{{ .Params.image_alt }}" {{- if gt $img.Height $img.Width -}}style="width: auto;"{{- end -}} />
{{ else }}
<img src="{{ $img.RelPermalink }}" alt="{{ .Params.image_alt }}" style="max-height: {{ $maxHeight }}px;" />
<img src="{{ $img.RelPermalink }}" alt="{{ .Params.image_alt }}" />
{{ end }}
</span>
{{ end }}