fix: skip posts with empty date

This commit is contained in:
Egor Aristov 2025-02-02 15:33:49 +03:00
parent 593e1ac7d1
commit 0d7c238e65
Signed by: egor3f
GPG Key ID: 40482A264AAEC85F
2 changed files with 6 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package dateparser
import (
"fmt"
godateparser "github.com/markusmobius/go-dateparser"
"strings"
"time"
@ -13,6 +14,10 @@ type DateParser struct {
func (d *DateParser) ParseDate(str string) (time.Time, error) {
str = strings.TrimSpace(str)
if len(str) == 0 {
return time.Time{}, fmt.Errorf("date string is empty")
}
dt, err := godateparser.Parse(&godateparser.Configuration{
CurrentTime: d.CurrentTimeFunc(),
}, str)

View File

@ -287,7 +287,7 @@ func (p *pageParser) parse() (*models.TaskResult, error) {
log.Errorf("extract post fields: %v", err)
continue
}
if len(item.Title) == 0 || len(item.Link) == 0 {
if len(item.Title) == 0 || len(item.Link) == 0 || item.Created.IsZero() {
log.Warnf("post has no required fields, skip")
continue
}