|
|
@@ -2,7 +2,7 @@
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
-package filter
|
|
|
+package processor
|
|
|
|
|
|
import (
|
|
|
"miniflux.app/logger"
|
|
|
@@ -13,15 +13,15 @@ import (
|
|
|
"miniflux.app/storage"
|
|
|
)
|
|
|
|
|
|
-// Apply executes all entry filters.
|
|
|
-func Apply(store *storage.Storage, feed *model.Feed) {
|
|
|
+// ProcessFeedEntries downloads original web page for entries and apply filters.
|
|
|
+func ProcessFeedEntries(store *storage.Storage, feed *model.Feed) {
|
|
|
for _, entry := range feed.Entries {
|
|
|
if feed.Crawler {
|
|
|
if !store.EntryURLExists(feed.UserID, entry.URL) {
|
|
|
content, err := scraper.Fetch(entry.URL, feed.ScraperRules, feed.UserAgent)
|
|
|
if err != nil {
|
|
|
- logger.Error("Unable to crawl this entry: %q => %v", entry.URL, err)
|
|
|
- } else {
|
|
|
+ logger.Error(`[Filter] Unable to crawl this entry: %q => %v`, entry.URL, err)
|
|
|
+ } else if content != "" {
|
|
|
// We replace the entry content only if the scraper doesn't return any error.
|
|
|
entry.Content = content
|
|
|
}
|
|
|
@@ -34,3 +34,20 @@ func Apply(store *storage.Storage, feed *model.Feed) {
|
|
|
entry.Content = sanitizer.Sanitize(entry.URL, entry.Content)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// ProcessEntryWebPage downloads the entry web page and apply rewrite rules.
|
|
|
+func ProcessEntryWebPage(entry *model.Entry) error {
|
|
|
+ content, err := scraper.Fetch(entry.URL, entry.Feed.ScraperRules, entry.Feed.UserAgent)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ content = rewrite.Rewriter(entry.URL, content, entry.Feed.RewriteRules)
|
|
|
+ content = sanitizer.Sanitize(entry.URL, content)
|
|
|
+
|
|
|
+ if content != "" {
|
|
|
+ entry.Content = content
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|