filter.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package filter
  5. import (
  6. "miniflux.app/logger"
  7. "miniflux.app/model"
  8. "miniflux.app/reader/rewrite"
  9. "miniflux.app/reader/sanitizer"
  10. "miniflux.app/reader/scraper"
  11. "miniflux.app/storage"
  12. )
  13. // Apply executes all entry filters.
  14. func Apply(store *storage.Storage, feed *model.Feed) {
  15. for _, entry := range feed.Entries {
  16. if feed.Crawler {
  17. if !store.EntryURLExists(feed.UserID, entry.URL) {
  18. content, err := scraper.Fetch(entry.URL, feed.ScraperRules, feed.UserAgent)
  19. if err != nil {
  20. logger.Error("Unable to crawl this entry: %q => %v", entry.URL, err)
  21. } else {
  22. // We replace the entry content only if the scraper doesn't return any error.
  23. entry.Content = content
  24. }
  25. }
  26. }
  27. entry.Content = rewrite.Rewriter(entry.URL, entry.Content, feed.RewriteRules)
  28. // The sanitizer should always run at the end of the process to make sure unsafe HTML is filtered.
  29. entry.Content = sanitizer.Sanitize(entry.URL, entry.Content)
  30. }
  31. }