mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-25 16:52:29 +00:00
0cc39af682
The existing endpoint will be retired and removed on November 23, 2021. References: - https://twittercommunity.com/t/consolidating-the-oembed-functionality/154690 - https://developer.twitter.com/en/docs/twitter-for-websites/oembed-api#Embedded This is a backward compatible change. The existing endpoint requires a single parameter: the id of the tweet. The new endpoint requires two parameters: the id of the tweet, and the user with whom it is associated. For the moment, if you supply the wrong user, the request will be redirected (with a small delay) to the correct user/id pair. This behavior is undocumented, but we will take advantage of it as Hugo site authors transition to the new syntax. {{< tweet 1453110110599868418 >}} --> works, throws warning, deprecate at some point {{< tweet user="SanDiegoZoo" id="1453110110599868418" >}} --> new syntax Fixes #8130
58 lines
2.2 KiB
HTML
58 lines
2.2 KiB
HTML
{{- $pc := .Page.Site.Config.Privacy.Twitter -}}
|
|
{{- $sc := .Page.Site.Config.Services.Twitter -}}
|
|
{{- if not $pc.Disable -}}
|
|
{{- $msg1 := "The %q shortcode requires two named parameters: user and id. See %s" -}}
|
|
{{- $msg2 := "The %q shortcode will soon require two named parameters: user and id. See %s" -}}
|
|
{{- if .IsNamedParams -}}
|
|
{{- $id := .Get "id" -}}
|
|
{{- $user := .Get "user" -}}
|
|
{{- if and $id $user -}}
|
|
{{- template "render-simple-tweet" (dict "id" $id "user" $user "dnt" $pc.EnableDNT "disableInlineCSS" $sc.DisableInlineCSS "ctx" .) -}}
|
|
{{- else -}}
|
|
{{- errorf $msg1 .Name .Position -}}
|
|
{{- end -}}
|
|
{{- else -}}
|
|
{{- $id := .Get 1 -}}
|
|
{{- $user := .Get 0 -}}
|
|
{{- if eq 1 (len .Params) -}}
|
|
{{- $id = .Get 0 -}}
|
|
{{- $user = "x" -}} {{/* This triggers a redirect. It works, but may not work forever. */}}
|
|
{{- warnf $msg2 .Name .Position -}}
|
|
{{- end -}}
|
|
{{- template "render-simple-tweet" (dict "id" $id "user" $user "dnt" $pc.EnableDNT "disableInlineCSS" $sc.DisableInlineCSS "ctx" .) -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- define "render-simple-tweet" -}}
|
|
{{- $url := printf "https://twitter.com/%v/status/%v" .user .id -}}
|
|
{{- $query := querify "url" $url "dnt" .dnt "omit_script" true -}}
|
|
{{- $request := printf "https://publish.twitter.com/oembed?%s" $query -}}
|
|
{{- $json := getJSON $request -}}
|
|
{{- if not .disableInlineCSS -}}
|
|
{{- template "__h_simple_twitter_css" .ctx -}}
|
|
{{- end }}
|
|
{{ $json.html | safeHTML -}}
|
|
{{- end -}}
|
|
|
|
{{- define "__h_simple_twitter_css" -}}
|
|
{{- if not (.Page.Scratch.Get "__h_simple_twitter_css") -}}
|
|
{{/* Only include once */}}
|
|
{{- .Page.Scratch.Set "__h_simple_twitter_css" true }}
|
|
<style type="text/css">
|
|
.twitter-tweet {
|
|
font: 14px/1.45 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
|
|
border-left: 4px solid #2b7bb9;
|
|
padding-left: 1.5em;
|
|
color: #555;
|
|
}
|
|
.twitter-tweet a {
|
|
color: #2b7bb9;
|
|
text-decoration: none;
|
|
}
|
|
blockquote.twitter-tweet a:hover,
|
|
blockquote.twitter-tweet a:focus {
|
|
text-decoration: underline;
|
|
}
|
|
</style>
|
|
{{- end -}}
|
|
{{- end -}}
|