Skip to content

Commit

Permalink
set the updated to nil when the entry is still draft
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Oct 14, 2023
1 parent 2e2bbd7 commit 05aea5a
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,31 @@ func entryFromAtom(e *atom.Entry) (*entry, error) {
categories = append(categories, c.Term)
}

entry := &entry{
var isDraft bool
if e.Control != nil && e.Control.Draft == "yes" {
isDraft = true
}

// Set the updated to nil when the entry is still draft.
// But if the date is in the future, don't set to nil because it may be a reserved post.
updated := e.Updated
if updated != nil && isDraft && !time.Now().Before(*updated) {
updated = nil
}

return &entry{
entryHeader: &entryHeader{
URL: &entryURL{u},
EditURL: editLink.Href,
Title: e.Title,
Category: categories,
Date: e.Updated,
Date: updated,
IsDraft: isDraft,
},
LastModified: e.Edited,
Content: e.Content.Content,
ContentType: e.Content.Type,
}

if e.Control != nil && e.Control.Draft == "yes" {
entry.IsDraft = true
}

return entry, nil
}, nil
}

var delimReg = regexp.MustCompile(`---\n+`)
Expand All @@ -180,6 +187,11 @@ func entryFromReader(source io.Reader) (*entry, error) {
if err != nil {
return nil, err
}
// Set the updated to nil when the entry is still draft.
// But if the date is in the future, don't set to nil because it may be a reserved post.
if eh.IsDraft && eh.Date != nil && !time.Now().Before(*eh.Date) {
eh.Date = nil
}
content = c[2]
}
entry := &entry{
Expand Down

0 comments on commit 05aea5a

Please sign in to comment.