|
21 | 21 | <link rel="alternate" type="{{ .MediaType.Type }}" href="{{ .Permalink }}" title="{{ $.Site.Title }} — {{ $.Title }}"> |
22 | 22 | {{ end }} |
23 | 23 |
|
24 | | -{{/* ── OG image: front matter → default social cover ── */}} |
| 24 | +{{/* ── OG image: `image` → first of `images` → default social cover ── */}} |
25 | 25 | {{ $ogImage := "" }} |
| 26 | +{{ $ogW := 1200 }} |
| 27 | +{{ $ogH := 630 }} |
26 | 28 | {{ if .Params.image }} |
27 | 29 | {{ $res := resources.Get .Params.image }} |
28 | 30 | {{ if not $res }}{{ $res = .Resources.Get .Params.image }}{{ end }} |
29 | 31 | {{ with $res }} |
30 | 32 | {{ $ogImage = (. | fingerprint).Permalink }} |
31 | 33 | {{ end }} |
32 | | -{{ else if .Params.images }} |
33 | | - {{ $ogImage = absURL (index .Params.images 0) }} |
34 | | -{{ else }} |
| 34 | +{{ end }} |
| 35 | +{{ if and (not $ogImage) .Params.images }} |
| 36 | + {{/* `images` entries are filenames inside the page's own bundle (logo.png, banner.jpg, |
| 37 | + photo.jpg…), so they must go through .Resources — absURL on a bare filename |
| 38 | + points at the site root and 404s. */}} |
| 39 | + {{ $file := index .Params.images 0 }} |
| 40 | + {{ $res := .Resources.Get $file }} |
| 41 | + {{ if not $res }}{{ $res = resources.Get (strings.TrimPrefix "/" $file) }}{{ end }} |
| 42 | + {{ with $res }} |
| 43 | + {{ $ogImage = (. | fingerprint).Permalink }} |
| 44 | + {{ $ogW = .Width }} |
| 45 | + {{ $ogH = .Height }} |
| 46 | + {{ end }} |
| 47 | +{{ end }} |
| 48 | +{{ if not $ogImage }} |
35 | 49 | {{ $cover := resources.Get "images/social_cover.jpg" }} |
36 | 50 | {{ if $cover }} |
37 | 51 | {{ $ogImage = ($cover | fingerprint).Permalink }} |
|
47 | 61 | <meta property="og:locale" content="en_US"> |
48 | 62 | {{ with $ogImage }} |
49 | 63 | <meta property="og:image" content="{{ . }}"> |
50 | | -<meta property="og:image:width" content="1200"> |
51 | | -<meta property="og:image:height" content="630"> |
| 64 | +<meta property="og:image:width" content="{{ $ogW }}"> |
| 65 | +<meta property="og:image:height" content="{{ $ogH }}"> |
52 | 66 | {{ end }} |
53 | 67 |
|
54 | 68 | {{/* ── Article meta (blog posts only) ── */}} |
|
60 | 74 | {{ end }} |
61 | 75 |
|
62 | 76 | {{/* ── Twitter Card ── */}} |
63 | | -<meta name="twitter:card" content="{{ if $ogImage }}summary_large_image{{ else }}summary{{ end }}"> |
| 77 | +<meta name="twitter:card" content="{{ if and $ogImage (ge (div (float $ogW) (float $ogH)) 1.4) }}summary_large_image{{ else }}summary{{ end }}"> |
64 | 78 | <meta name="twitter:title" content="{{ if .IsHome }}{{ .Site.Title }}{{ else }}{{ .Title }}{{ end }}"> |
65 | 79 | <meta name="twitter:description" content="{{ $desc }}"> |
66 | 80 | {{ with $ogImage }}<meta name="twitter:image" content="{{ . }}">{{ end }} |
|
0 commit comments