From da18fe3b68c9d40fb3f4b8bf95432c36b67aa71c Mon Sep 17 00:00:00 2001 From: Matthieu Bessat Date: Tue, 7 May 2024 19:02:32 +0200 Subject: [PATCH] fix: resize og:image --- layouts/partials/helpers/image.html | 12 +++--------- layouts/partials/opengraph/include.html | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/layouts/partials/helpers/image.html b/layouts/partials/helpers/image.html index 2fc3c92..ed43ed5 100644 --- a/layouts/partials/helpers/image.html +++ b/layouts/partials/helpers/image.html @@ -13,19 +13,14 @@ {{ $result = merge $result (dict "permalink" $imageValue) }} {{ else }} - {{ $pageResourceImage := resources.GetMatch (printf "%s" ($imageValue | safeURL)) }} + {{ $pageResourceImage := (.Context.Resources.GetMatch ($imageValue | safeURL)).Fill "300x300 center" }} {{ if $pageResourceImage }} {{ $result = merge $result (dict "permalink" $pageResourceImage.RelPermalink) }} - - - {{ if ne (path.Ext $imageValue) ".svg" }} - {{ $result = merge $result (dict "resource" $pageResourceImage) }} - {{ end }} {{ else }} - {{ $result = merge $result (dict "permalink" (relURL $imageValue)) }} + {{ $result = merge $result (dict "permalink" (printf "%s" (relURL $imageValue))) }} {{ end }} {{ end }} @@ -42,8 +37,7 @@ {{ if $siteResourceImage }} - {{ $result = merge $result (dict "permalink" $siteResourceImage.RelPermalink) }} - {{ $result = merge $result (dict "resource" $siteResourceImage) }} + {{ $result = merge $result (dict "permalink" ($siteResourceImage.Fill "300x300 center").RelPermalink) }} {{ else }} {{ errorf "Failed loading image: %q" $defaultImageSetting.src }} diff --git a/layouts/partials/opengraph/include.html b/layouts/partials/opengraph/include.html index 743fb76..7ce8cf5 100644 --- a/layouts/partials/opengraph/include.html +++ b/layouts/partials/opengraph/include.html @@ -39,6 +39,6 @@ {{ $image := partial "helpers/image" (dict "Context" . "Type" "opengraph") .RelPermalink "opengraph" }} {{ if $image.exists }} - + {{- end -}}