allow empty description or content

This commit is contained in:
Egor Aristov 2025-01-25 18:28:19 +03:00
parent 973a33f559
commit e73515bec3
2 changed files with 8 additions and 4 deletions

View File

@ -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"`
}

View File

@ -287,14 +287,18 @@ func (p *pageParser) extractPost(post playwright.Locator) (models.FeedItem, erro
page, _ := post.Page()
item.Link = absUrl(item.Link, page)
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)
if len(p.task.SelectorContent) > 0 {
item.Content = p.extractContent(post)
}
item.Enclosure = p.must(post.Locator(p.task.SelectorEnclosure).First().GetAttribute("src", defOptAttr))