From 33445e5b681bbdffaf0925ed020ecdcc49687f15 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Mon, 11 Dec 2017 22:16:32 -0800 Subject: Add the possibility to define rewrite rules for each feed --- reader/processor/processor.go | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'reader/processor') diff --git a/reader/processor/processor.go b/reader/processor/processor.go index ef93b9a..06dad43 100644 --- a/reader/processor/processor.go +++ b/reader/processor/processor.go @@ -5,12 +5,37 @@ package processor import ( + "github.com/miniflux/miniflux2/model" "github.com/miniflux/miniflux2/reader/rewrite" "github.com/miniflux/miniflux2/reader/sanitizer" ) -// ItemContentProcessor executes a set of functions to sanitize and alter item contents. -func ItemContentProcessor(url, content string) string { - content = sanitizer.Sanitize(url, content) - return rewrite.Rewriter(url, content) +// FeedProcessor handles the processing of feed contents. +type FeedProcessor struct { + feed *model.Feed + scraperRules string + rewriteRules string +} + +// WithScraperRules adds scraper rules to the processing. +func (f *FeedProcessor) WithScraperRules(rules string) { + f.scraperRules = rules +} + +// WithRewriteRules adds rewrite rules to the processing. +func (f *FeedProcessor) WithRewriteRules(rules string) { + f.rewriteRules = rules +} + +// Process applies rewrite and scraper rules. +func (f *FeedProcessor) Process() { + for _, entry := range f.feed.Entries { + entry.Content = sanitizer.Sanitize(entry.URL, entry.Content) + entry.Content = rewrite.Rewriter(entry.URL, entry.Content, f.rewriteRules) + } +} + +// NewFeedProcessor returns a new FeedProcessor. +func NewFeedProcessor(feed *model.Feed) *FeedProcessor { + return &FeedProcessor{feed: feed} } -- cgit v1.2.3