-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstructs.go
202 lines (174 loc) · 5.24 KB
/
structs.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package main
import (
"os"
"slices"
"strings"
"github.com/go-yaml/yaml"
)
type BlogrollInfo struct {
Title string `yaml:"title"`
Date string `yaml:"date"`
Description string `yaml:"description"`
Params BlogrollInfoParams `yaml:"params"`
}
type BlogrollInfoParams struct {
Link string `yaml:"link"`
BlogrollId string `yaml:"blogroll_id"`
Recommends []BlogrollRecommendation `yaml:"recommends"`
}
type BlogrollRecommendation struct {
Title string `yaml:"title"`
Description string `yaml:"description"`
Id string `yaml:"id"`
}
func NewBlogrollInfo(row Blogroll) *BlogrollInfo {
params := BlogrollInfoParams{
Link: row.Link,
BlogrollId: row.BlogrollId,
}
return &BlogrollInfo{
Title: row.Title,
Date: row.Date,
Description: row.Description,
Params: params,
}
}
func (f *BlogrollInfo) Save() {
// Stable sort to improve git diffs
slices.SortFunc(f.Params.Recommends, func(a, b BlogrollRecommendation) int {
return strings.Compare(a.Id, b.Id)
})
output, err := yaml.Marshal(f)
ohno(err)
// Markdown uses `---` for YAML frontmatter
sep := []byte("---\n")
output = append(sep, output...)
output = append(output, sep...)
path := "content/blogrolls/br-" + f.Params.BlogrollId + ".md"
err = os.WriteFile(path, output, os.FileMode(int(0660)))
ohno(err)
}
type FeedInfo struct {
Title string `yaml:"title"`
Date string `yaml:"date"`
Description string `yaml:"description"`
Params FeedInfoParams `yaml:"params"`
}
type BlogrollBrief struct {
Title string `yaml:"title"`
Description string `yaml:"description"`
Id string `yaml:"id"`
}
type FeedInfoParams struct {
FeedLink string `yaml:"feedlink"`
FeedType string `yaml:"feedtype"`
FeedID string `yaml:"feedid"`
Websites map[string]bool `yaml:"websites"`
Blogrolls []string `yaml:"blogrolls"`
InBlogroll []BlogrollBrief `yaml:"in_blogrolls"`
Recommended []string `yaml:"recommended"`
Recommender []string `yaml:"recommender"`
Categories []string `yaml:"categories"`
RelMe map[string]bool `yaml:"relme"`
LastPostTitle string `yaml:"last_post_title"`
LastPostDesc string `yaml:"last_post_description"`
LastPostDate string `yaml:"last_post_date"`
LastPostLink string `yaml:"last_post_link"`
LastPostCategories []string `yaml:"last_post_categories"`
LastPostLanguage string `yaml:"last_post_language"`
LastPostGuid string `yaml:"last_post_guid"`
ScoreCriteria map[string]int `yaml:"score_criteria"`
Score int `yaml:"score"`
IsPodcast bool `yaml:"ispodcast"`
IsNoarchive bool `yaml:"isnoarchive"`
InNetwork bool `yaml:"innetwork"`
Language string `yaml:"language"`
}
func NewFeedInfo(row Feed) *FeedInfo {
p := FeedInfoParams{
FeedLink: row.FeedLink,
FeedID: row.FeedId,
FeedType: row.FeedType,
Websites: map[string]bool{},
RelMe: map[string]bool{},
ScoreCriteria: map[string]int{},
IsPodcast: row.IsPodcast,
IsNoarchive: row.IsNoarchive,
}
f := FeedInfo{
Title: row.Title,
Date: row.Date,
Description: row.Description,
Params: p,
}
return &f
}
type RejectInfo struct {
Title string `yaml:"title"`
Params RejectInfoParams `yaml:"params"`
}
type RejectInfoParams struct {
FeedLink string `yaml:"feedlink"`
FeedID string `yaml:"feedid"`
}
func (f *FeedInfo) Reject() {
r := RejectInfo{
Title: f.Title,
Params: RejectInfoParams{
FeedLink: f.Params.FeedLink,
FeedID: f.Params.FeedID,
},
}
output, err := yaml.Marshal(r)
ohno(err)
// Markdown uses `---` for YAML frontmatter
sep := []byte("---\n")
output = append(sep, output...)
output = append(output, sep...)
path := "content/excluded/feed-" + r.Params.FeedID + ".md"
err = os.WriteFile(path, output, os.FileMode(int(0660)))
ohno(err)
}
func (f *FeedInfo) Save() {
output, err := yaml.Marshal(f)
ohno(err)
// Markdown uses `---` for YAML frontmatter
sep := []byte("---\n")
output = append(sep, output...)
output = append(output, sep...)
path := "content/discover/feed-" + f.Params.FeedID + ".md"
err = os.WriteFile(path, output, os.FileMode(int(0660)))
ohno(err)
}
type ScanFeedInfo struct {
Title string
Date string
Description string
FeedLink string
FeedID string
FeedType string
IsPodcast bool
IsNoarchive bool
}
//type Link struct {
// SourceType int64
// SourceURL string
// DestinationType int64
// DestinationURL string
//}
type LinkOnly struct {
Link string
}
type TypedLink struct {
Type int64
Link string
}
type RelMeClusterInfo struct {
Title string `yaml:"title"`
Params RelMeClusterParams `yaml:"params"`
}
type RelMeClusterParams struct {
VerifiedWebsites []string `yaml:"verifiedWebsites"`
UnverifiedWebsites []string `yaml:"unverifiedWebsites"`
Feeds map[string]FeedInfo `yaml:"feeds"`
}