mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-02 02:49:32 -05: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
35 lines
1.4 KiB
HTML
35 lines
1.4 KiB
HTML
{{- $pc := .Page.Site.Config.Privacy.Twitter -}}
|
|
{{- if not $pc.Disable -}}
|
|
{{- if $pc.Simple -}}
|
|
{{- template "_internal/shortcodes/twitter_simple.html" . -}}
|
|
{{- else -}}
|
|
{{- $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-tweet" (dict "id" $id "user" $user "dnt" $pc.EnableDNT) -}}
|
|
{{- 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-tweet" (dict "id" $id "user" $user "dnt" $pc.EnableDNT) -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- define "render-tweet" -}}
|
|
{{- $url := printf "https://twitter.com/%v/status/%v" .user .id -}}
|
|
{{- $query := querify "url" $url "dnt" .dnt -}}
|
|
{{- $request := printf "https://publish.twitter.com/oembed?%s" $query -}}
|
|
{{- $json := getJSON $request -}}
|
|
{{- $json.html | safeHTML -}}
|
|
{{- end -}}
|