Better social card logic
This commit is contained in:
parent
8b4ac7a925
commit
488da01892
8 changed files with 22 additions and 25 deletions
|
@ -3,7 +3,11 @@
|
|||
<meta name="description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}" />
|
||||
<meta name="keywords" content="{{ if .IsPage}}{{ range $index, $tag := .Params.tags }}{{ $tag }},{{ end }}{{ else }}{{ range $plural, $terms := .Site.Taxonomies }}{{ range $term, $val := $terms }}{{ printf "%s," $term }}{{ end }}{{ end }}{{ end }}" />
|
||||
|
||||
{{ if (default false .Site.Params.generateSocialCard) }}
|
||||
<!-- Only generate social card if: -->
|
||||
<!-- - generateSocialCard = true -->
|
||||
<!-- - there aren't images set in frontmatter -->
|
||||
<!-- - page is of .Kind "page" -->
|
||||
{{ if and (and (default false .Site.Params.generateSocialCard) (not (isset .Params "images"))) (eq .Kind "page") }}
|
||||
{{ partial "social_card.html" . }}
|
||||
{{ else }}
|
||||
<!-- Open Graph / Facebook -->
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
)) }}
|
||||
|
||||
{{ $date := .Date.Format (default "2006-01-02" .Site.Params.dateFormat) }}
|
||||
{{ $byline := (printf "%s | %s" ($.Param "author") $date) }}
|
||||
{{ $author := (default $.Site.Author.name ($.Param "author") ) }}
|
||||
{{ $byline := (printf "%s | %s" $author $date) }}
|
||||
|
||||
{{ $fg = $fg.Filter (images.Text $byline (dict
|
||||
"font" $font
|
||||
|
@ -34,11 +35,7 @@
|
|||
<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}" />
|
||||
<meta property="og:url" content="{{ .Permalink }}" />
|
||||
|
||||
{{- with .Params.images -}}
|
||||
{{- range first 6 . }}<meta property="og:image" content="{{ . | absURL }}" />{{ end -}}
|
||||
{{- else -}}
|
||||
<meta property="og:image" content="{{ $card.Permalink | absURL }}"/>
|
||||
{{- end -}}
|
||||
|
||||
{{- if .IsPage }}
|
||||
{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}}
|
||||
|
@ -71,13 +68,9 @@
|
|||
|
||||
<!-- Twitter -->
|
||||
<!-- Source: https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/twitter_cards.html -->
|
||||
{{- with .Params.images -}}
|
||||
<meta name="twitter:card" content="summary_large_image"/>
|
||||
<meta name="twitter:image" content="{{ index . 0 | absURL }}"/>
|
||||
{{ else -}}
|
||||
<meta name="twitter:card" content="summary_large_image"/>
|
||||
<meta name="twitter:image" content="{{ $card.Permalink | absURL }}"/>
|
||||
{{- end }}
|
||||
|
||||
<meta name="twitter:title" content="{{ .Title }}"/>
|
||||
<meta name="twitter:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end -}}"/>
|
||||
{{ with .Site.Social.twitter -}}
|
||||
|
@ -95,11 +88,7 @@
|
|||
{{ with .Lastmod }}<meta itemprop="dateModified" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end}}
|
||||
<meta itemprop="wordCount" content="{{ .WordCount }}">
|
||||
|
||||
{{- with .Params.images -}}
|
||||
{{- range first 6 . -}}<meta itemprop="image" content="{{ . | absURL }}">{{ end -}}
|
||||
{{- else -}}
|
||||
<meta itemprop="image" content="{{ $card.Permalink | absURL }}"/>
|
||||
{{- end -}}
|
||||
|
||||
<!-- Output all taxonomies as schema.org keywords -->
|
||||
<meta itemprop="keywords" content="{{ if .IsPage}}{{ range $index, $tag := .Params.tags }}{{ $tag }},{{ end }}{{ else }}{{ range $plural, $terms := .Site.Taxonomies }}{{ range $term, $val := $terms }}{{ printf "%s," $term }}{{ end }}{{ end }}{{ end }}" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue