1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-09-15 18:57:04 +00:00

refactor(subscription): combine all JSON feed mime types in one query

- Look for JSON feeds in one pass instead of two
- Move conditions around to reduce the amount of comparisons
- Edit an existing test to exercise this commit's changes
This commit is contained in:
Julien Voisin 2025-09-11 01:50:40 +02:00 committed by GitHub
parent da8d4d86c3
commit 8f2dd02f3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 15 deletions

View file

@ -124,10 +124,9 @@ func (f *subscriptionFinder) FindSubscriptions(websiteURL, rssBridgeURL string,
func (f *subscriptionFinder) findSubscriptionsFromWebPage(websiteURL, contentType string, body io.Reader) (Subscriptions, *locale.LocalizedErrorWrapper) { func (f *subscriptionFinder) findSubscriptionsFromWebPage(websiteURL, contentType string, body io.Reader) (Subscriptions, *locale.LocalizedErrorWrapper) {
queries := map[string]string{ queries := map[string]string{
"link[type='application/rss+xml']": parser.FormatRSS, "link[type='application/rss+xml']": parser.FormatRSS,
"link[type='application/atom+xml']": parser.FormatAtom, "link[type='application/atom+xml']": parser.FormatAtom,
"link[type='application/json']": parser.FormatJSON, "link[type='application/json'], link[type='application/feed+json']": parser.FormatJSON,
"link[type='application/feed+json']": parser.FormatJSON,
} }
htmlDocumentReader, err := encoding.NewCharsetReader(body, contentType) htmlDocumentReader, err := encoding.NewCharsetReader(body, contentType)
@ -154,24 +153,24 @@ func (f *subscriptionFinder) findSubscriptionsFromWebPage(websiteURL, contentTyp
subscription := new(subscription) subscription := new(subscription)
subscription.Type = kind subscription.Type = kind
if title, exists := s.Attr("title"); exists { if feedURL, exists := s.Attr("href"); exists && feedURL != "" {
subscription.Title = title subscription.URL, err = urllib.AbsoluteURL(websiteURL, feedURL)
if err != nil {
return
}
} else {
return // without an url, there can be no subscription.
} }
if feedURL, exists := s.Attr("href"); exists { if title, exists := s.Attr("title"); exists {
if feedURL != "" { subscription.Title = title
subscription.URL, err = urllib.AbsoluteURL(websiteURL, feedURL)
if err != nil {
return
}
}
} }
if subscription.Title == "" { if subscription.Title == "" {
subscription.Title = subscription.URL subscription.Title = subscription.URL
} }
if subscription.URL != "" && !subscriptionURLs[subscription.URL] { if !subscriptionURLs[subscription.URL] {
subscriptionURLs[subscription.URL] = true subscriptionURLs[subscription.URL] = true
subscriptions = append(subscriptions, subscription) subscriptions = append(subscriptions, subscription)
} }

View file

@ -390,7 +390,7 @@ func TestParseWebPageWithMultipleFeeds(t *testing.T) {
<html> <html>
<head> <head>
<link href="http://example.org/atom.xml" rel="alternate" type="application/atom+xml" title="Atom Feed"> <link href="http://example.org/atom.xml" rel="alternate" type="application/atom+xml" title="Atom Feed">
<link href="http://example.org/feed.json" rel="alternate" type="application/feed+json" title="JSON Feed"> <link href="http://example.org/feed.json" rel="alternate" type="application/json" title="JSON Feed">
</head> </head>
<body> <body>
</body> </body>