diff --git a/postsDb.go b/postsDb.go index ecf0287..3176688 100644 --- a/postsDb.go +++ b/postsDb.go @@ -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") diff --git a/postsDb_test.go b/postsDb_test.go index 7c950d2..6bc3f74 100644 --- a/postsDb_test.go +++ b/postsDb_test.go @@ -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) + }) + }