diff --git a/layouts/partials/templates/opengraph.html b/layouts/partials/templates/opengraph.html index 95f037c..1a0a776 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 }} {{- $images := partial "partials/templates/_funcs/get-page-images" . -}} diff --git a/layouts/partials/templates/schema_json.html b/layouts/partials/templates/schema_json.html index ed4d689..5bfd969 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 }}, @@ -86,6 +90,7 @@ "image": {{ .Permalink }}, {{- 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 46b0d04..e6f218a 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 }} {{- $images := partial "partials/templates/_funcs/get-page-images" . -}} {{- with index $images 0 -}}