Skip to content

Commit

Permalink
feat: Use site image in absence of page image (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcen authored Jul 8, 2024
1 parent db346b0 commit 4b962af
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions layouts/partials/meta/standard.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,20 @@
<link rel="alternate" hreflang="{{ .Language.Lang }}" href="{{ .Permalink }}" title="{{ .Language.LanguageName }}" />
{{ end }}

{{ with .Params.image }}
<meta itemprop="image" content="{{ . | absURL }}" />
<meta property="og:image" content="{{ . | absURL }}" />
<meta name="twitter:image" content="{{ . | absURL }}" />
<meta name="twitter:image:src" content="{{ . | absURL }}" />
{{ else }}
<meta itemprop="image" content="{{ .Site.Params.ogimage | absURL }}" />
<meta property="og:image" content="{{ .Site.Params.ogimage | absURL }}" />
<meta name="twitter:image" content="{{ .Site.Params.ogimage | absURL }}" />
<meta name="twitter:image:src" content="{{ .Site.Params.ogimage | absURL }}" />
{{ end }}
{{/* Define empty variable image */}}
{{- $image := "" -}}

{{/* If image is defined in front matter, use it */}}
{{- if .Params.image -}}
{{- $image = .Params.image -}}
{{/* If image is not defined in front matter, use site ogimage */}}
{{- else if .Site.Params.ogimage -}}
{{- $image = .Site.Params.ogimage -}}
{{- end -}}

{{- if $image -}}
<meta itemprop="image" content="{{ $image | absURL }}" />
<meta property="og:image" content="{{ $image | absURL }}" />
<meta name="twitter:image" content="{{ $image | absURL }}" />
<meta name="twitter:image:src" content="{{ $image | absURL }}" />
{{- end -}}

0 comments on commit 4b962af

Please sign in to comment.