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) {
queries := map[string]string{
"link[type='application/rss+xml']": parser.FormatRSS,
"link[type='application/atom+xml']": parser.FormatAtom,
"link[type='application/json']": parser.FormatJSON,
"link[type='application/feed+json']": parser.FormatJSON,
"link[type='application/rss+xml']": parser.FormatRSS,
"link[type='application/atom+xml']": parser.FormatAtom,
"link[type='application/json'], link[type='application/feed+json']": parser.FormatJSON,
}
htmlDocumentReader, err := encoding.NewCharsetReader(body, contentType)
@ -154,24 +153,24 @@ func (f *subscriptionFinder) findSubscriptionsFromWebPage(websiteURL, contentTyp
subscription := new(subscription)
subscription.Type = kind
if title, exists := s.Attr("title"); exists {
subscription.Title = title
if feedURL, exists := s.Attr("href"); exists && feedURL != "" {
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 feedURL != "" {
subscription.URL, err = urllib.AbsoluteURL(websiteURL, feedURL)
if err != nil {
return
}
}
if title, exists := s.Attr("title"); exists {
subscription.Title = title
}
if subscription.Title == "" {
subscription.Title = subscription.URL
}
if subscription.URL != "" && !subscriptionURLs[subscription.URL] {
if !subscriptionURLs[subscription.URL] {
subscriptionURLs[subscription.URL] = true
subscriptions = append(subscriptions, subscription)
}

View file

@ -390,7 +390,7 @@ func TestParseWebPageWithMultipleFeeds(t *testing.T) {
<html>
<head>
<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>
<body>
</body>