+ {{ if $image.resource }}
+ {{- $imageRaw := $image.resource | resources.Fingerprint "md5" -}}
+ {{- $thumbnail := $imageRaw.Fill .size -}}
+
+
+ {{ else }}
+
+ {{ end }}
+
{{ end }}
diff --git a/layouts/partials/article/components/details.html b/layouts/partials/article/components/details.html
index 4349d61..0a8f777 100644
--- a/layouts/partials/article/components/details.html
+++ b/layouts/partials/article/components/details.html
@@ -1,15 +1,14 @@
-{{ $i := .Params.image }}
+{{ $image := partial "helper/image" (dict "Context" .) }}
{{ $context := . }}
-
{{ with $categories := .Params.categories }}
{{ range $categories }}
- {{ if $i }}
- {{- $image := partial "helper/image" $context | resources.Fingerprint "md5" -}}
- {{- $20x := $image.Fill "20x20 smart" -}}
+ {{ if and $image.exists $image.resource }}
+ {{- $imageRaw := $image.resource | resources.Fingerprint "md5" -}}
+ {{- $20x := $imageRaw.Fill "20x20 smart" -}}
{{ . | humanize }}
+ data-image="{{ $20x.RelPermalink }}" data-key="{{ $context.Slug }}" data-hash="{{ $imageRaw.Data.Integrity }}">{{ . | humanize }}
{{ else }}
{{ . | humanize }}
{{ end }}
diff --git a/layouts/partials/article/components/header.html b/layouts/partials/article/components/header.html
index 1bd5663..df7c764 100644
--- a/layouts/partials/article/components/header.html
+++ b/layouts/partials/article/components/header.html
@@ -1,16 +1,19 @@
- {{ if .Params.image }}
- {{- $image := partial "helper/image" . -}}
+ {{ $image := partial "helper/image" (dict "Context" . "Type" "article") }}
- {{- $tablet := $image.Resize "1024x" -}}
- {{- $desktop := $image.Resize "2000x" -}}
+ {{ if $image.exists }}
+
+ {{ if $image.resource }}
+ {{- $tablet := $image.resource.Resize "1024x" -}}
+ {{- $desktop := $image.resource.Resize "2000x" -}}
-
-
-
+
+ {{ else }}
+
+ {{ end }}
+
{{ end }}
{{ partial "article/components/details" . }}
diff --git a/layouts/partials/head/opengraph.html b/layouts/partials/head/opengraph.html
index dd298c2..9410693 100644
--- a/layouts/partials/head/opengraph.html
+++ b/layouts/partials/head/opengraph.html
@@ -40,13 +40,9 @@
{{- end -}}
{{- end -}}
-{{- if .Params.image -}}
- {{ $image := partial "helper/image" . }}
+{{ $image := partial "helper/image" (dict "Context" . "Type" "opengraph") }}
+{{- if $image.exists -}}
-
-
-{{- else if .Site.Params.opengraph.defaultImage -}}
- {{ $image := resources.Get .Site.Params.opengraph.defaultImage }}
-
-
+
+
{{- end -}}
\ No newline at end of file
diff --git a/layouts/partials/helper/image.html b/layouts/partials/helper/image.html
index 308a36c..5276f2e 100644
--- a/layouts/partials/helper/image.html
+++ b/layouts/partials/helper/image.html
@@ -1,2 +1,63 @@
-{{- $image := .Resources.GetMatch (printf "%s" (.Params.image | safeURL)) -}}
-{{ return $image }}
\ No newline at end of file
+{{ $result := dict "exists" false "permalink" nil "resource" nil "isDefault" false }}
+{{ $imageField := default "image" .Context.Site.Params.featuredImageField }}
+{{ $imageValue := index .Context.Params $imageField }}
+
+{{ if $imageValue }}
+
+ {{ $result = merge $result (dict "exists" true) }}
+ {{ $url := urls.Parse $imageValue }}
+
+ {{ if or (eq $url.Scheme "http") (eq $url.Scheme "https") }}
+
+ {{ $result = merge $result (dict "permalink" $imageValue) }}
+ {{ else }}
+ {{ $pageResourceImage := .Context.Resources.GetMatch (printf "%s" ($imageValue | safeURL)) }}
+ {{ $siteResourceImage := resources.GetMatch (printf "%s" ($imageValue | safeURL)) }}
+
+ {{ if $pageResourceImage }}
+
+ {{ $result = merge $result (dict "permalink" $pageResourceImage.RelPermalink) }}
+ {{ $result = merge $result (dict "resource" $pageResourceImage) }}
+ {{ else if $siteResourceImage }}
+
+ {{ $result = merge $result (dict "permalink" $siteResourceImage.RelPermalink) }}
+ {{ $result = merge $result (dict "resource" $siteResourceImage) }}
+ {{ else }}
+
+ {{ errorf "Failed loading image: %q" $imageValue }}
+ {{ $result = merge $result (dict "exists" false) }}
+ {{ end }}
+
+ {{ end }}
+
+{{ else if and (ne .Type nil) (index .Context.Site.Params.defaultImage .Type) }}
+
+ {{ $defaultImageSetting := index .Context.Site.Params.defaultImage .Type }}
+
+ {{ if $defaultImageSetting.enabled }}
+ {{ $result = merge $result (dict "isDefault" true) }}
+ {{ $result = merge $result (dict "exists" true) }}
+
+ {{ if $defaultImageSetting.local }}
+ {{ $siteResourceImage := resources.GetMatch (printf "%s" ($defaultImageSetting.src | safeURL)) }}
+
+ {{ if $siteResourceImage }}
+
+ {{ $result = merge $result (dict "permalink" $siteResourceImage.RelPermalink) }}
+ {{ $result = merge $result (dict "resource" $siteResourceImage) }}
+ {{ else }}
+
+ {{ errorf "Failed loading image: %q" $defaultImageSetting.src }}
+ {{ $result = merge $result (dict "exists" false) }}
+ {{ end }}
+
+ {{ else }}
+
+ {{ $result = merge $result (dict "permalink" $defaultImageSetting.src) }}
+ {{ end }}
+
+ {{ end }}
+
+{{ end }}
+
+{{ return $result }}
\ No newline at end of file