-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoot.html
More file actions
131 lines (121 loc) · 5.01 KB
/
toot.html
File metadata and controls
131 lines (121 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
{{- /* Only enable if name params used (we need 'id') */ -}}
{{- if .IsNamedParams -}}
{{- /* Discover the sites configured user's home server */ -}}
{{- $parts := split .Site.Params.mastodonName "@" -}}
{{- $url := "" -}}
{{- with try (resources.GetRemote (printf "https://%s/.well-known/webfinger?resource=acct:%s@%s" (index $parts 2) (index $parts 1) (index $parts 2))) -}}
{{- with .Err -}}
{{- errorf "%s" . -}}
{{- else with .Value -}}
{{- $finger := .Content | transform.Unmarshal -}}
{{- $url = index (split (index $finger.aliases 0) "@") 0 -}}
{{- end -}}
{{- else -}}
{{- errorf "Unable to finger %q" .Site.Params.mastodonName -}}
{{ end }}
{{- /* Grab toot with ID from users home server */ -}}
{{- $toot := dict -}}
{{- with try (resources.GetRemote (printf "%s/api/v1/statuses/%s" $url (.Get "id"))) -}}
{{- with .Err -}}
{{- errorf "%s" . -}}
{{- else with .Value -}}
{{- $toot = .Content | transform.Unmarshal -}}
{{- end -}}
{{- else -}}
{{- errorf "Unable to get toot %q" .Get "id" -}}
{{ end }}
{{- /* Replace emojis in user display name */ -}}
{{- $displayName := $toot.account.display_name -}}
{{- range $index, $emoji := $toot.account.emojis }}
{{- $shortcode := printf ":%s:" $emoji.shortcode -}}
{{- if strings.Contains $toot.account.display_name $shortcode -}}
{{- $emojiElement := printf "<span class=\"icon is-small\"><img src=\"%s\" alt=\"%s\"/></span>" $emoji.url $shortcode -}}
{{- $displayName = strings.Replace $displayName $shortcode $emojiElement -}}
{{- end -}}
{{ end -}}
{{- /* Grab toots source server accounting for authors web/domain setting */ -}}
{{- $instanceHost := (urls.Parse $toot.account.url).Host -}}
{{- $acParts := split $toot.account.acct "@" -}}
{{- if eq (len $acParts) 1 -}}
{{- $instanceHost = index $parts 2 }}
{{- end -}}
{{- /* Grab toot authors avatar */ -}}
{{- $avatar := $toot.account.avatar -}}
{{- with try (resources.GetRemote $toot.account.avatar) -}}
{{- with .Err }}
{{- errorf "%s" . -}}
{{- else with .Value -}}
{{- $avatar = .RelPermalink -}}
{{- end -}}
{{- else -}}
{{- errorf "Unable to get remote resource %q" $avatar -}}
{{- end -}}
<div class="columns is-centered">
<div class="u-repost-of h-cite toot is-three-fifths" itemprop="sharedContent" itemid="{{ $toot.url }}" itemscope itemtype="https://schema.org/SocialMediaPosting">
<div class="toot-content">
<div class="p-author h-card media" itemprop="author" itemscope itemtype="https://schema.org/Person">
<div class="media-left">
<a href="{{ $toot.account.url }}" class="u-url" target="_blank" rel="noopener noreferrer">
<figure class="image is-48x48">
<img src="{{ $avatar }}" alt="Placeholder image" class="u-photo" itemprop="image">
</figure>
</a>
</div>
<div class="media-content">
<a href="{{ $toot.account.url }}" target="_blank" rel="noopener noreferrer" itemprop="url">
<p class="p-name title is-5" itemprop="name">{{ $displayName | safeHTML}}</p>
<p class="subtitle is-6">@{{ $toot.account.username}}@{{ $instanceHost }}</p>
</a>
</div>
</div>
<div class="p-content content">
{{ if strings.HasSuffix $toot.content "</p>"}}
{{ strings.TrimPrefix "<p>" (strings.TrimSuffix "</p>" $toot.content) | safeHTML }}
{{ else }}
{{ $toot.content | safeHTML }}
{{ end }}
</div>
{{ with $toot.media_attachments }}
<div class="toot-gallery {{- if gt (. | len) 1 }} fixed-grid has-2-cols{{ end -}}">
{{ if gt (. | len) 1 }}
<div class="columns is-multiline is-mobile is-variable is-1">
{{ range $index, $attachment := . }}
<div class="column is-half">
{{- $image := dict
"src" $attachment.url
"alt" $attachment.description
-}}
{{- partial "figure.html" $image -}}
</div>
{{ end}}
</div>
{{ else }}
{{ end }}
</div>
{{ end }}
<div class="toot-meta">
<a href="{{ $toot.url }}" class="u-url" target="_blank" rel="noopener noreferrer" itemprop="url">
{{- $date := time $toot.created_at }}
<time class="dt-published" datetime="{{ dateFormat "2006-01-02T15:04:05Z07:00" $toot.created_at }}" itemprop="datePublished">
{{ dateFormat "Jan 2, 2006, 15:04" $toot.created_at }}</time></a>
·
<a href="{{ $toot.url }}/reblogs" target="_blank" rel="noopener noreferrer">
<span class="icon-text">
<span class="icon">
<i class="fas fa-retweet"></i>
</span>
<span>{{ $toot.reblogs_count }}</span>
</span></a>
·
<a href="{{ $toot.url }}/favourites" target="_blank" rel="noopener noreferrer">
<span class="icon-text">
<span class="icon">
<i class="fas fa-star"></i>
</span>
<span>{{ $toot.favourites_count }}</span>
</span></a>
</div>
</div>
</div>
</div>
{{- end -}}