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 8bcca2b
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type entryURL struct {
type entryHeader struct {
Title string `yaml:"Title"`
Category []string `yaml:"Category,omitempty"`
Date *time.Time `yaml:"Date"`
Date *time.Time `yaml:"Date,omitempty"`
URL *entryURL `yaml:"URL"`
EditURL string `yaml:"EditURL"`
IsDraft bool `yaml:"Draft,omitempty"`
Expand Down 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 8bcca2b

Please sign in to comment.