Skip to content

Commit 6db5a64

Browse files
Mazizovaclaude
andcommitted
Fix og:image pointing at a non-existent file on pages with images
For pages that set `images:` (webinars, events, software, books, SaaS, People…) head.html emitted absURL(<bare filename>), e.g. https://oursqlfoundation.org/banner.jpg. Those files live inside the page's own bundle, not at the site root, so the share image 404'd on 85 of 327 pages and social platforms showed no preview at all. Resolve the first `images` entry through the page's resources (same fingerprinted-permalink path the `image` front matter already used), and fall back to the default social cover if it can't be resolved instead of emitting a dead URL. Since logos and photos are not 1200x630, the real image dimensions are now declared in og:image:width/height, and twitter:card drops to `summary` for roughly square images (large cards only for wide ones like the webinar banners). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 084fb82 commit 6db5a64

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

‎layouts/partials/head.html‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,31 @@
2121
<link rel="alternate" type="{{ .MediaType.Type }}" href="{{ .Permalink }}" title="{{ $.Site.Title }} — {{ $.Title }}">
2222
{{ end }}
2323

24-
{{/* ── OG image: front matter → default social cover ── */}}
24+
{{/* ── OG image: `image` → first of `images` → default social cover ── */}}
2525
{{ $ogImage := "" }}
26+
{{ $ogW := 1200 }}
27+
{{ $ogH := 630 }}
2628
{{ if .Params.image }}
2729
{{ $res := resources.Get .Params.image }}
2830
{{ if not $res }}{{ $res = .Resources.Get .Params.image }}{{ end }}
2931
{{ with $res }}
3032
{{ $ogImage = (. | fingerprint).Permalink }}
3133
{{ 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 }}
3549
{{ $cover := resources.Get "images/social_cover.jpg" }}
3650
{{ if $cover }}
3751
{{ $ogImage = ($cover | fingerprint).Permalink }}
@@ -47,8 +61,8 @@
4761
<meta property="og:locale" content="en_US">
4862
{{ with $ogImage }}
4963
<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 }}">
5266
{{ end }}
5367

5468
{{/* ── Article meta (blog posts only) ── */}}
@@ -60,7 +74,7 @@
6074
{{ end }}
6175

6276
{{/* ── 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 }}">
6478
<meta name="twitter:title" content="{{ if .IsHome }}{{ .Site.Title }}{{ else }}{{ .Title }}{{ end }}">
6579
<meta name="twitter:description" content="{{ $desc }}">
6680
{{ with $ogImage }}<meta name="twitter:image" content="{{ . }}">{{ end }}

0 commit comments

Comments
 (0)