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