Skip to content

Commit 95ad3ad

Browse files
alanorthbep
authored andcommitted
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/
1 parent 91c569c commit 95ad3ad

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

‎tpl/template_embedded.go‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,13 @@ func (t *GoHTMLTemplate) EmbedTemplates() {
167167
<meta property="og:image" content="{{ . | absURL }}" />
168168
{{ end }}{{ end }}
169169
170-
{{ if not .Date.IsZero }}<meta property="og:updated_time" content="{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}"/>{{ end }}{{ with .Params.audio }}
170+
{{ if .IsPage }}
171+
{{ if not .PublishDate.IsZero }}<meta property="article:published_time" content="{{ .PublishDate.Format "2006-01-02T15:04:05-07:00" | safeHTML }}"/>
172+
{{ else if not .Date.IsZero }}<meta property="article:published_time" content="{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}"/>{{ end }}
173+
{{ if not .Lastmod.IsZero }}<meta property="article:modified_time" content="{{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }}"/>{{ end }}
174+
{{ else }}
175+
{{ if not .Date.IsZero }}<meta property="article:modified_time" content="{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}"/>{{ end }}
176+
{{ end }}{{ with .Params.audio }}
171177
<meta property="og:audio" content="{{ . }}" />{{ end }}{{ with .Params.locale }}
172178
<meta property="og:locale" content="{{ . }}" />{{ end }}{{ with .Site.Params.title }}
173179
<meta property="og:site_name" content="{{ . }}" />{{ end }}{{ with .Params.videos }}
@@ -189,8 +195,6 @@ func (t *GoHTMLTemplate) EmbedTemplates() {
189195
{{ range .Site.Authors }}{{ with .Social.facebook }}
190196
<meta property="article:author" content="https://www.facebook.com/{{ . }}" />{{ end }}{{ with .Site.Social.facebook }}
191197
<meta property="article:publisher" content="https://www.facebook.com/{{ . }}" />{{ end }}
192-
<meta property="article:published_time" content="{{ .PublishDate }}" />
193-
<meta property="article:modified_time" content="{{ .Date }}" />
194198
<meta property="article:section" content="{{ .Section }}" />
195199
{{ with .Params.tags }}{{ range first 6 . }}
196200
<meta property="article:tag" content="{{ . }}" />{{ end }}{{ end }}

0 commit comments

Comments
 (0)