From e9edfa8f1c56d0014dd29ac8ed6e122a01b3f845 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Wed, 18 Jun 2025 19:18:21 +0800 Subject: [PATCH] feat: support all types of sources for defaultSocialImage --- layouts/partials/head.html | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 424f8c98..ca9e70b3 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -109,12 +109,25 @@ {{ template "_internal/twitter_cards.html" . }} {{- /* Main page always uses this; fallback elsewhere if no feature image */ -}} {{- /* See https://gohugo.io/templates/embedded/#open-graph */ -}} - {{ if not ($.Resources.GetMatch "*feature*") }} - {{ with .Site.Params.defaultSocialImage }} - - - {{ end }} - {{ end }} + + {{- $images := .Resources.ByType "image" -}} + {{- $socialImage := $images.GetMatch "*feature*" -}} + + {{- if not $socialImage -}} + {{- with .Site.Params.defaultSocialImage -}} + {{- if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") -}} + {{- $socialImage = resources.GetRemote . -}} + {{- else -}} + {{- $socialImage = resources.Get . -}} + {{- end -}} + {{- end -}} + {{- end -}} + + {{- with $socialImage -}} + + + {{- end -}} + {{/* Schema */}} {{ partial "schema.html" . }} {{/* Me */}}