A social RSS reader built on the AT Protocol. glean.at
glean atproto atmosphere rss feed social app
14
fork

Configure Feed

Select the types of activity you want to include in your feed.

Strip trailing slashes from favicon URLs

+13 -8
+10 -5
internal/feed/discover.go
··· 6 6 "net/http" 7 7 "net/url" 8 8 "regexp" 9 + "strings" 9 10 "time" 10 11 ) 11 12 ··· 22 23 relIconRe = regexp.MustCompile(`rel="[^"]*icon[^"]*"`) 23 24 baseHrefRe = regexp.MustCompile(`<base[^>]+href="([^"]*)"`) 24 25 25 - faviconPaths = []string{"/favicon.ico", "/favicon.png", "/apple-touch-icon.png"} 26 + faviconPaths = []string{"/favicon.ico", "/favicon.png", "/apple-touch-icon.png"} 26 27 discoverClient = &http.Client{Timeout: 15 * time.Second} 27 28 ) 28 29 ··· 45 46 }, nil 46 47 } 47 48 49 + func cleanFavicon(s string) string { 50 + return strings.TrimRight(s, "/") 51 + } 52 + 48 53 func ResolveFavicon(ctx context.Context, feedURL, siteURL, parsedFavicon string) string { 49 54 if parsedFavicon != "" { 50 - return parsedFavicon 55 + return cleanFavicon(parsedFavicon) 51 56 } 52 57 target := siteURL 53 58 if target == "" { ··· 57 62 if err != nil { 58 63 return "" 59 64 } 60 - return result.Favicon 65 + return cleanFavicon(result.Favicon) 61 66 } 62 67 63 68 func findFeedURLs(base *url.URL, links []string) []string { ··· 87 92 continue 88 93 } 89 94 if u, err := base.Parse(href); err == nil { 90 - return u.String() 95 + return cleanFavicon(u.String()) 91 96 } 92 97 } 93 98 ··· 109 114 } 110 115 resp.Body.Close() 111 116 if resp.StatusCode == http.StatusOK { 112 - return resolved.String() 117 + return cleanFavicon(resolved.String()) 113 118 } 114 119 } 115 120 return ""
+3 -3
internal/feed/parser.go
··· 151 151 Title: jf.Title, 152 152 SiteURL: jf.HomePageURL, 153 153 Description: jf.Description, 154 - FaviconURL: jf.Favicon, 154 + FaviconURL: cleanFavicon(jf.Favicon), 155 155 Type: "json", 156 156 }, 157 157 } ··· 222 222 Title: rss.Channel.Title, 223 223 SiteURL: rss.Channel.Link, 224 224 Description: rss.Channel.Description, 225 - FaviconURL: rss.Channel.Image.URL, 225 + FaviconURL: cleanFavicon(rss.Channel.Image.URL), 226 226 Type: "rss", 227 227 }, 228 228 } ··· 292 292 Title: atom.Title, 293 293 SiteURL: pickAtomLink(atom.Link), 294 294 Description: atom.Subtitle, 295 - FaviconURL: favicon, 295 + FaviconURL: cleanFavicon(favicon), 296 296 Type: "atom", 297 297 }, 298 298 }