+2
-5
internal/rss/feed.go
+2
-5
internal/rss/feed.go
···
41
}
42
43
// Limit the number of items to return
44
-
maxItems := len(feed.Items)
45
-
items := make([]*FeedItem, 0, maxItems)
46
-
for i := 0; i < maxItems; i++ {
47
-
item := feed.Items[i]
48
-
49
published := time.Now()
50
if item.PublishedParsed != nil {
51
published = *item.PublishedParsed
+31
-11
main.go
+31
-11
main.go
···
5
"flag"
6
"fmt"
7
"log"
8
"os"
9
"os/signal"
10
"strings"
···
242
}
243
244
func formatPost(item *rss.FeedItem) string {
245
-
// Start with title
246
-
text := item.Title
247
248
-
// Add link if available
249
-
if item.Link != "" {
250
-
text += "\n\n" + item.Link
251
}
252
253
// Truncate if too long
254
if len(text) > maxPostLength {
255
-
// Try to truncate title intelligently
256
-
maxTitleLen := maxPostLength - len(item.Link) - 5 // 5 for "\n\n" and "..."
257
-
if maxTitleLen > 0 {
258
-
text = truncateText(item.Title, maxTitleLen) + "...\n\n" + item.Link
259
} else {
260
-
// If even with minimal title it's too long, just use the link
261
-
text = item.Link
262
}
263
}
264
···
5
"flag"
6
"fmt"
7
"log"
8
+
"net/url"
9
"os"
10
"os/signal"
11
"strings"
···
243
}
244
245
func formatPost(item *rss.FeedItem) string {
246
+
// Collect all unique URLs
247
+
urls := []string{}
248
+
if item.Link != "" {
249
+
urls = append(urls, item.Link)
250
+
}
251
+
252
+
// Add GUID if it's a URL and different from link (e.g., HN comment links)
253
+
if item.GUID != "" && item.GUID != item.Link {
254
+
if u, err := url.Parse(item.GUID); err == nil && (u.Scheme == "http" || u.Scheme == "https") {
255
+
urls = append(urls, item.GUID)
256
+
}
257
+
}
258
259
+
// Build post: title + links
260
+
text := item.Title
261
+
if len(urls) > 0 {
262
+
text += "\n" + strings.Join(urls, "\n")
263
}
264
265
// Truncate if too long
266
if len(text) > maxPostLength {
267
+
linkText := ""
268
+
if len(urls) > 0 {
269
+
linkText = "\n" + strings.Join(urls, "\n")
270
+
}
271
+
272
+
availableForTitle := maxPostLength - len(linkText) - 3 // 3 for "..."
273
+
if availableForTitle > 20 {
274
+
text = truncateText(item.Title, availableForTitle) + "..." + linkText
275
} else {
276
+
// Title too long even truncated, use just first URL or truncated title
277
+
if len(urls) > 0 {
278
+
text = urls[0]
279
+
} else {
280
+
text = truncateText(item.Title, maxPostLength-3) + "..."
281
+
}
282
}
283
}
284