fix: resize og:image

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

View file

@ -13,19 +13,14 @@
<!-- Is an external image -->
{{ $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 }}
<!-- If image is found under page bundle -->
{{ $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 }}
<!-- 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 }}
@ -42,8 +37,7 @@
{{ if $siteResourceImage }}
<!-- Try search image under site's assets folder -->
{{ $result = merge $result (dict "permalink" $siteResourceImage.RelPermalink) }}
{{ $result = merge $result (dict "resource" $siteResourceImage) }}
{{ $result = merge $result (dict "permalink" ($siteResourceImage.Fill "300x300 center").RelPermalink) }}
{{ else }}
<!-- Can not find the image -->
{{ errorf "Failed loading image: %q" $defaultImageSetting.src }}

View file

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