feat: add defaultSocialImage (#1491) (#2100)

Add `defaultSocialImage` as the default image for social media sharing. This feature would be useful for users who don’t want to specify an image for every article. This PR also resolves the issue where the homepage missing an image when shared.
This commit is contained in:
ZhenShuo Leo
2025-05-03 02:59:33 +08:00
parent 1d21656d5e
commit e4b76d6fce
6 changed files with 13 additions and 0 deletions

View File

@@ -107,6 +107,14 @@
{{/* Social */}}
{{ template "_internal/opengraph.html" . }}
{{ template "_internal/twitter_cards.html" . }}
{{- /* Image for both main page and backoff if not `*feature*` image found */ -}}
{{- /* See https://gohugo.io/templates/embedded/#open-graph */ -}}
{{ if not ($.Resources.GetMatch "*feature*") }}
{{ with .Site.Params.defaultSocialImage }}
<meta name="twitter:image" content="{{ . | absURL }}" />
<meta property="og:image" content="{{ . | absURL }}" />
{{ end }}
{{ end }}
{{/* Schema */}}
{{ partial "schema.html" . }}
{{/* Me */}}