Cover another case of #46

This commit is contained in:
Jan-Lukas Else 2022-12-25 21:06:23 +01:00
parent 87e10cf68c
commit 6d25ba0029
2 changed files with 17 additions and 0 deletions

View File

@ -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")

View File

@ -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)
})
}