diff options
author | Tina <feministclickback@mail36.net> | 2020-05-08 18:23:41 +0300 |
---|---|---|
committer | Tina <feministclickback@mail36.net> | 2020-05-08 18:23:41 +0300 |
commit | 159516b36338373a1319e2c8ebcbacc4d2a7637f (patch) | |
tree | 66530c6b1ea7ce70b38748590e0c1bb2aa63ef79 | |
parent | 8ad42947c8f8449a3695cd2019c9c6addfd469f4 (diff) |
Tina Reis's avatar
include og:locale in open graph meta data
The open graph protocol enables web pages to show up as rich objects in
a social graph, see: https://ogp.me/
Which basically means that when someone shares a link of a webpage on
Facebook, it will look like a page on Facebook instead of an external
web page.
Hugo has an internal template for Open Graph meta data:
https://gohugo.io/templates/internal/#open-graph
It is used in Terrassa theme.
However, I wanted to include the optional meta tag og:locale, to signal
to social media platforms which language the page is in.
Hugo's template includes og:locale, but it is set using page parameters,
not site parameters, see code here on line 30:
https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/opengraph.html
This doesn't make sense to me, because then we'd have to define the
locale parameter in the front matter of every single page for it to render. We could do that automatically by adding a line in `archetypes` default, which defines the default parameters that are added to each page, but still this means an additional line in every page that we create.
So I decided to manually add og:locale meta tag in head.html.
I can come back to this later, if I ever figure out why Hugo does it
that way, and change it but this works for now.
-rw-r--r-- | layouts/partials/head.html | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/layouts/partials/head.html b/layouts/partials/head.html index e617b43..0621306 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -6,7 +6,7 @@ <title>{{ $.Site.Title }} - {{ .Title }}</title> <link rel="icon" href="{{ $.Site.BaseURL }}{{ $.Site.Params.favicon }}" /> <meta name="description" content="{{ $.Site.Params.description }}" /> - + {{ if .IsTranslated }} {{ range .AllTranslations }} <link rel="alternate" hreflang="{{ .Language.Lang }}" href="{{ .Permalink }}" title="{{ .Language.LanguageName }}"> @@ -22,6 +22,13 @@ {{ template "_internal/twitter_cards.html" . }} {{ template "_internal/opengraph.html" . }} + <meta property="og:locale" content="{{ .Site.Language.Lang }}" /> + {{ if .IsTranslated }} + {{ range .Translations }} + <meta property="og:locale:alternate" content="{{ .Language.Lang }}" /> + {{ end }} + {{ end }} + <!-- CSS --> {{ partial "styles.html" . }} </head> |