fix: resize og:image
All checks were successful
Deploy workflow / deploy (push) Successful in 36s

This commit is contained in:
Matthieu Bessat 2024-05-07 19:02:32 +02:00
parent 5171bcfdf2
commit 89e6e5f8db
2 changed files with 4 additions and 10 deletions

View file

@ -13,19 +13,14 @@
<!-- Is an external image --> <!-- Is an external image -->
{{ $result = merge $result (dict "permalink" $imageValue) }} {{ $result = merge $result (dict "permalink" $imageValue) }}
{{ else }} {{ else }}
{{ $pageResourceImage := resources.GetMatch (printf "%s" ($imageValue | safeURL)) }} {{ $pageResourceImage := (.Context.Resources.GetMatch ($imageValue | safeURL)).Fill "300x300 center" }}
{{ if $pageResourceImage }} {{ if $pageResourceImage }}
<!-- If image is found under page bundle --> <!-- If image is found under page bundle -->
{{ $result = merge $result (dict "permalink" $pageResourceImage.RelPermalink) }} {{ $result = merge $result (dict "permalink" $pageResourceImage.RelPermalink) }}
<!-- Disable SVG image processing, not supported by Hugo -->
{{ if ne (path.Ext $imageValue) ".svg" }}
{{ $result = merge $result (dict "resource" $pageResourceImage) }}
{{ end }}
{{ else }} {{ else }}
<!-- Can not find the image under page bundle. Could be a relative linked image --> <!-- Can not find the image under page bundle. Could be a relative linked image -->
{{ $result = merge $result (dict "permalink" (relURL $imageValue)) }} {{ $result = merge $result (dict "permalink" (printf "%s" (relURL $imageValue))) }}
{{ end }} {{ end }}
{{ end }} {{ end }}
@ -42,8 +37,7 @@
{{ if $siteResourceImage }} {{ if $siteResourceImage }}
<!-- Try search image under site's assets folder --> <!-- Try search image under site's assets folder -->
{{ $result = merge $result (dict "permalink" $siteResourceImage.RelPermalink) }} {{ $result = merge $result (dict "permalink" ($siteResourceImage.Fill "300x300 center").RelPermalink) }}
{{ $result = merge $result (dict "resource" $siteResourceImage) }}
{{ else }} {{ else }}
<!-- Can not find the image --> <!-- Can not find the image -->
{{ errorf "Failed loading image: %q" $defaultImageSetting.src }} {{ errorf "Failed loading image: %q" $defaultImageSetting.src }}

View file

@ -39,6 +39,6 @@
{{ $image := partial "helpers/image" (dict "Context" . "Type" "opengraph") .RelPermalink "opengraph" }} {{ $image := partial "helpers/image" (dict "Context" . "Type" "opengraph") .RelPermalink "opengraph" }}
{{ if $image.exists }} {{ if $image.exists }}
<meta property="og:image" content="{{ absURL $image.permalink }}" /> <meta property="og:image" content="{{ $image.permalink }}" />
{{- end -}} {{- end -}}