2018-05-24 05:24:38 -04:00
|
|
|
{{- $pc := .Page.Site.Config.Privacy.Twitter -}}
|
2018-05-20 14:00:29 -04:00
|
|
|
{{- if not $pc.Disable -}}
|
2021-10-31 06:56:36 -04:00
|
|
|
{{- if $pc.Simple -}}
|
|
|
|
{{- template "_internal/shortcodes/twitter_simple.html" . -}}
|
|
|
|
{{- else -}}
|
2024-02-01 16:45:31 -05:00
|
|
|
{{- $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) -}}
|
2021-10-31 06:56:36 -04:00
|
|
|
{{- else -}}
|
2024-02-01 16:45:31 -05:00
|
|
|
{{- errorf "The %q shortcode requires two named parameters: user and id. See %s" .Name .Position -}}
|
2021-10-31 06:56:36 -04:00
|
|
|
{{- 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 -}}
|
2024-02-01 16:45:31 -05:00
|
|
|
{{- 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 -}}
|
2018-05-30 16:42:32 -04:00
|
|
|
{{- end -}}
|