From e73515bec350f573702af33d309d7556321f0dd5 Mon Sep 17 00:00:00 2001 From: Egor Aristov Date: Sat, 25 Jan 2025 18:28:19 +0300 Subject: [PATCH] allow empty description or content --- internal/delivery/http/handler.go | 4 ++-- internal/extractors/pwextractor/pwextractor.go | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/delivery/http/handler.go b/internal/delivery/http/handler.go index bda2a4a..8a002b2 100644 --- a/internal/delivery/http/handler.go +++ b/internal/delivery/http/handler.go @@ -50,10 +50,10 @@ type Specs struct { SelectorPost string `json:"selector_post" validate:"selector"` SelectorTitle string `json:"selector_title" validate:"selector"` SelectorLink string `json:"selector_link" validate:"selector"` - SelectorDescription string `json:"selector_description" validate:"selector"` + SelectorDescription string `json:"selector_description" validate:"omitempty,selector"` SelectorAuthor string `json:"selector_author" validate:"selector"` SelectorCreated string `json:"selector_created" validate:"selector"` - SelectorContent string `json:"selector_content" validate:"selector"` + SelectorContent string `json:"selector_content" validate:"omitempty,selector"` SelectorEnclosure string `json:"selector_enclosure" validate:"selector"` CacheLifetime string `json:"cache_lifetime"` } diff --git a/internal/extractors/pwextractor/pwextractor.go b/internal/extractors/pwextractor/pwextractor.go index 18e346c..aacc29f 100644 --- a/internal/extractors/pwextractor/pwextractor.go +++ b/internal/extractors/pwextractor/pwextractor.go @@ -287,14 +287,18 @@ func (p *pageParser) extractPost(post playwright.Locator) (models.FeedItem, erro page, _ := post.Page() item.Link = absUrl(item.Link, page) - item.Description = p.must(post.Locator(p.task.SelectorDescription).First().InnerText(defOptInText)) + if len(p.task.SelectorDescription) > 0 { + item.Description = p.must(post.Locator(p.task.SelectorDescription).First().InnerText(defOptInText)) + } item.AuthorName = p.must(post.Locator(p.task.SelectorAuthor).First().InnerText(defOptInText)) item.AuthorLink = p.must(post.Locator(p.task.SelectorAuthor).First().GetAttribute("href", defOptAttr)) item.AuthorLink = absUrl(item.AuthorLink, page) - item.Content = p.extractContent(post) + if len(p.task.SelectorContent) > 0 { + item.Content = p.extractContent(post) + } item.Enclosure = p.must(post.Locator(p.task.SelectorEnclosure).First().GetAttribute("src", defOptAttr))