From 95ad3ad2fa3e6f4514166b47b77f051d280c16e9 Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Sun, 22 Jan 2017 16:06:41 +0200 Subject: [PATCH] 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/ --- tpl/template_embedded.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tpl/template_embedded.go b/tpl/template_embedded.go index 3dca82bc5..f782a31e9 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 }}