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

Closes #8296
Closes #8698
Closes #8991
Closes #9818
Closes #9866
Closes #10647

Co-authored-by: tomy0000000 <git@tomy.me>
Co-authored-by: sean-au <sean@powerfulwebdesign.com.au>
This commit is contained in:
Joe Mooring 2024-04-01 08:51:32 -07:00 committed by Bjørn Erik Pedersen
parent 6624979e1b
commit 2da4ec5738

View file

@ -1,44 +1,72 @@
<meta property="og:title" content="{{ .Title }}">
<meta property="og:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}">
<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}">
<meta property="og:url" content="{{ .Permalink }}"> <meta property="og:url" content="{{ .Permalink }}">
{{- $images := partial "_funcs/get-page-images" . -}} {{- with or site.Title site.Params.title | plainify }}
{{- range first 6 $images -}} <meta property="og:site_name" content="{{ . }}">
<meta property="og:image" content="{{ .Permalink }}"> {{- end }}
{{- end -}}
{{- with or .Title site.Title site.Params.title | plainify}}
{{- if .IsPage }} <meta property="og:title" content="{{ . }}">
{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}} {{- end }}
<meta property="article:section" content="{{ .Section }}">
{{ with .PublishDate }}<meta property="article:published_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }}>{{ end }} {{- with or .Description .Summary site.Params.description | plainify }}
{{ with .Lastmod }}<meta property="article:modified_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }}>{{ end }} <meta property="og:description" content="{{ . }}">
{{- end -}} {{- end }}
{{- with .Params.audio }}<meta property="og:audio" content="{{ . }}">{{ end }} {{- with or .Params.locale site.Language.LanguageCode site.Language.Lang }}
{{- with .Params.locale }}<meta property="og:locale" content="{{ . }}">{{ end }} <meta property="og:locale" content="{{ . }}">
{{- with .Site.Params.title }}<meta property="og:site_name" content="{{ . }}">{{ end }} {{- end }}
{{- with .Params.videos }}{{- range . }}
<meta property="og:video" content="{{ . | absURL }}"> {{- if .IsPage }}
{{ end }}{{ end }} <meta property="og:type" content="article">
<meta property="article:section" content="{{ .Section }}">
{{- /* If it is part of a series, link to related articles */}} {{- $ISO8601 := "2006-01-02T15:04:05-07:00" }}
{{- $permalink := .Permalink }} {{- with .PublishDate }}
{{- $siteSeries := .Site.Taxonomies.series }} <meta property="article:published_time" {{ .Format $ISO8601 | printf "content=%q" | safeHTMLAttr }}>
{{- if $siteSeries }} {{- end }}
{{ with .Params.series }}{{- range $name := . }} {{- with .Lastmod }}
{{- $series := index $siteSeries ($name | urlize) }} <meta property="article:modified_time" {{ .Format $ISO8601 | printf "content=%q" | safeHTMLAttr }}>
{{- range $page := first 6 $series.Pages }} {{- end }}
{{- if ne $page.Permalink $permalink }}<meta property="og:see_also" content="{{ $page.Permalink }}">{{ end }} {{- range .GetTerms "tags" | first 6 }}
{{- end }} <meta property="article:tag" content="{{ .Page.Title | plainify }}">
{{ end }}{{ end }} {{- end }}
{{- else }}
<meta property="og:type" content="website">
{{- end }}
{{- with partial "_funcs/get-page-images" . }}
{{- range . | first 6 }}
<meta property="og:image" content="{{ .Permalink }}">
{{- end }}
{{- end }}
{{- with .Params.audio }}
{{- range . | first 6 }}
<meta property="og:audio" content="{{ . | absURL }}">
{{- end }}
{{- end }}
{{- with .Params.videos }}
{{- range . | first 6 }}
<meta property="og:video" content="{{ . | absURL }}">
{{- end }}
{{- end }}
{{- range .GetTerms "series" }}
{{- range .Pages | first 7 }}
{{- if ne $ . }}
<meta property="og:see_also" content="{{ .Permalink }}">
{{- end }}
{{- end }}
{{- end }} {{- end }}
{{- /* Facebook Page Admin ID for Domain Insights */}}
{{- with site.Params.social }} {{- with site.Params.social }}
{{- if reflect.IsMap . }} {{- if reflect.IsMap . }}
{{- with .facebook_app_id }}
<meta property="fb:app_id" content="{{ . }}">
{{- else }}
{{- with .facebook_admin }} {{- with .facebook_admin }}
<meta property="fb:admins" content="{{ . }}"> <meta property="fb:admins" content="{{ . }}">
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- end }}
{{- end }} {{- end }}