-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
59 lines (54 loc) · 1.08 KB
/
util.go
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
package templates
import (
"html"
"meguca/common"
"time"
)
// CalculateOmit returns the omitted post and image counts for a thread
func CalculateOmit(t common.Thread) (int, int) {
// There might still be posts missing due to deletions even in complete
// thread queries. Ensure we are actually retrieving an abbreviated thread
// before calculating.
if !t.Abbrev {
return 0, 0
}
var (
omit = int(t.PostCtr) - (len(t.Posts) + 1)
imgOmit uint32
)
if omit != 0 {
imgOmit = t.ImageCtr
if t.Image != nil {
imgOmit--
}
for _, p := range t.Posts {
if p.Image != nil {
imgOmit--
}
}
}
return omit, int(imgOmit)
}
func bold(s string) string {
s = html.EscapeString(s)
b := make([]byte, 3, len(s)+7)
copy(b, "<b>")
b = append(b, s...)
b = append(b, "</b>"...)
return string(b)
}
// Manually correct time zone, because it gets stored wrong in the database
// somehow.
func correctTimeZone(t time.Time) time.Time {
t = t.Round(time.Second)
return time.Date(
t.Year(),
t.Month(),
t.Day(),
t.Hour(),
t.Minute(),
t.Second(),
0,
time.Local,
).UTC()
}