Skip to content

Commit

Permalink
Fix: Open graph images missing on Score blog (#33)
Browse files Browse the repository at this point in the history
Signed-off-by: Santiago Beroch <[email protected]>
Co-authored-by: Mathieu Benoit <[email protected]>
  • Loading branch information
sberoch and mathieu-benoit authored Nov 5, 2024
1 parent 4782b8c commit c1dc443
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
34 changes: 19 additions & 15 deletions layouts/partials/head/opengraph.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,29 @@
{{ .Scratch.Set "title" .Title -}}
{{ end -}}

{{ with $.Params.images -}}
{{ range first 6 . -}}
{{ with .Params.image }}
<meta property="og:image" content="{{ $.Permalink }}{{ . }}">
{{ end -}}
{{ else -}}
{{ $images := $.Resources.ByType "image" -}}
{{ $featured := $images.GetMatch "*feature*" -}}
{{ if not $featured -}}
{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}
{{ end -}}
{{ with $featured -}}
<meta property="og:image" content="{{ $featured.Permalink }}"/>
{{ else }}
{{ with $.Params.images -}}
{{ range first 6 . -}}
<meta property="og:image" content="{{ $.Permalink }}{{ . }}">
{{ end -}}
{{ else -}}
{{ with $.Site.Params.images -}}
<meta property="og:image" content="{{ index . 0 | absURL }}"/>
<meta property="og:image:alt" content="{{ $.Site.Params.title }}">
{{ $images := $.Resources.ByType "image" -}}
{{ $featured := $images.GetMatch "*feature*" -}}
{{ if not $featured -}}
{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}
{{ end -}}
{{ with $featured -}}
<meta property="og:image" content="{{ $featured.Permalink }}"/>
{{ else -}}
{{ with $.Site.Params.images -}}
<meta property="og:image" content="{{ index . 0 | absURL }}"/>
<meta property="og:image:alt" content="{{ $.Site.Params.title }}">
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}
{{ end }}

{{ with $.Site.Params.images -}}
{{ $.Scratch.Set "primaryImage" (index . 0 | absURL) -}}
Expand Down
31 changes: 18 additions & 13 deletions layouts/partials/head/twitter_cards.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@
<meta name="twitter:creator" content="{{ .Site.Params.twitterCreator }}">
<meta name="twitter:title" content="{{ .Title }}">
<meta name="twitter:description" content="{{ .Description }}">
{{ with $.Params.images -}}
<meta name="twitter:image" content="{{ $.Permalink }}{{ index . 0 }}">
{{ else -}}
{{ $images := $.Resources.ByType "image" -}}
{{ $featured := $images.GetMatch "*feature*" -}}
{{ if not $featured -}}
{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" -}}
{{ end -}}
{{ with $featured -}}
<meta name="twitter:image" content="{{ $featured.Permalink }}">
{{ with .Params.image }}
<meta name="twitter:image" content="{{ $.Permalink }}{{ . }}">
{{ else }}
{{ with $.Params.images -}}
<meta name="twitter:image" content="{{ $.Permalink }}{{ index . 0 }}">
{{ else -}}
{{ with $.Site.Params.images -}}
<meta name="twitter:image" content="{{ index . 0 | absURL }}">
{{ $images := $.Resources.ByType "image" -}}
{{ $featured := $images.GetMatch "*feature*" -}}
{{ if not $featured -}}
{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" -}}
{{ end -}}
{{ with $featured -}}
<meta name="twitter:image" content="{{ $featured.Permalink }}">
{{ else -}}
<meta name="twitter:card" content="summary">
{{ with $.Site.Params.images -}}
<meta name="twitter:image" content="{{ index . 0 | absURL }}">
{{ else -}}
<meta name="twitter:card" content="summary">
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}

<meta name="twitter:image:alt" content="{{ .Title }}">

0 comments on commit c1dc443

Please sign in to comment.