fix: skip posts with empty date
This commit is contained in:
parent
bdccf591a8
commit
b1d28b62e5
@ -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)
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user