|
54 | 54 | {{ $desc = $superuser_role }} |
55 | 55 | {{ end }} |
56 | 56 | <meta name="description" content='{{ printf "%.254s" $desc }}'> |
| 57 | + {{/* Shorter description for social previews (avoids mid-word truncation). */}} |
| 58 | + {{ $og_desc := "" }} |
| 59 | + {{ if .Params.sharing_description }} |
| 60 | + {{ $og_desc = .Params.sharing_description }} |
| 61 | + {{ else if .Params.og_description }} |
| 62 | + {{ $og_desc = .Params.og_description }} |
| 63 | + {{ else }} |
| 64 | + {{ $og_desc = printf "%.200s" $desc }} |
| 65 | + {{ end }} |
57 | 66 |
|
58 | 67 | {{ range .Translations }} |
59 | 68 | <link rel="alternate" hreflang="{{ .Lang }}" href="{{ .Permalink }}"> |
|
186 | 195 | {{ $avatar_image := (.Resources.ByType "image").GetMatch "avatar*" }} |
187 | 196 | {{ $has_logo := fileExists "assets/images/logo.webp" | or (fileExists "assets/images/logo.svg") }} |
188 | 197 | {{ $og_image := "" }} |
189 | | - {{ $twitter_card := "summary_large_image" }} |
| 198 | + {{ $og_image_width := 0 }} |
| 199 | + {{ $og_image_height := 0 }} |
190 | 200 | {{ if (and (eq .Kind "taxonomy") $avatar_image) }} |
191 | | - {{ $og_image = ($avatar_image.Fill "270x270 Center").Permalink }}{{/* Match image proc in About widget. */}} |
192 | | - {{ $twitter_card = "summary" }} |
| 201 | + {{ $avatar_fill := $avatar_image.Fill "270x270 Center" }} |
| 202 | + {{ $og_image = $avatar_fill.Permalink }} |
| 203 | + {{ $og_image_width = $avatar_fill.Width }} |
| 204 | + {{ $og_image_height = $avatar_fill.Height }} |
193 | 205 | {{ else if $featured_image }} |
194 | 206 | {{ $og_image = $featured_image.Permalink }} |
| 207 | + {{ $og_image_width = $featured_image.Width }} |
| 208 | + {{ $og_image_height = $featured_image.Height }} |
195 | 209 | {{ else if .Params.header.image }} |
196 | 210 | {{ $og_image = printf "%s/%s" $media_dir .Params.header.image | absURL }} |
197 | 211 | {{ else if site.Params.sharing_image }} |
198 | 212 | {{ $og_image = site.Params.sharing_image | absURL }} |
| 213 | + {{ with images.Config (printf "/static/%s" site.Params.sharing_image) }} |
| 214 | + {{ $og_image_width = .Width }} |
| 215 | + {{ $og_image_height = .Height }} |
| 216 | + {{ end }} |
199 | 217 | {{ else if $has_logo }} |
200 | 218 | {{ $og_image = (partial "functions/get_logo" (dict "constraint" "fit" "size" 300)).Permalink }} |
201 | | - {{ $twitter_card = "summary" }} |
202 | 219 | {{ else }} |
203 | 220 | {{ $og_image = (partial "functions/get_icon" 512).Permalink }} |
204 | | - {{ $twitter_card = "summary" }} |
205 | 221 | {{ end }} |
206 | 222 | {{ $scr.Set "og_image" $og_image }}{{/* Set `og_image` globally for `rss.xml`. */}} |
207 | | - <meta property="twitter:card" content="{{ $twitter_card }}"> |
208 | | - {{ with site.Params.twitter }} |
209 | | - <meta property="twitter:site" content="@{{ . }}"> |
210 | | - <meta property="twitter:creator" content="@{{ . }}"> |
211 | | - {{ end }} |
| 223 | + {{ $og_image_alt := site.Params.sharing_image_alt | default site.Title }} |
| 224 | + {{ if .Params.sharing_image_alt }}{{ $og_image_alt = .Params.sharing_image_alt }}{{ end }} |
212 | 225 | <meta property="og:site_name" content="{{ site.Title }}"> |
213 | 226 | <meta property="og:url" content="{{ .Permalink }}"> |
214 | | - <meta property="og:title" content="{{ if not .IsHome }}{{ .Title }}{{ else }}{{ site.Title }}{{ end }}"> |
215 | | - <meta property="og:description" content='{{ printf "%.254s" $desc }}'> |
| 227 | + {{/* Sharing title: allow override, else append site name for context in previews. */}} |
| 228 | + {{ $og_title := "" }} |
| 229 | + {{ if .Params.sharing_title }} |
| 230 | + {{ $og_title = .Params.sharing_title }} |
| 231 | + {{ else if .Params.og_title }} |
| 232 | + {{ $og_title = .Params.og_title }} |
| 233 | + {{ else if .IsHome }} |
| 234 | + {{ $og_title = site.Title }} |
| 235 | + {{ else }} |
| 236 | + {{ $og_title = printf "%s | %s" .Title site.Title }} |
| 237 | + {{ end }} |
| 238 | + <meta property="og:title" content="{{ $og_title }}"> |
| 239 | + <meta property="og:description" content='{{ $og_desc }}'> |
216 | 240 | {{- with $og_image -}} |
217 | 241 | <meta property="og:image" content="{{.}}"> |
218 | | - <meta property="twitter:image" content="{{.}}"> |
| 242 | + {{- if (and (gt $og_image_width 0) (gt $og_image_height 0)) -}} |
| 243 | + <meta property="og:image:width" content="{{ $og_image_width }}"> |
| 244 | + <meta property="og:image:height" content="{{ $og_image_height }}"> |
| 245 | + {{- end -}} |
| 246 | + {{- with $og_image_alt -}} |
| 247 | + <meta property="og:image:alt" content="{{ . }}"> |
| 248 | + {{- end -}} |
219 | 249 | {{- end -}} |
220 | 250 | <meta property="og:locale" content="{{ site.LanguageCode | default "en-us" }}"> |
221 | 251 | {{ if .IsPage }} |
|
0 commit comments