From 374a0f51f71dc6e324bac23a1d3d7f930cc5825f Mon Sep 17 00:00:00 2001
From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com>
Date: Wed, 1 Oct 2025 13:44:02 +0800
Subject: [PATCH] fix(head): social image meta duplication
---
layouts/partials/head.html | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 3ca809de..07b9dd1f 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -54,24 +54,28 @@
{{/* Social */}}
{{ template "_internal/opengraph.html" . }}
{{ template "_internal/twitter_cards.html" . }}
-
- {{/* Main page always uses this; fallback elsewhere if no feature image */}}
- {{/* See https://gohugo.io/templates/embedded/#open-graph */}}
- {{ $images := .Resources.ByType "image" }}
- {{ $socialImage := $images.GetMatch "*feature*" }}
- {{ if not $socialImage }}
+ {{/* Use defaultSocialImage if feature image does not exist */}}
+ {{ $featureImage := "" }}
+ {{ $pageImages := .Resources.ByType "image" }}
+ {{ range slice "*featured*" "*cover*" "*thumbnail*" }}
+ {{ if not $featureImage }}
+ {{ $featureImage = $pageImages.GetMatch . }}
+ {{ end }}
+ {{ end }}
+ {{ if not $featureImage }}
{{ with .Site.Params.defaultSocialImage }}
+ {{ $socialImage := "" }}
{{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }}
{{ $socialImage = resources.GetRemote . }}
{{ else }}
{{ $socialImage = resources.Get . }}
{{ end }}
+ {{ with $socialImage }}
+
+
+ {{ end }}
{{ end }}
{{ end }}
- {{ with $socialImage }}
-
-
- {{ end }}
{{/* Site Verification */}}
{{ with .Site.Params.verification.google }}