mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +00:00
opengraph: adjust to Hugo's build-in code #824
This commit is contained in:
parent
3c6d603254
commit
714b64ab14
1 changed files with 51 additions and 50 deletions
|
@ -1,11 +1,10 @@
|
|||
{{- /* based on Hugo 0.119.0 _internal/opengraph.html but with modified title */}}
|
||||
{{- /* based on Hugo 0.125.0 _internal/opengraph.html but with modified title */}}
|
||||
{{- $format := partial "get-format.hugo" . }}
|
||||
{{- $outputFormat := partial "output-format.hugo" (dict "page" . "format" $format) }}
|
||||
{{- $basename := "index" }}
|
||||
{{- if eq $outputFormat "searchpage" }}
|
||||
{{- $basename = partial "BaseName.hugo" $format.RelPermalink }}
|
||||
{{- end }}
|
||||
{{- $page := . }}
|
||||
{{- $title := .Title }}
|
||||
{{- if eq $outputFormat "searchpage" }}
|
||||
{{- $title = T "Search" }}
|
||||
|
@ -19,34 +18,24 @@
|
|||
{{- if and $title .Site.Title (not (eq $title .Site.Title)) }}
|
||||
{{- $title = printf "%s %s %s" $title (default "::" .Site.Params.titleSeparator) .Site.Title }}
|
||||
{{- end }}
|
||||
<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="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true "basename" $basename) }}">
|
||||
{{- with $.Params.images }}
|
||||
{{- range first 6 . }}
|
||||
<meta property="og:image" content="{{ . | absURL }}">
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
{{- $images := $.Resources.ByType "image" }}
|
||||
{{- $featured := $images.GetMatch "*feature*" }}
|
||||
{{- if not $featured }}
|
||||
{{- $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}
|
||||
{{- end }}
|
||||
{{- with $featured }}
|
||||
<meta property="og:image" content="{{ $featured.Permalink }}">
|
||||
{{- else }}
|
||||
{{- with $.Site.Params.images }}
|
||||
<meta property="og:image" content="{{ index . 0 | absURL }}">
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{- with or site.Title site.Params.title | plainify }}
|
||||
<meta property="og:site_name" content="{{ . }}">
|
||||
{{- end }}
|
||||
<meta property="og:title" content="{{ $title | plainify }}">
|
||||
|
||||
{{- with or .Description .Summary site.Params.description | plainify }}
|
||||
<meta property="og:description" content="{{ . }}">
|
||||
{{- end }}
|
||||
|
||||
{{- with or .Params.locale site.Language.LanguageCode site.Language.Lang }}
|
||||
<meta property="og:locale" content="{{ . }}">
|
||||
{{- end }}
|
||||
|
||||
{{- if .IsPage }}
|
||||
{{- $iso8601 := "2006-01-02T15:04:05-07:00" }}
|
||||
{{- with .Parent }}
|
||||
{{- $page := . }}
|
||||
{{- $link := "<link href=\"%s\" rel=\"%s\" type=\"%s\" title=\"%s\">" }}
|
||||
<meta property="og:type" content="article">
|
||||
{{- with .FirstSection }}
|
||||
{{- $title := .Title }}
|
||||
{{- if eq $outputFormat "searchpage" }}
|
||||
{{- $title = T "Search" }}
|
||||
|
@ -60,48 +49,57 @@
|
|||
{{- if and $title .Site.Title (not (eq $title .Site.Title)) }}
|
||||
{{- $title = printf "%s %s %s" $title (default "::" .Site.Params.titleSeparator) .Site.Title }}
|
||||
{{- end }}
|
||||
<meta property="article:section" content="{{ $title }}">
|
||||
<meta property="article:section" content="{{ $title | plainify }}">
|
||||
{{- end }}
|
||||
{{- $iso8601 := "2006-01-02T15:04:05-07:00" }}
|
||||
{{- with .PublishDate }}
|
||||
<meta property="article:published_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }}>
|
||||
{{- end }}
|
||||
{{- with .Lastmod }}
|
||||
<meta property="article:modified_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }}>
|
||||
{{- end }}
|
||||
{{- range .GetTerms "tags" | first 6 }}
|
||||
<meta property="article:tag" content="{{ .Page.Title | plainify }}">
|
||||
{{- 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 }}
|
||||
<meta property="og:audio" content="{{ . }}">
|
||||
{{- end }}
|
||||
{{- with .Params.locale }}
|
||||
<meta property="og:locale" content="{{ . }}">
|
||||
{{- end }}
|
||||
{{- with .Site.Title }}
|
||||
<meta property="og:site_name" content="{{ . }}">
|
||||
{{- range . | first 6 }}
|
||||
<meta property="og:audio" content="{{ . | absURL }}">
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{- with .Params.videos }}
|
||||
{{- range . }}
|
||||
{{- range . | first 6 }}
|
||||
<meta property="og:video" content="{{ . | absURL }}">
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{- /* If it is part of a series, link to related articles */}}
|
||||
{{- $permalink := .Permalink }}
|
||||
{{- $siteSeries := .Site.Taxonomies.series }}
|
||||
{{- if $siteSeries }}
|
||||
{{- with .Params.series }}
|
||||
{{- range $name := . }}
|
||||
{{- $series := index $siteSeries ($name | urlize) }}
|
||||
{{- range $page := first 6 $series.Pages }}
|
||||
{{- if ne $page.Permalink $permalink }}
|
||||
<meta property="og:see_also" content="{{ $page.Permalink }}">
|
||||
{{ end }}
|
||||
{{- end }}
|
||||
{{- range .GetTerms "series" }}
|
||||
{{- range .Pages | first 7 }}
|
||||
{{- if ne $ . }}
|
||||
<meta property="og:see_also" content="{{ .Permalink }}">
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{- $facebookApp := "" }}
|
||||
{{- with site.Params.social }}
|
||||
{{- if reflect.IsMap . }}
|
||||
{{- with .facebook_app_id }}
|
||||
{{- $facebookApp = . }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{- /* Deprecate site.Social.facebook_admin in favor of site.Params.social.facebook_admin */}}
|
||||
{{- $facebookAdmin := "" }}
|
||||
{{- with site.Params.social.facebook_admin }}
|
||||
{{- $facebookAdmin = . }}
|
||||
|
@ -115,7 +113,10 @@
|
|||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{- /* Facebook Page Admin ID for Domain Insights */}}
|
||||
{{- with $facebookAdmin }}
|
||||
{{- with $facebookApp }}
|
||||
<meta property="fb:app_id" content="{{ . }}">
|
||||
{{- else }}
|
||||
{{- with $facebookAdmin }}
|
||||
<meta property="fb:admins" content="{{ . }}">
|
||||
{{- end }}
|
||||
{{- end }}
|
Loading…
Reference in a new issue