1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-09-15 18:57:04 +00:00

Add scraper rules

This commit is contained in:
Frédéric Guillot 2017-12-10 20:51:04 -08:00
parent 7a35c58f53
commit 87ccad5c7f
16 changed files with 140 additions and 34 deletions

View file

@ -40,18 +40,14 @@ func (c *Controller) FetchContent(ctx *core.Context, request *core.Request, resp
return
}
content, err := scraper.Fetch(entry.URL)
content, err := scraper.Fetch(entry.URL, entry.Feed.ScraperRules)
if err != nil {
response.JSON().ServerError(err)
return
}
if len(content) > len(entry.Content) {
entry.Content = content
c.store.UpdateEntryContent(entry)
} else {
content = entry.Content
}
entry.Content = content
c.store.UpdateEntryContent(entry)
response.JSON().Created(map[string]string{"content": content})
}

View file

@ -217,10 +217,11 @@ func (c *Controller) getFeedFormTemplateArgs(ctx *core.Context, user *model.User
if feedForm == nil {
args["form"] = form.FeedForm{
SiteURL: feed.SiteURL,
FeedURL: feed.FeedURL,
Title: feed.Title,
CategoryID: feed.Category.ID,
SiteURL: feed.SiteURL,
FeedURL: feed.FeedURL,
Title: feed.Title,
ScraperRules: feed.ScraperRules,
CategoryID: feed.Category.ID,
}
} else {
args["form"] = feedForm

View file

@ -14,10 +14,11 @@ import (
// FeedForm represents a feed form in the UI
type FeedForm struct {
FeedURL string
SiteURL string
Title string
CategoryID int64
FeedURL string
SiteURL string
Title string
ScraperRules string
CategoryID int64
}
// ValidateModification validates FeedForm fields
@ -34,6 +35,7 @@ func (f FeedForm) Merge(feed *model.Feed) *model.Feed {
feed.Title = f.Title
feed.SiteURL = f.SiteURL
feed.FeedURL = f.FeedURL
feed.ScraperRules = f.ScraperRules
feed.ParsingErrorCount = 0
feed.ParsingErrorMsg = ""
return feed
@ -47,9 +49,10 @@ func NewFeedForm(r *http.Request) *FeedForm {
}
return &FeedForm{
FeedURL: r.FormValue("feed_url"),
SiteURL: r.FormValue("site_url"),
Title: r.FormValue("title"),
CategoryID: int64(categoryID),
FeedURL: r.FormValue("feed_url"),
SiteURL: r.FormValue("site_url"),
Title: r.FormValue("title"),
ScraperRules: r.FormValue("scraper_rules"),
CategoryID: int64(categoryID),
}
}