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 -}}
|
|
|
|
{{- $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 -}}
|
2018-05-30 16:42:32 -04:00
|
|
|
{{- end -}}
|