feat(helper/image): new return format

This commit is contained in:
Jimmy Cai
2020-09-11 16:01:01 +02:00
parent 3e18e165e0
commit cfd4cdb731
8 changed files with 30 additions and 35 deletions
@@ -4,8 +4,8 @@
{{ with $categories := .Params.categories }}
<header class="article-category">
{{ range $categories }}
{{ if and $image.exists $image.local }}
{{- $imageRaw := $image.src | resources.Fingerprint "md5" -}}
{{ if and $image.exists $image.resource }}
{{- $imageRaw := $image.resource | resources.Fingerprint "md5" -}}
{{- $20x := $imageRaw.Fill "20x20 smart" -}}
<a href="/categories/{{ . | urlize }}" class="color-tag"
data-image="{{ $20x.RelPermalink }}" data-key="{{ $context.Slug }}" data-hash="{{ $imageRaw.Data.Integrity }}">{{ . | humanize }}</a>
@@ -3,15 +3,15 @@
{{ if $image.exists }}
<div class="article-image">
{{ if $image.local }}
{{- $tablet := $image.src.Resize "1024x" -}}
{{- $desktop := $image.src.Resize "2000x" -}}
{{ if $image.resource }}
{{- $tablet := $image.resource.Resize "1024x" -}}
{{- $desktop := $image.resource.Resize "2000x" -}}
<img srcset="{{ $tablet.RelPermalink }} 1024w, {{ $desktop.RelPermalink }} 2000w"
src="{{ $desktop.RelPermalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}" loading="lazy"
src="{{ $desktop.RelPermalink }}" width="{{ $image.resource.Width }}" height="{{ $image.resource.Height }}" loading="lazy"
alt="Featured image of post {{ .Title }}" />
{{ else }}
<img src="{{ $image.src }}" loading="lazy" alt="Featured image of post {{ .Title }}" />
<img src="{{ $image.permalink }}" loading="lazy" alt="Featured image of post {{ .Title }}" />
{{ end }}
</div>
{{ end }}