feat: responsive avatar image size

This commit is contained in:
xiaoxiyao 2024-09-23 22:14:25 +08:00
parent 2a18a92901
commit 8bb7025940

View file

@ -16,9 +16,20 @@
{{ $avatar := resources.Get (.src) }} {{ $avatar := resources.Get (.src) }}
{{ if $avatar }} {{ if $avatar }}
{{ $avatarResized := $avatar.Resize "300x" }} {{ $avatarResized := $avatar.Resize "120x" }}
<img src="{{ $avatarResized.RelPermalink }}" width="{{ $avatarResized.Width }}" {{ $avatar1_5 := $avatar.Resize "180x" }}
height="{{ $avatarResized.Height }}" class="site-logo" loading="lazy" alt="Avatar"> {{ $avatar2 := $avatar.Resize "240x" }}
<img
src="{{ $avatarResized.RelPermalink }}"
srcset="{{$avatarResized.RelPermalink}},
{{$avatar1_5.RelPermalink}} 1.5x,
{{$avatar2.RelPermalink}} 2x"
width="{{ $avatarResized.Width }}"
height="{{ $avatarResized.Height }}"
class="site-logo"
loading="lazy"
alt="Avatar"
/>
{{ else }} {{ else }}
{{ errorf "Failed loading avatar from %q" . }} {{ errorf "Failed loading avatar from %q" . }}
{{ end }} {{ end }}