summaryrefslogtreecommitdiffstats
path: root/layouts
diff options
context:
space:
mode:
authorSerghei Iakovlev <egrep@protonmail.ch>2022-05-25 00:01:42 +0200
committerSerghei Iakovlev <egrep@protonmail.ch>2022-05-25 00:01:42 +0200
commitabe3b6761139a97ce535486af2f6918f2a8c0051 (patch)
tree0619acb48c28dd9d29110eee6841f5912bff8d35 /layouts
parentcd9b95683a8ec2c2ef86863c61025ae8a6fc4222 (diff)
downloadgohugo-theme-ed-abe3b6761139a97ce535486af2f6918f2a8c0051.tar.gz
Add ability to create twitter cards
Diffstat (limited to 'layouts')
-rw-r--r--layouts/partials/head.html1
-rw-r--r--layouts/partials/templates/opengraph.html2
-rw-r--r--layouts/partials/templates/twitter_cards.html19
3 files changed, 21 insertions, 1 deletions
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 81dd2d0..24fd6f9 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -29,4 +29,5 @@
{{- /* Misc */}}
{{ template "partials/templates/opengraph.html" . }}
+ {{ template "partials/templates/twitter_cards.html" . }}
</head>
diff --git a/layouts/partials/templates/opengraph.html b/layouts/partials/templates/opengraph.html
index fbee957..c65cdac 100644
--- a/layouts/partials/templates/opengraph.html
+++ b/layouts/partials/templates/opengraph.html
@@ -1,5 +1,5 @@
<!-- Open Graph metadata -->
- <meta property="og:title" content="{{ .Title }}">
+ <meta property="og:title" content="{{ partial "title.html" . }}">
<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 }}">
diff --git a/layouts/partials/templates/twitter_cards.html b/layouts/partials/templates/twitter_cards.html
new file mode 100644
index 0000000..970c137
--- /dev/null
+++ b/layouts/partials/templates/twitter_cards.html
@@ -0,0 +1,19 @@
+ <!-- Twitter Card metadata -->
+ <meta name="twitter:title" content="{{- partial "title.html" . -}}">
+ <meta name="twitter:description" content="{{ (partial "description.html" . ) }}">
+
+ {{- /* Twitter username for the website used in the card footer */}}
+ {{- with site.Social.twitter }}
+ <meta name="twitter:site" content="@{{ . }}">
+ {{- end }}
+
+ {{- $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png" ) -}}
+ {{- $image := .Resources.GetMatch .Params.featured_image -}}
+
+ {{- if and .IsPage $image }}
+ <meta name="twitter:card" content="summary_large_image">
+ <meta name="twitter:image" content="{{ $image.Permalink }}">
+ {{- else }}
+ <meta name="twitter:card" content="summary_large_image">
+ <meta name="twitter:image" content="{{ $logo.Permalink }}">
+ {{- end -}}