fix: skip posts with empty date
This commit is contained in:
parent
bdccf591a8
commit
b1d28b62e5
@ -1,6 +1,7 @@
|
|||||||
package dateparser
|
package dateparser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
godateparser "github.com/markusmobius/go-dateparser"
|
godateparser "github.com/markusmobius/go-dateparser"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -13,6 +14,10 @@ type DateParser struct {
|
|||||||
func (d *DateParser) ParseDate(str string) (time.Time, error) {
|
func (d *DateParser) ParseDate(str string) (time.Time, error) {
|
||||||
str = strings.TrimSpace(str)
|
str = strings.TrimSpace(str)
|
||||||
|
|
||||||
|
if len(str) == 0 {
|
||||||
|
return time.Time{}, fmt.Errorf("date string is empty")
|
||||||
|
}
|
||||||
|
|
||||||
dt, err := godateparser.Parse(&godateparser.Configuration{
|
dt, err := godateparser.Parse(&godateparser.Configuration{
|
||||||
CurrentTime: d.CurrentTimeFunc(),
|
CurrentTime: d.CurrentTimeFunc(),
|
||||||
}, str)
|
}, str)
|
||||||
|
|||||||
@ -287,7 +287,7 @@ func (p *pageParser) parse() (*models.TaskResult, error) {
|
|||||||
log.Errorf("extract post fields: %v", err)
|
log.Errorf("extract post fields: %v", err)
|
||||||
continue
|
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")
|
log.Warnf("post has no required fields, skip")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user