Browse Source

refactor(subscription): improve wp-json skip

No need for an extra-condition, we can simply express the constrain in the
query instead.
jvoisin 1 month ago
parent
commit
0201c80db1
1 changed files with 7 additions and 7 deletions
  1. 7 7
      internal/reader/subscription/finder.go

+ 7 - 7
internal/reader/subscription/finder.go

@@ -118,9 +118,13 @@ func (f *subscriptionFinder) FindSubscriptions(websiteURL, rssBridgeURL string,
 
 func (f *subscriptionFinder) findSubscriptionsFromWebPage(websiteURL, contentType string, body []byte) (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'], link[type='application/feed+json']": parser.FormatJSON,
+		"link[type='application/rss+xml']":   parser.FormatRSS,
+		"link[type='application/atom+xml']":  parser.FormatAtom,
+		"link[type='application/feed+json']": parser.FormatJSON,
+
+		// Ignore JSON feed URLs that contain "/wp-json/" to avoid confusion
+		// with WordPress REST API endpoints.
+		"link[type='application/json']:not([href*='/wp-json/'])": parser.FormatJSON,
 	}
 
 	htmlDocumentReader, err := encoding.NewCharsetReaderFromBytes(body, contentType)
@@ -148,10 +152,6 @@ func (f *subscriptionFinder) findSubscriptionsFromWebPage(websiteURL, contentTyp
 			subscription.Type = feedFormat
 
 			if feedURL, exists := s.Attr("href"); exists && feedURL != "" {
-				// Ignore JSON feed URLs that contain "wp-json" to avoid confusion with WordPress REST API endpoints.
-				if feedFormat == parser.FormatJSON && strings.Contains(feedURL, "wp-json") {
-					return
-				}
 				subscription.URL, err = urllib.ResolveToAbsoluteURL(websiteURL, feedURL)
 				if err != nil {
 					return