internal/aggregator/article.go (view raw)
1package aggregator
2
3import "time"
4
5// Article represents an article extracted from an RSS feed.
6type Article struct {
7 Title string `json:"title"`
8 Link string `json:"link"`
9 Content string `json:"content"`
10 Published time.Time `json:"published"`
11 Author string `json:"author,omitempty"`
12 SourceFeed string `json:"source_feed,omitempty"`
13 Summary string `json:"summary,omitempty"`
14}
15
16// ToMap converts article to a map for serialisation.
17func (a *Article) ToMap() map[string]any {
18 content := a.Content
19 if len(content) > 500 {
20 content = content[:500] + "... [truncated]"
21 }
22
23 result := map[string]any{
24 "title": a.Title,
25 "link": a.Link,
26 "content": content,
27 "author": a.Author,
28 "source_feed": a.SourceFeed,
29 "summary": a.Summary,
30 }
31
32 if !a.Published.IsZero() {
33 result["published"] = a.Published.Format(time.RFC3339)
34 }
35
36 return result
37}
38