/
schema.go
74 lines (59 loc) · 1.44 KB
/
schema.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
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"time"
"github.com/garyburd/twister/web"
md "github.com/knieriem/markdown"
"bytes"
"strings"
)
type Page struct {
Permalink string
Title string
Description string
Keywords string
PageTitle string
Content string
Template string
}
type CachedNewsItem struct {
NewsItem *NewsItem
CachedAt int64
}
type CachedNewsItemArray struct {
NewsItems []*NewsItem
CachedAt int64
}
type NewsItem struct {
Page
Byline string
PostedTime int64
Blurb string
FullDescription string
ImagePath string
ExternalLink string
NewsCategory string
ContributedBy string
Tags []string
}
func (n *NewsItem) PostedTimeEnglish() string {
localTime := time.SecondsToLocalTime(n.PostedTime)
return localTime.Format("_2 January 2006")
}
func (n *NewsItem) ConvertTags() string {
return strings.Join(n.Tags, ",")
}
func (n *NewsItem) RssBestLink() string{
if len(n.ExternalLink) > 0 {
return n.ExternalLink
}
return "http://www.gophertimes.com/" + n.Page.Permalink
}
func (n *NewsItem) EscapedFullDescription() string {
return web.HTMLEscapeString(n.FullDescription)
}
func (n *NewsItem) FormattedFullDescription() string {
doc := md.Parse(n.FullDescription, md.Extensions{Smart: true})
buf := bytes.NewBuffer(nil)
doc.WriteHtml(buf)
return string(buf.Bytes())
}