forked from gohugoio/hugo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Twitter shortcode oEmbed endpoint
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 gohugoio#8130
- Loading branch information
Showing
9 changed files
with
211 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
node_modules | ||
nohup.out | ||
.DS_Store | ||
trace.out | ||
trace.out | ||
.hugo_build.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,39 @@ | ||
{{- $pc := .Page.Site.Config.Privacy.Twitter -}} | ||
{{- if not $pc.Disable -}} | ||
{{- if $pc.Simple -}} | ||
{{ template "_internal/shortcodes/twitter_simple.html" . }} | ||
{{- else -}} | ||
{{- $url := printf "https://api.twitter.com/1/statuses/oembed.json?id=%v&dnt=%t" (index .Params 0) $pc.EnableDNT -}} | ||
{{- $json := getJSON $url -}} | ||
{{ $json.html | safeHTML }} | ||
{{- if $pc.Simple -}} | ||
{{- template "_internal/shortcodes/twitter_simple.html" . -}} | ||
{{- else -}} | ||
{{- $id := "" -}} | ||
{{- $user := "" -}} | ||
{{- $msg1 := "The %q shortcode requires a parameter named %q. See %s" -}} | ||
{{- $msg2 := "The %q shortcode now requires two named parameters: user and id. See %s" -}} | ||
|
||
{{- if .IsNamedParams -}} | ||
{{- with .Get "id" -}} | ||
{{- $id = . -}} | ||
{{- else -}} | ||
{{- errorf $msg1 .Name "id" .Position -}} | ||
{{- end -}} | ||
{{- with .Get "user" -}} | ||
{{- $user = . -}} | ||
{{- else -}} | ||
{{- errorf $msg1 .Name "user" .Position -}} | ||
{{- end -}} | ||
{{- else -}} | ||
{{- 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 }} | ||
{{- else -}} | ||
{{- $id = .Get 1 -}} | ||
{{- $user = .Get 0 -}} | ||
{{- end -}} | ||
{{- end -}} | ||
|
||
{{- $url := printf "https://twitter.com/%v/status/%v" $user $id -}} | ||
{{- $query := querify "url" $url "dnt" $pc.EnableDNT -}} | ||
{{- $request := printf "https://publish.twitter.com/oembed?%s" $query -}} | ||
{{- $json := getJSON $request -}} | ||
{{- $json.html | safeHTML -}} | ||
{{- end -}} | ||
{{- end -}} | ||
{{- end -}} |
Oops, something went wrong.