{{ $masIns := .Get 0 }} {{ $tootLink := "" }} {{ $card := "" }} {{ $handleInst := "" }} {{ $mediaMD5 := "" }} {{ $imageCount := 0 }} {{ $votesCount := 0 }} {{ $id := .Get 1 }} {{ $urlToGet := print "https://" $masIns "/api/v1/statuses/" $id }} {{- with try (resources.GetRemote $urlToGet) -}} {{ with .Err }}
{{ else with .Value }} {{ $json := unmarshal .Content }} {{ $jsonHolder := $json }}{{/* Being safe */}} {{ if isset $json "account" }} {{ $tootLink = print "https://" $masIns "/" "@" $json.account.acct "/status/" $id }} {{ $handleInst = print "@" $json.account.acct "@" $masIns }} {{ end }} {{ if isset $json "content" }}
{{ $json.account.display_name }} {{ $handleInst }}
{{ $json.content | safeHTML }} {{ with $json.media_attachments }} {{ range $media_attachments := . }} {{ if eq $media_attachments.type "image" }} {{ $imageCount = (add ($imageCount) 1) }} {{ end }} {{ end }}
{{ range $media_attachments := . }} {{ if eq $media_attachments.type "image" }} {{ $mediaMD5 = md5 $media_attachments.url }} Image {{ $media_attachments.id }} from toot {{ $id }} on {{ $masIns }} {{- if $json.sensitive -}}
Sensitive content
(flagged at origin)
{{- end -}} {{ end }} {{ end }}
{{/* N.B.: The above results in an empty, no-height div when there's no image but there **is** at least one item in `$media_attachments`. Unfortunately, it seems to be the only way to accomplish this. Not a good HTML practice, but gets the job done. */}} {{ range $media_attachments := . }} {{ if eq $media_attachments.type "video" }} {{ $mediaMD5 = md5 $media_attachments.url }}
{{- if $json.sensitive -}}
Sensitive content
(flagged at origin)
{{- end -}}
{{ end }} {{ if eq $media_attachments.type "gifv" }} {{ $mediaMD5 = md5 $media_attachments.url }}
{{- if $json.sensitive -}}
Sensitive content
(flagged at origin)
{{- end -}}
{{ end }} {{ end }} {{ end }} {{ with $json.card }} {{- $cardData := . -}} {{- with $cardData.image -}}
Card image from {{ $masIns }} toot {{ $id }}

{{ $cardData.title }}

{{ $cardData.description }}

{{- end -}} {{ end }} {{ with $json.poll }} {{ $poll := . }} {{ with $poll.options }} {{ range $pollOptions := . }} {{ $votesCount = add $votesCount $pollOptions.votes_count }} {{ end }}
{{ range $pollOptions := . }}
{{ (mul 100 (div $pollOptions.votes_count $votesCount)) | lang.FormatPercent 1 }}
{{ $pollOptions.title }}
{{ end }}
{{ end }} {{ end }}
{{ end }} {{ end }} {{- end -}}