Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tpl
diff options
context:
space:
mode:
authorJoe Mooring <joe.mooring@veriphor.com>2021-10-31 13:56:36 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-11-01 17:51:00 +0300
commit0cc39af68232f1a4981aae2e72cf65da762b5768 (patch)
treeda1c6a143d93544f5d9df2646128f2ae79ca7c3f /tpl
parented6fd26ce884c49b02497728a99e90b92dd65f1f (diff)
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 #8130
Diffstat (limited to 'tpl')
-rw-r--r--tpl/tplimpl/embedded/templates.autogen.go120
-rw-r--r--tpl/tplimpl/embedded/templates/shortcodes/twitter.html39
-rw-r--r--tpl/tplimpl/embedded/templates/shortcodes/twitter_simple.html79
3 files changed, 170 insertions, 68 deletions
diff --git a/tpl/tplimpl/embedded/templates.autogen.go b/tpl/tplimpl/embedded/templates.autogen.go
index 8e691af4c..5394cbc7a 100644
--- a/tpl/tplimpl/embedded/templates.autogen.go
+++ b/tpl/tplimpl/embedded/templates.autogen.go
@@ -589,47 +589,99 @@ if (!doNotTrack) {
{`shortcodes/relref.html`, `{{ relref . .Params }}`},
{`shortcodes/twitter.html`, `{{- $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 -}}
+ {{- $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 -}}
-{{- 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 -}}
+`},
{`shortcodes/twitter_simple.html`, `{{- $pc := .Page.Site.Config.Privacy.Twitter -}}
{{- $sc := .Page.Site.Config.Services.Twitter -}}
{{- if not $pc.Disable -}}
-{{- $id := .Get 0 -}}
-{{- $json := getJSON "https://api.twitter.com/1/statuses/oembed.json?id=" $id "&omit_script=true" -}}
-{{- if not $sc.DisableInlineCSS -}}
-{{ template "__h_simple_twitter_css" $ }}
+ {{- $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 -}}
-{{ $json.html | safeHTML }}
+
+{{- 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 }}`},
+{{- 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 -}}
+`},
{`shortcodes/vimeo.html`, `{{- $pc := .Page.Site.Config.Privacy.Vimeo -}}
{{- if not $pc.Disable -}}
{{- if $pc.Simple -}}
diff --git a/tpl/tplimpl/embedded/templates/shortcodes/twitter.html b/tpl/tplimpl/embedded/templates/shortcodes/twitter.html
index e2c4983d7..2f1d2323e 100644
--- a/tpl/tplimpl/embedded/templates/shortcodes/twitter.html
+++ b/tpl/tplimpl/embedded/templates/shortcodes/twitter.html
@@ -1,10 +1,35 @@
{{- $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 -}}
+ {{- $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 -}}
-{{- end -}} \ No newline at end of file
diff --git a/tpl/tplimpl/embedded/templates/shortcodes/twitter_simple.html b/tpl/tplimpl/embedded/templates/shortcodes/twitter_simple.html
index 45d594fd9..0127fbe22 100644
--- a/tpl/tplimpl/embedded/templates/shortcodes/twitter_simple.html
+++ b/tpl/tplimpl/embedded/templates/shortcodes/twitter_simple.html
@@ -1,33 +1,58 @@
{{- $pc := .Page.Site.Config.Privacy.Twitter -}}
{{- $sc := .Page.Site.Config.Services.Twitter -}}
{{- if not $pc.Disable -}}
-{{- $id := .Get 0 -}}
-{{- $json := getJSON "https://api.twitter.com/1/statuses/oembed.json?id=" $id "&omit_script=true" -}}
-{{- if not $sc.DisableInlineCSS -}}
-{{ template "__h_simple_twitter_css" $ }}
+ {{- $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 -}}
-{{ $json.html | safeHTML }}
+
+{{- 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 }} \ No newline at end of file
+{{- 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 -}}