Skip to content

Commit 8c5833b

Browse files
jmooringtomy0000000sean-au
authored andcommitted
[PATCH] tpl/tplimpl: Improve embedded opengraph template
Changes: - Add tags per documentation - Prefer site.Title over site.Params.title - Plainify titles, tags, and descriptions - Add fallback values for locale - Fix pages related by series - Improve readability Co-authored-by: tomy0000000 <git@tomy.me> Co-authored-by: sean-au <sean@powerfulwebdesign.com.au>
1 parent aebcc92 commit 8c5833b

File tree

1 file changed

+62
-42
lines changed

1 file changed

+62
-42
lines changed
Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,72 @@
1-
<meta property="og:title" content="{{ .Title }}">
2-
<meta property="og:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}">
3-
<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}">
41
<meta property="og:url" content="{{ .Permalink }}">
5-
{{- if .Params.cover.image -}}
6-
{{- if (ne .Params.cover.relative true) }}
7-
<meta property="og:image" content="{{ .Params.cover.image | absURL }}">
8-
{{- else}}
9-
<meta property="og:image" content="{{ (path.Join .RelPermalink .Params.cover.image ) | absURL }}">
10-
{{- end}}
11-
{{- else }}
122

13-
{{- $images := partial "partials/templates/_funcs/get-page-images" . -}}
14-
{{- range first 6 $images }}
15-
<meta property="og:image" content="{{ .Permalink }}">
16-
{{ end -}}
3+
{{- with or site.Title site.Params.title | plainify }}
4+
<meta property="og:site_name" content="{{ . }}">
5+
{{- end }}
6+
7+
{{- with or .Title site.Title site.Params.title | plainify}}
8+
<meta property="og:title" content="{{ . }}">
9+
{{- end }}
10+
11+
{{- with or .Description .Summary site.Params.description | plainify }}
12+
<meta property="og:description" content="{{ . }}">
13+
{{- end }}
14+
15+
{{- with or .Params.locale site.Language.LanguageCode site.Language.Lang }}
16+
<meta property="og:locale" content="{{ . }}">
1717
{{- end }}
1818

1919
{{- if .IsPage }}
20-
{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}}
21-
<meta property="article:section" content="{{ .Section }}">
22-
{{ with .PublishDate }}<meta property="article:published_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }}>{{ end }}
23-
{{ with .Lastmod }}<meta property="article:modified_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }}>{{ end }}
24-
{{- end -}}
25-
26-
{{- with .Params.audio }}<meta property="og:audio" content="{{ . }}">{{ end }}
27-
{{- with .Params.locale }}<meta property="og:locale" content="{{ . }}">{{ end }}
28-
{{- with site.Params.title }}<meta property="og:site_name" content="{{ . }}">{{ end }}
29-
{{- with .Params.videos }}{{- range . }}
30-
<meta property="og:video" content="{{ . | absURL }}">
31-
{{ end }}{{ end }}
32-
33-
{{- /* If it is part of a series, link to related articles */}}
34-
{{- $permalink := .Permalink }}
35-
{{- $siteSeries := site.Taxonomies.series }}
36-
{{- if $siteSeries }}
37-
{{ with .Params.series }}{{- range $name := . }}
38-
{{- $series := index $siteSeries ($name | urlize) }}
39-
{{- range $page := first 6 $series.Pages }}
40-
{{- if ne $page.Permalink $permalink }}<meta property="og:see_also" content="{{ $page.Permalink }}">{{ end }}
41-
{{- end }}
42-
{{ end }}{{ end }}
43-
{{- end }}
44-
45-
{{- /* Facebook Page Admin ID for Domain Insights */}}
20+
<meta property="og:type" content="article">
21+
<meta property="article:section" content="{{ .Section }}">
22+
{{- $ISO8601 := "2006-01-02T15:04:05-07:00" }}
23+
{{- with .PublishDate }}
24+
<meta property="article:published_time" {{ .Format $ISO8601 | printf "content=%q" | safeHTMLAttr }}>
25+
{{- end }}
26+
{{- with .Lastmod }}
27+
<meta property="article:modified_time" {{ .Format $ISO8601 | printf "content=%q" | safeHTMLAttr }}>
28+
{{- end }}
29+
{{- range .GetTerms "tags" | first 6 }}
30+
<meta property="article:tag" content="{{ .Page.Title | plainify }}">
31+
{{- end }}
32+
{{- else }}
33+
<meta property="og:type" content="website">
34+
{{- end }}
35+
36+
{{- with partial "_funcs/get-page-images" . }}
37+
{{- range . | first 6 }}
38+
<meta property="og:image" content="{{ .Permalink }}">
39+
{{- end }}
40+
{{- end }}
41+
42+
{{- with .Params.audio }}
43+
{{- range . | first 6 }}
44+
<meta property="og:audio" content="{{ . | absURL }}">
45+
{{- end }}
46+
{{- end }}
47+
48+
{{- with .Params.videos }}
49+
{{- range . | first 6 }}
50+
<meta property="og:video" content="{{ . | absURL }}">
51+
{{- end }}
52+
{{- end }}
53+
54+
{{- range .GetTerms "series" }}
55+
{{- range .Pages | first 7 }}
56+
{{- if ne $ . }}
57+
<meta property="og:see_also" content="{{ .Permalink }}">
58+
{{- end }}
59+
{{- end }}
60+
{{- end }}
61+
4662
{{- with site.Params.social }}
4763
{{- if reflect.IsMap . }}
48-
{{- with .facebook_admin }}
49-
<meta property="fb:admins" content="{{ . }}">
64+
{{- with .facebook_app_id }}
65+
<meta property="fb:app_id" content="{{ . }}">
66+
{{- else }}
67+
{{- with .facebook_admin }}
68+
<meta property="fb:admins" content="{{ . }}">
69+
{{- end }}
5070
{{- end }}
5171
{{- end }}
5272
{{- end }}

0 commit comments

Comments
 (0)