diff --git a/layouts/partials/templates/opengraph.html b/layouts/partials/templates/opengraph.html index 9e8df143..127819b5 100644 --- a/layouts/partials/templates/opengraph.html +++ b/layouts/partials/templates/opengraph.html @@ -3,11 +3,16 @@ {{- if .Params.cover.image -}} +{{- $cover := (.Resources.ByType "image").GetMatch (printf "*%s*" (.Params.cover.image)) }} +{{- if $cover -}}{{/* i.e it is present in page bundle */}} + +{{- else }}{{/* For absolute urls and external links */}} {{- if (ne .Params.cover.relative true) }} {{- else}} {{- end}} +{{- end}} {{- else }} {{- with $.Params.images -}} diff --git a/layouts/partials/templates/schema_json.html b/layouts/partials/templates/schema_json.html index 435cba51..2abffa74 100644 --- a/layouts/partials/templates/schema_json.html +++ b/layouts/partials/templates/schema_json.html @@ -74,6 +74,10 @@ "wordCount" : "{{ .WordCount }}", "inLanguage": {{ .Language.Lang | default "en-us" }}, {{ if .Params.cover.image -}} + {{- $cover := (.Resources.ByType "image").GetMatch (printf "*%s*" (.Params.cover.image)) }} + {{- if $cover -}}{{/* i.e it is present in page bundle */}} + "image": "{{ $cover.Permalink }}", + {{- else }}{{/* For absolute urls and external links */}} "image": {{- if (ne .Params.cover.relative true) -}} {{ .Params.cover.image | absURL }}, @@ -81,6 +85,7 @@ {{ (path.Join .RelPermalink .Params.cover.image ) | absURL }}, {{- end}} {{- end -}} + {{- end -}} "datePublished": {{ .PublishDate }}, "dateModified": {{ .Lastmod }}, {{- with (.Params.author | default site.Params.author) }} diff --git a/layouts/partials/templates/twitter_cards.html b/layouts/partials/templates/twitter_cards.html index bd46e376..61fcdc4c 100644 --- a/layouts/partials/templates/twitter_cards.html +++ b/layouts/partials/templates/twitter_cards.html @@ -1,10 +1,16 @@ {{- if .Params.cover.image -}} +{{- $cover := (.Resources.ByType "image").GetMatch (printf "*%s*" (.Params.cover.image)) }} +{{- if $cover -}}{{/* i.e it is present in page bundle */}} + + +{{- else }}{{/* For absolute urls and external links */}} {{- if (ne $.Params.cover.relative true) }} {{- else }} {{- end}} +{{- end -}} {{- else }} {{- with $.Params.images -}}