Subscribe and post RSS feeds to Bluesky
rss bluesky

refactor: improve bsky post

Changed files
+33 -16
internal
rss
+2 -5
internal/rss/feed.go
··· 41 41 } 42 42 43 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 - 44 + items := make([]*FeedItem, 0, len(feed.Items)) 45 + for _, item := range feed.Items { 49 46 published := time.Now() 50 47 if item.PublishedParsed != nil { 51 48 published = *item.PublishedParsed
+31 -11
main.go
··· 5 5 "flag" 6 6 "fmt" 7 7 "log" 8 + "net/url" 8 9 "os" 9 10 "os/signal" 10 11 "strings" ··· 242 243 } 243 244 244 245 func formatPost(item *rss.FeedItem) string { 245 - // Start with title 246 - text := item.Title 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 + } 247 258 248 - // Add link if available 249 - if item.Link != "" { 250 - text += "\n\n" + item.Link 259 + // Build post: title + links 260 + text := item.Title 261 + if len(urls) > 0 { 262 + text += "\n" + strings.Join(urls, "\n") 251 263 } 252 264 253 265 // Truncate if too long 254 266 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 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 259 275 } else { 260 - // If even with minimal title it's too long, just use the link 261 - text = item.Link 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 + } 262 282 } 263 283 } 264 284