twitter_simple.html (2261B)
1 {{- $pc := .Page.Site.Config.Privacy.Twitter -}} 2 {{- $sc := .Page.Site.Config.Services.Twitter -}} 3 {{- if not $pc.Disable -}} 4 {{- $msg1 := "The %q shortcode requires two named parameters: user and id. See %s" -}} 5 {{- $msg2 := "The %q shortcode will soon require two named parameters: user and id. See %s" -}} 6 {{- if .IsNamedParams -}} 7 {{- $id := .Get "id" -}} 8 {{- $user := .Get "user" -}} 9 {{- if and $id $user -}} 10 {{- template "render-simple-tweet" (dict "id" $id "user" $user "dnt" $pc.EnableDNT "disableInlineCSS" $sc.DisableInlineCSS "ctx" .) -}} 11 {{- else -}} 12 {{- errorf $msg1 .Name .Position -}} 13 {{- end -}} 14 {{- else -}} 15 {{- $id := .Get 1 -}} 16 {{- $user := .Get 0 -}} 17 {{- if eq 1 (len .Params) -}} 18 {{- $id = .Get 0 -}} 19 {{- $user = "x" -}} {{/* This triggers a redirect. It works, but may not work forever. */}} 20 {{- warnf $msg2 .Name .Position -}} 21 {{- end -}} 22 {{- template "render-simple-tweet" (dict "id" $id "user" $user "dnt" $pc.EnableDNT "disableInlineCSS" $sc.DisableInlineCSS "ctx" .) -}} 23 {{- end -}} 24 {{- end -}} 25 26 {{- define "render-simple-tweet" -}} 27 {{- $url := printf "https://twitter.com/%v/status/%v" .user .id -}} 28 {{- $query := querify "url" $url "dnt" .dnt "omit_script" true -}} 29 {{- $request := printf "https://publish.twitter.com/oembed?%s" $query -}} 30 {{- $json := getJSON $request -}} 31 {{- if not .disableInlineCSS -}} 32 {{- template "__h_simple_twitter_css" .ctx -}} 33 {{- end }} 34 {{ $json.html | safeHTML -}} 35 {{- end -}} 36 37 {{- define "__h_simple_twitter_css" -}} 38 {{- if not (.Page.Scratch.Get "__h_simple_twitter_css") -}} 39 {{/* Only include once */}} 40 {{- .Page.Scratch.Set "__h_simple_twitter_css" true }} 41 <style type="text/css"> 42 .twitter-tweet { 43 font: 14px/1.45 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif; 44 border-left: 4px solid #2b7bb9; 45 padding-left: 1.5em; 46 color: #555; 47 } 48 .twitter-tweet a { 49 color: #2b7bb9; 50 text-decoration: none; 51 } 52 blockquote.twitter-tweet a:hover, 53 blockquote.twitter-tweet a:focus { 54 text-decoration: underline; 55 } 56 </style> 57 {{- end -}} 58 {{- end -}}