summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerghei Iakovlev <egrep@protonmail.ch>2022-05-24 22:42:02 +0200
committerSerghei Iakovlev <egrep@protonmail.ch>2022-05-24 22:42:06 +0200
commitd2f88394bc44e1d0e1d8e9beb72d7055d52ce62e (patch)
tree4da42c62f7ce8e0a14f29d214bb0421e773b6597
parent43c35d217e14fe00a91b2945d4d3bdefe48947b8 (diff)
downloadgohugo-theme-ed-d2f88394bc44e1d0e1d8e9beb72d7055d52ce62e.tar.gz
Provide ability to use featured image
-rw-r--r--exampleSite/content/documentation/index.md1
-rw-r--r--layouts/partials/templates/opengraph.html25
2 files changed, 10 insertions, 16 deletions
diff --git a/exampleSite/content/documentation/index.md b/exampleSite/content/documentation/index.md
index 5e4460b..20a9061 100644
--- a/exampleSite/content/documentation/index.md
+++ b/exampleSite/content/documentation/index.md
@@ -1,6 +1,7 @@
---
title: Documentation
author: Alex Gil
+featured_image: screenshot-home.png
---
## Contents
diff --git a/layouts/partials/templates/opengraph.html b/layouts/partials/templates/opengraph.html
index aed77e3..fbee957 100644
--- a/layouts/partials/templates/opengraph.html
+++ b/layouts/partials/templates/opengraph.html
@@ -3,26 +3,19 @@
<meta property="og:description" content="{{ (partial "description.html" . ) }}">
<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}">
<meta property="og:url" content="{{ .Permalink }}">
-{{- if .Params.cover.image -}}
- {{- if (ne .Params.cover.relative true) }}
- <meta property="og:image" content="{{ .Params.cover.image | absURL }}">
- {{- else }}
- <meta property="og:image" content="{{ (path.Join .RelPermalink .Params.cover.image ) | absURL }}">
- {{- end }}
- {{- if .Params.cover.width -}}
- <meta property="og:image:width" content="{{ .Params.cover.width }}">
- {{- end }}
+{{- $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png" ) -}}
+{{- $image := .Resources.GetMatch .Params.featured_image -}}
- {{- if .Params.cover.height -}}
- <meta property="og:image:height" content="{{ .Params.cover.height }}">
- {{- end }}
+{{- if and .IsPage $image }}
+ <meta property="og:image" content="{{ $image.Permalink }}">
+ <meta property="og:image:width" content="{{ $image.Width }}">
+ <meta property="og:image:height" content="{{ $image.Height }}">
{{- else }}
- {{- $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png" ) }}
<meta property="og:image" content="{{ $logo.Permalink }}">
- <meta property="og:image:width" content="{{ site.Params.assets.logo_width | default 200 }}">
- <meta property="og:image:height" content="{{ site.Params.assets.logo_height | default 200 }}">
-{{- end }}
+ <meta property="og:image:width" content="{{ $logo.Width }}">
+ <meta property="og:image:height" content="{{ $logo.Height }}">
+{{- end -}}
{{- /* Facebook Page Admin ID for Domain Insights */}}
{{- with site.Social.facebook_admin }}