-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.go
73 lines (62 loc) · 1.81 KB
/
main.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
package main
import (
"fmt"
"github.com/mmcdole/gofeed"
"log"
)
type Friend struct {
Name string `json:"name"`
Description string `json:"description"`
Avatar string `json:"avatar"`
URL string `json:"url"`
RSS string `json:"rss"`
Feed *gofeed.Feed `json:"-"` // RSS Content
}
type FriendsData struct {
Friends []*Friend `json:"friends"`
}
type Post struct {
Title string
Author string
Date string // YYYY-MM-DD
Content string // 保留前 200 字
PostURL string // 文章链接
AuthorURL string // 作者链接
}
func main() {
// 读取有哪些朋友
friends := Read(Config.InputPath)
// 获取朋友的RSS内容
for _, friend := range friends.Friends {
err := friend.FetchFeed()
if err != nil {
log.Printf("Error fetching feed for %s with %s : %v", friend.Name, friend.RSS, err)
}
}
// 从 RSS 中解析文章
posts := GetPosts(friends)
for _, post := range posts {
fmt.Printf("标题:%s\n", post.Title)
fmt.Printf("作者:%s\n", post.Author)
fmt.Printf("日期:%s\n", post.Date)
fmt.Printf("内容:%s\n", post.Content)
fmt.Printf("文章链接:%s\n", post.PostURL)
fmt.Printf("作者链接:%s\n", post.AuthorURL)
fmt.Println("---------------------")
}
// 渲染 markdown 和 json
markdownBytes := RenderMarkdown(friends.Friends, posts)
jsonBytes := RenderJson(friends.Friends, posts)
//fmt.Println(string(markdownBytes))
// 写入文件
err := Write(markdownBytes, Config.OutputMarkdownPath)
if err != nil {
log.Fatalf("Failed to write file: %v", err)
}
fmt.Println("Markdown content written to file successfully!")
err = Write(jsonBytes, Config.OutputJsonPath)
if err != nil {
log.Fatalf("Failed to write file: %v", err)
}
fmt.Println("Json content written to file successfully!")
}