Ver código fonte

Use new Twitter card partial. Fix #2

master
Adrian Short 5 anos atrás
pai
commit
343eb68f00
2 arquivos alterados com 43 adições e 1 exclusões
  1. +1
    -1
      layouts/partials/header.html
  2. +42
    -0
      layouts/partials/twitter_cards.html

+ 1
- 1
layouts/partials/header.html Ver arquivo

@@ -19,7 +19,7 @@
{{ if not .Page.Params.via }}
<meta name="twitter:creator" content="@{{ .Site.Params.twitter }}">
{{ end }}
{{- template "_internal/twitter_cards.html" -}}
{{- partial "twitter_cards" . -}}
</head>
<body>
<header>


+ 42
- 0
layouts/partials/twitter_cards.html Ver arquivo

@@ -0,0 +1,42 @@
<!-- From: https://gitlab.com/kaushalmodi/hugo-theme-refined/blob/b627ec997ad83e058b4cc817397fa1a3f0ce0b74/layouts/partials/twitter_cards.html
via: https://discourse.gohugo.io/t/links-for-images-videos-audio-in-internal-templates-twitter-cards-and-opengraph/10464 -->
{{ $permalink := .Permalink }}
{{- with $.Params.images -}}
<meta name="twitter:card" content="summary_large_image"/>
<!-- As per https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/summary-card-with-large-image,
the required card property is "twitter:image", not "twitter:image:src". -->
{{- $image := (index . 0) -}}
{{- $image_link_absolute := (findRE "^/" $image) -}}
{{- if $image_link_absolute -}}
<meta name="twitter:image" content="{{- $image | absURL -}}"/>
{{- else -}}
<meta name="twitter:image" content="{{- (printf "%s%s" $permalink $image) -}}"/>
{{- end -}}
{{ else -}}
{{- $images := $.Resources.ByType "image" -}}
{{- $featured := $images.GetMatch "*feature*" -}}
{{- $featured := cond (ne $featured nil) $featured ($images.GetMatch "{*cover*,*thumbnail*}") -}}
{{- with $featured -}}
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="{{ $featured.Permalink }}"/>
{{- else -}}
{{- with $.Site.Params.images -}}
<meta name="twitter:card" content="summary_large_image"/>
{{- $image := (index . 0) -}}
{{- $image_link_absolute := (findRE "^/" $image) -}}
{{- if $image_link_absolute -}}
<meta name="twitter:image" content="{{- $image | absURL -}}"/>
{{- else -}}
<meta name="twitter:image" content="{{- (printf "%s%s" $permalink $image) -}}"/>
{{- end -}}
{{ else -}}
<meta name="twitter:card" content="summary"/>
{{- end -}}
{{- end -}}
{{- 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 -}}
<meta name="twitter:site" content="@{{ . }}"/>
<meta name="twitter:creator" content="@{{ . }}"/>
{{ end -}}

Carregando…
Cancelar
Salvar