From: Alan Orth Date: Sun, 22 Jan 2017 14:06:41 +0000 (+0200) Subject: tpl: Improve generation of OpenGraph date tags X-Git-Tag: v0.19~100 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=95ad3ad2fa3e6f4514166b47b77f051d280c16e9;p=brevno-suite%2Fhugo tpl: Improve generation of OpenGraph date tags Allow all nodes/pages to use date-related OpenGraph meta tags, not only sites which are using the as-of-yet unfinished .Site.Authors functionality. Improve compliance of tags with Facebook's OpenGraph docs for the "website" and "article" types[0][1]. Also, use the proper tag for modification date (og:update_time vs article:modified_time). Generate date published using either .PublishDate or .Date, and use .Lastmod for modification date, which can use the new enableGitInfo functionality from Hugo 0.18, but seamlessly falls back to .Date if the site does not have this enabled/supported. [0] https://developers.facebook.com/docs/reference/opengraph/object-type/website/ [1] https://developers.facebook.com/docs/reference/opengraph/object-type/article/ --- diff --git a/tpl/template_embedded.go b/tpl/template_embedded.go index 3dca82bc..f782a31e 100644 --- a/tpl/template_embedded.go +++ b/tpl/template_embedded.go @@ -167,7 +167,13 @@ func (t *GoHTMLTemplate) EmbedTemplates() { {{ end }}{{ end }} -{{ if not .Date.IsZero }}{{ end }}{{ with .Params.audio }} +{{ if .IsPage }} +{{ if not .PublishDate.IsZero }} +{{ else if not .Date.IsZero }}{{ end }} +{{ if not .Lastmod.IsZero }}{{ end }} +{{ else }} +{{ if not .Date.IsZero }}{{ end }} +{{ end }}{{ with .Params.audio }} {{ end }}{{ with .Params.locale }} {{ end }}{{ with .Site.Params.title }} {{ end }}{{ with .Params.videos }} @@ -189,8 +195,6 @@ func (t *GoHTMLTemplate) EmbedTemplates() { {{ range .Site.Authors }}{{ with .Social.facebook }} {{ end }}{{ with .Site.Social.facebook }} {{ end }} - - {{ with .Params.tags }}{{ range first 6 . }} {{ end }}{{ end }}