-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.go
54 lines (46 loc) · 876 Bytes
/
template.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
package goblawg
import (
"html/template"
"math/rand"
"time"
"github.com/russross/blackfriday"
)
/* Template functions
* */
func Markdown(input []byte) template.HTML {
output := blackfriday.MarkdownCommon(input)
return template.HTML(string(output))
}
func DateFmt(tt time.Time) string {
const layout = "3:04pm, 2 January 2006"
return tt.Format(layout)
}
func IsEven(i int) bool {
if i%2 == 0 {
return true
} else {
return false
}
}
func Subslice(a []*Post, start, end int) []*Post {
ln := end - start
if len(a) < ln || ln < 0 {
return a
} else {
return a[start:end]
}
}
func RandomPosts(a []*Post, currPostURL string, numPosts int) []*Post {
perm := rand.Perm(len(a))
res := []*Post{}
for i := range perm {
v := perm[i]
if a[v].Link != currPostURL {
res = append(res, a[v])
}
if len(res) >= numPosts {
break
}
}
return res
}