-
Notifications
You must be signed in to change notification settings - Fork 1
/
model_post.go
63 lines (54 loc) · 1.31 KB
/
model_post.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
60
61
62
63
package ambient
import (
"time"
)
// Post -
type Post struct {
Title string `json:"title"`
URL string `json:"url"`
Canonical string `json:"canonical"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Timestamp time.Time `json:"timestamp"`
Content string `json:"content"`
Published bool `json:"published"`
Page bool `json:"page"`
Tags TagList `json:"tags"`
}
// PostWithID -
type PostWithID struct {
Post
ID string `json:"id"`
}
// PostWithIDList -
type PostWithIDList []PostWithID
func (t PostWithIDList) Len() int {
return len(t)
}
func (t PostWithIDList) Swap(i, j int) {
t[i], t[j] = t[j], t[i]
}
func (t PostWithIDList) Less(i, j int) bool {
if t[i].Timestamp.Equal(t[j].Timestamp) {
return t[i].Title > t[j].Title // Sort by title ASC
} else if t[i].Timestamp.Before(t[j].Timestamp) {
return true // Sort by timestamp, DESC
}
return false
}
// PostList -
type PostList []Post
func (t PostList) Len() int {
return len(t)
}
func (t PostList) Swap(i, j int) {
t[i], t[j] = t[j], t[i]
}
func (t PostList) Less(i, j int) bool {
if t[i].Timestamp.Equal(t[j].Timestamp) {
return t[i].Title > t[j].Title // Sort by title ASC
} else if t[i].Timestamp.Before(t[j].Timestamp) {
return true // Sort by timestamp, DESC
}
return false
}