refactor(opengraph): add default value for twitter:card (#72)

This commit is contained in:
Jimmy Cai 2020-12-20 11:05:34 +01:00 committed by GitHub
parent d205753323
commit 25a72940b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 21 deletions

View File

@ -62,7 +62,10 @@ params:
opengraph: opengraph:
twitter: twitter:
# Your Twitter username
site: site:
# Available values: summary, summary_large_image
card: summary_large_image card: summary_large_image
defaultImage: defaultImage:

View File

@ -6,35 +6,35 @@
<meta property='og:url' content='{{ .Permalink }}'> <meta property='og:url' content='{{ .Permalink }}'>
<meta property='og:site_name' content='{{ .Site.Title }}'> <meta property='og:site_name' content='{{ .Site.Title }}'>
<meta property='og:type' content=' <meta property='og:type' content='
{{- if .IsPage -}} {{- if .IsPage -}}
article article
{{- else -}} {{- else -}}
website website
{{- end -}} {{- end -}}
'> '>
{{- with .Params.locale -}} {{- with .Params.locale -}}
<meta property='og:locale' content='{{ . }}'> <meta property='og:locale' content='{{ . }}'>
{{- end -}} {{- end -}}
{{- if .IsPage -}} {{- if .IsPage -}}
<meta property='article:section' content='{{ .Section | title }}' /> <meta property='article:section' content='{{ .Section | title }}' />
{{- range .Params.tags -}} {{- range .Params.tags -}}
<meta property='article:tag' content='{{ . }}' /> <meta property='article:tag' content='{{ . }}' />
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- if .IsPage -}} {{- if .IsPage -}}
{{- if not .Date.IsZero -}} {{- if not .Date.IsZero -}}
<meta property='article:published_time' content='{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}'/> <meta property='article:published_time' content='{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}'/>
{{- end -}} {{- end -}}
{{- if not .Lastmod.IsZero -}} {{- if not .Lastmod.IsZero -}}
<meta property='article:modified_time' content='{{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }}'/> <meta property='article:modified_time' content='{{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }}'/>
{{- end -}} {{- end -}}
{{- else -}} {{- else -}}
{{- if not .Site.LastChange.IsZero -}} {{- if not .Site.LastChange.IsZero -}}
<meta property='og:updated_time' content='{{ .Site.LastChange.Format " 2006-01-02T15:04:05-07:00 " | safeHTML }}'/> <meta property='og:updated_time' content='{{ .Site.LastChange.Format " 2006-01-02T15:04:05-07:00 " | safeHTML }}'/>
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{ $image := partialCached "helper/image" (dict "Context" . "Type" "opengraph") .RelPermalink "opengraph" }} {{ $image := partialCached "helper/image" (dict "Context" . "Type" "opengraph") .RelPermalink "opengraph" }}

View File

@ -10,6 +10,6 @@
{{- $image := partialCached "helper/image" (dict "Context" . "Type" "opengraph") .RelPermalink "opengraph" -}} {{- $image := partialCached "helper/image" (dict "Context" . "Type" "opengraph") .RelPermalink "opengraph" -}}
{{- if $image.exists -}} {{- if $image.exists -}}
<meta name="twitter:card" content="{{ .Site.Params.opengraph.twitter.card }}"> <meta name="twitter:card" content="{{ default `summary_large_image` .Site.Params.opengraph.twitter.card }}">
<meta name="twitter:image" content='{{ absURL $image.permalink }}' /> <meta name="twitter:image" content='{{ absURL $image.permalink }}' />
{{- end -}} {{- end -}}