mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-25 19:21:25 +00:00
d0788b96ae
- Replace data.GetJSON calls with resources.GetRemote - Remove usage of Facebook’s oEmbed Read feature Fixes #11971
29 lines
1.1 KiB
HTML
29 lines
1.1 KiB
HTML
{{- $pc := .Page.Site.Config.Privacy.Twitter -}}
|
|
{{- if not $pc.Disable -}}
|
|
{{- if $pc.Simple -}}
|
|
{{- template "_internal/shortcodes/twitter_simple.html" . -}}
|
|
{{- else -}}
|
|
{{- $id := or (.Get "id") "" -}}
|
|
{{- $user := or (.Get "user") "" -}}
|
|
{{- if and $id $user -}}
|
|
{{- template "render-tweet" (dict "id" $id "user" $user "dnt" $pc.EnableDNT "name" .Name "position" .Position) -}}
|
|
{{- else -}}
|
|
{{- errorf "The %q shortcode requires two named parameters: user and id. See %s" .Name .Position -}}
|
|
{{- 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 -}}
|
|
{{- with resources.GetRemote $request -}}
|
|
{{- with .Err -}}
|
|
{{- errorf "%s" . -}}
|
|
{{- else -}}
|
|
{{- (. | transform.Unmarshal).html | safeHTML -}}
|
|
{{- end -}}
|
|
{{- else -}}
|
|
{{- warnidf "shortcode-twitter-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" .name .position -}}
|
|
{{- end -}}
|
|
{{- end -}}
|