-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathblogroll.go
49 lines (41 loc) · 1.08 KB
/
blogroll.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
package jobs
import (
mustardcore "mustard/core"
"regexp"
"github.com/mmcdole/gofeed"
)
type blogItem struct {
Title string `json:"title"`
Description string `json:"description"`
Link string `json:"url"`
}
type blogData struct {
Title string `json:"title"`
Items []blogItem `json:"items"`
}
var blogURL = "https://www.goavega.com/feed"
func init() {
mustardcore.GetFactory().Advertise("blogroll", func() {
re := regexp.MustCompile(`<[^>]*>`)
fp := gofeed.NewParser()
feed, _ := fp.ParseURL(blogURL)
totalItems := len(feed.Items)
takeItems := totalItems
if totalItems > 15 {
takeItems = 15
}
slicedItems := feed.Items[1:takeItems]
var (
blog blogData
items []blogItem
)
blog = blogData{Title: feed.Title}
for _, item := range slicedItems {
items = append(items, blogItem{Title: item.Title, Description: re.ReplaceAllString(item.Description, ""),
Link: mustardcore.QRAsDataURI(item.Link)})
}
blog.Items = items
data := mustardcore.EventData{Event: "blogRoll", Data: blog}
mustardcore.GetEventsManager().Notify(data)
})
}