-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopic.tmpl
164 lines (151 loc) · 6.97 KB
/
topic.tmpl
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
{{/* -----------------------------------------------------------
Purpose:
- shows topic data (meta, posts) as compact HTML page
Description:
- NN
Releases:
- v1.0.0 - 2022/11/21: initial release
- v1.1.0 - 2022/11/22: reply_to* added to post header
- v1.2.0 - 2022/11/25: reactions added to post header, tags added to meta data
Author:
- NN
Remarks:
- Basic table design for each post entry:
┌──────┬────────────────────────────────────┐
│ │ ┌──────────────┬───────────────┐ │
│ │ └──────────────┴───────────────┘ │
│ │ │
│ │ │
│ │ │
│ │ │
└──────┴────────────────────────────────────┘
----------------------------------------------------------- */}}
{{/* configuration */}}
{{ $data := (index . 0 0) }}
{{ $forum := (index . 0 1) }}
{{/* content */}}
{{ $json := readJSON $data }}
{{ $forumURL := printf "https://%s" $forum }}
<!doctype html>
<head>
<meta charset='utf-8'>
<title>{{ $json.meta_data.id }}</title>
<link rel='stylesheet' href='./main.css'>
</head>
<body>
<main>
{{/* ---------- meta data ---------- */}}
<base href="{{ $forumURL }}" />
<h2>{{ $json.meta_data.title }}</h2>
<p>{{ if $json.meta_data.tags }} {{ $json.meta_data.tags | join ", " }} {{ end }}</p>
<hr>
<table class="meta_data_table">
<tr>
<th>Forum</th>
<th>Created</th>
<th>Solution</th>
<th>Category</th>
<th>Topic</th>
<th>Posts</th>
<th>Words</th>
<th>Reading Time</th>
<th>Views</th>
<th>Users</th>
<th>Likes</th>
<th>Links</th>
</tr>
<tr>
<td>{{ $forum }}</td>
{{ $date := substr 0 10 $json.meta_data.created_at }}
{{ $time := substr 11 16 $json.meta_data.created_at }}
<td>{{ $date }} / {{ $time }}</td>
<td>
{{ if $json.meta_data.accepted_answer }} #{{ $json.meta_data.accepted_answer.post_number }} {{ end }}
</td>
<td>{{ $json.meta_data.category_id }}</td>
<td>{{ $json.meta_data.id }}</td>
<td>{{ $json.meta_data.posts_count }}</td>
<td>{{ $json.meta_data.word_count }}</td>
<td>{{ add1 (div $json.meta_data.word_count 200) }} min</td>
<td>{{ $json.meta_data.views }}</td>
<td>{{ $json.meta_data.participant_count }}</td>
<td>{{ $json.meta_data.like_count }}</td>
<td>{{ if $json.meta_data.details.links }}{{ len $json.meta_data.details.links }}{{ end }}</td>
</tr>
</table>
<hr>
{{/* ---------- post data ---------- */}}
{{ range $json.post_data }}
{{ range .post_stream.posts }}
<table class="post_data_table">
<tr>
{{ if .accepted_answer }} <td class="avatar" style="background-color:#C1FFC1;"> {{ else }} <td class="avatar"> {{ end }}
{{ $imageURL := replace "{size}" "40" .avatar_template }}
<img class="avatar" src="{{ $imageURL }}" alt="avatar-image">
</td>
<td>
<table class="post_data_header">
<tr>
<td align=left>
<b>{{ .username }}</b>
{{ if .name }} / {{ .name }} {{ end }}
{{ if .user_title }} / {{ .user_title }} {{ end }}
{{ if .moderator }} / moderator {{ end }}
{{ if .admin }} / admin {{ end }}
{{ $likes := (index .actions_summary 0).count }}
{{ if $likes }}
{{ if eq (int $likes) 1 }}
/ {{ $likes }} like
{{ else }}
/ {{ $likes }} likes
{{ end }}
{{ end }}
{{/* begin experimental */}}
{{ if .reaction_users_count }}
{{ $reactions := sub .reaction_users_count $likes }}
{{ if $reactions }}
{{ if eq (int $reactions) 1 }}
/ {{ $reactions }} react
{{ else }}
/ {{ $reactions }} reacts
{{ end }}
{{ end }}
{{ end }}
{{/* end experimental */}}
{{ if .reply_count }}
{{ if eq (int .reply_count) 1 }}
/ {{ .reply_count }} reply
{{ else }}
/ {{ .reply_count }} replies
{{ end }}
{{ end }}
{{ if .accepted_answer }} / accepted answer {{ end }}
{{ if .reply_to_post_number }}
{{ if .reply_to_user.username }}
/ ➚ {{ .reply_to_user.username }} #{{ .reply_to_post_number }}
{{ else }}
/ ➚ #{{ .reply_to_post_number }}
{{ end }}
{{ end }}
{{ if .action_code }} / <b style="color: red;">{{ .action_code }}</b> {{ end }}
</td>
{{ $date := substr 0 10 .created_at }}
{{ $time := substr 11 16 .created_at }}
{{ $updated := ne .created_at .updated_at }}
<td align=right>
<a href="/t/-/{{ $json.meta_data.id}}/{{ .post_number }}" target="_blank" rel="noopener noreferrer">#{{ .post_number }}</a>
{{ if $updated }} / updated {{ end }}
/ {{ $date }} / {{ $time }}
</td>
</tr>
</table>
{{ toTypeHTML .cooked }}
</td>
</tr>
</table>
<hr>
{{ end }}
{{ end }}
</main>
</body>
</html>