feat(helper/image): new image helper (WIP)

This commit is contained in:
Jimmy Cai
2020-09-10 18:53:36 +02:00
parent 62b0da64df
commit 28c06ef8ae
7 changed files with 100 additions and 49 deletions
+13 -10
View File
@@ -1,16 +1,19 @@
<header class="article-header">
{{ if .Params.image }}
{{- $image := partial "helper/image" . -}}
{{ $image := partial "helper/image" . }}
{{- $tablet := $image.Resize "1024x" -}}
{{- $desktop := $image.Resize "2000x" -}}
{{ if $image.exists }}
<div class="article-image">
{{ if $image.local }}
{{- $tablet := $image.src.Resize "1024x" -}}
{{- $desktop := $image.src.Resize "2000x" -}}
<div class="article-image">
<img srcset="{{ $tablet.RelPermalink }} 1024w, {{ $desktop.RelPermalink }} 2000w"
src="{{ $desktop.RelPermalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}"
loading="lazy"
alt="Featured image of post {{ .Title }}" />
</div>
<img srcset="{{ $tablet.RelPermalink }} 1024w, {{ $desktop.RelPermalink }} 2000w"
src="{{ $desktop.RelPermalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}" loading="lazy"
alt="Featured image of post {{ .Title }}" />
{{ else }}
<img src="{{ $image.src }}" loading="lazy" alt="Featured image of post {{ .Title }}" />
{{ end }}
</div>
{{ end }}
{{ partial "article/components/details" . }}