From 731af8c564b2f44da1307013c0794461d561096b Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Sat, 17 Sep 2016 18:05:22 +0300 Subject: [PATCH] layouts: Add basic support for OpenGraph and Twitter card metadata Uses basic data like title, description, author, and date that we are using with existing vanilla meta tags, but extends them to OG and Twitter Card tags. See [0] and [1]. For the Twitter summary cards specifically, you can optionally add attribution for your username by adding something like this to your configuration: [params.social] twitter_username = "@mralanorth" ... and for posts with images, you can specify an "image" in the post's front matter like so: image = "/2016/09/IMG_20160916_174409.jpg" And then the theme will opt to use Twitter's "large" summary card. [0] http://ogp.me/ [1] https://dev.twitter.com/cards/getting-started --- layouts/_default/baseof.html | 7 +------ layouts/partials/metadata.html | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 layouts/partials/metadata.html diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 44fcccf..7d70fe2 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -7,12 +7,7 @@ {{ "" | safeHTML }} - - - - {{ if .Site.Params.google_verify_meta }}{{ end }} - - {{ .Hugo.Generator }} + {{ partial "metadata.html" . }} diff --git a/layouts/partials/metadata.html b/layouts/partials/metadata.html new file mode 100644 index 0000000..aed026b --- /dev/null +++ b/layouts/partials/metadata.html @@ -0,0 +1,36 @@ +{{ $title := .Title | default .Site.Title }} +{{ $description := .Params.description | default .Site.Params.description }} +{{ $author := .Params.author | default .Site.Params.author }} + + + + + {{ "" | safeHTML }} + + + + {{ if eq .Section "post" }} + + + + {{ if .Params.image }} + + {{ end }} + {{ else }} + + {{ end }} + + + + {{ "" | safeHTML }} + {{ if and (eq .Section "post") (.Params.image) }} + + + {{ else }} + + {{ end }} + {{ if .Site.Params.social.twitter_username}}{{ end }} + + + + {{ .Hugo.Generator }}