fix: ensure default image for og and twitter cards

Updated the HTML partial to use a default image when `.Params.image` is undefined, improving robustness of Open Graph and Twitter card metadata. This ensures consistent presentation of content across social media, preventing missing image issues when a custom image is not provided.
This commit is contained in:
Kumi 2024-11-09 16:02:35 +01:00
parent ebef29ce3d
commit 381922076f
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -8,13 +8,21 @@
{{ $css := $style | minify | fingerprint }} {{ $css := $style | minify | fingerprint }}
<link rel="stylesheet" href="{{ $css.RelPermalink }}"> <link rel="stylesheet" href="{{ $css.RelPermalink }}">
{{ $image := "" }}
{{ if .Params.image }}
{{ $image = .Params.image }}
{{ else }}
{{ $image = resources.Get "images/profile.jpg" }}
{{ end }}
<meta property="og:title" content="{{ .Title }}"> <meta property="og:title" content="{{ .Title }}">
<meta property="og:description" content="{{ .Description }}"> <meta property="og:description" content="{{ .Description }}">
<meta property="og:type" content="article"> <meta property="og:type" content="article">
<meta property="og:url" content="{{ .Permalink }}"> <meta property="og:url" content="{{ .Permalink }}">
<meta property="og:image" content="{{ .Site.BaseURL }}{{ .Params.image }}"> <meta property="og:image" content="{{ .Site.BaseURL }}{{ $image }}">
<meta name="twitter:card" content="summary_large_image"> <meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="{{ .Title }}"> <meta name="twitter:title" content="{{ .Title }}">
<meta name="twitter:description" content="{{ .Description }}"> <meta name="twitter:description" content="{{ .Description }}">
<meta name="twitter:image" content="{{ .Site.BaseURL }}{{ .Params.image }}"> <meta name="twitter:image" content="{{ .Site.BaseURL }}{{ $image }}">
</head> </head>