hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

twitter.html (1408B)

    1 {{- $pc := .Page.Site.Config.Privacy.Twitter -}}
    2 {{- if not $pc.Disable -}}
    3   {{- if $pc.Simple -}}
    4     {{- template "_internal/shortcodes/twitter_simple.html" . -}}
    5   {{- else -}}
    6     {{- $msg1 := "The %q shortcode requires two named parameters: user and id. See %s" -}}
    7     {{- $msg2 := "The %q shortcode will soon require two named parameters: user and id. See %s" -}}
    8     {{- if .IsNamedParams -}}
    9       {{- $id := .Get "id" -}}
   10       {{- $user := .Get "user" -}}
   11       {{- if and $id $user -}}
   12         {{- template "render-tweet" (dict "id" $id "user" $user "dnt" $pc.EnableDNT) -}}
   13       {{- else -}}
   14         {{- errorf $msg1 .Name .Position -}}
   15       {{- end -}}
   16     {{- else -}}
   17       {{- $id := .Get 1 -}}
   18       {{- $user := .Get 0 -}}
   19       {{- if eq 1 (len .Params) -}}
   20         {{- $id = .Get 0 -}}
   21         {{- $user = "x" -}} {{/* This triggers a redirect. It works, but may not work forever. */}}
   22         {{- warnf $msg2 .Name .Position -}}
   23       {{- end -}}
   24       {{- template "render-tweet" (dict "id" $id "user" $user "dnt" $pc.EnableDNT) -}}
   25     {{- end -}}
   26   {{- end -}}
   27 {{- end -}}
   28 
   29 {{- define "render-tweet" -}}
   30   {{- $url := printf "https://twitter.com/%v/status/%v" .user .id -}}
   31   {{- $query := querify "url" $url "dnt" .dnt -}}
   32   {{- $request := printf "https://publish.twitter.com/oembed?%s" $query -}}
   33   {{- $json := getJSON $request -}}
   34   {{- $json.html | safeHTML -}}
   35 {{- end -}}