mirror of https://github.com/jlelse/GoBlog
Cover another case of #46
This commit is contained in:
parent
87e10cf68c
commit
6d25ba0029
|
@ -63,6 +63,11 @@ func (a *goBlog) checkPost(p *post, new bool) (err error) {
|
|||
// Has published date in the past, so add updated date
|
||||
p.Updated = nowString
|
||||
}
|
||||
} else if !new && p.Updated != "" {
|
||||
if updated, err := dateparse.ParseLocal(p.Updated); err == nil && now.After(updated) {
|
||||
// Has updated date in the past, so add new updated date
|
||||
p.Updated = nowString
|
||||
}
|
||||
}
|
||||
// Fix content
|
||||
p.Content = strings.TrimSuffix(strings.TrimPrefix(p.Content, "\n"), "\n")
|
||||
|
|
|
@ -478,4 +478,16 @@ func Test_checkPost(t *testing.T) {
|
|||
assert.NotEqual(t, oldUpdate, p.Updated)
|
||||
})
|
||||
|
||||
t.Run("Updated post with just updated date should get new updated date", func(t *testing.T) {
|
||||
oldUpdate := time.Now().Local().Add(-1 * time.Hour).Format(time.RFC3339)
|
||||
p := &post{
|
||||
Updated: oldUpdate,
|
||||
}
|
||||
app.checkPost(p, false)
|
||||
|
||||
assert.Empty(t, p.Published)
|
||||
assert.NotEmpty(t, p.Updated)
|
||||
assert.NotEqual(t, oldUpdate, p.Updated)
|
||||
})
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue