From db6c54f3bf76494a322ca71043927deb788a18a5 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Mon, 3 Jan 2022 14:23:25 +0100 Subject: [PATCH] Fix Microformats query for post, schedule post if it's posted without status and published time is in the future --- postsDb.go | 10 ++++++++++ postsFuncs.go | 11 ++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/postsDb.go b/postsDb.go index 13cd555..0e9c192 100644 --- a/postsDb.go +++ b/postsDb.go @@ -37,6 +37,16 @@ func (a *goBlog) checkPost(p *post) (err error) { // Check status if p.Status == "" { p.Status = statusPublished + if p.Published != "" { + // If published time is in the future, set status to scheduled + publishedTime, err := dateparse.ParseLocal(p.Published) + if err != nil { + return err + } + if publishedTime.After(time.Now()) { + p.Status = statusScheduled + } + } } // Cleanup params for key, value := range p.Parameters { diff --git a/postsFuncs.go b/postsFuncs.go index 7b4433d..5d5fee8 100644 --- a/postsFuncs.go +++ b/postsFuncs.go @@ -155,15 +155,20 @@ func (a *goBlog) postToMfItem(p *post) *microformatItem { switch p.Status { case statusDraft: mfStatus = "draft" - case statusPublished, statusScheduled: + case statusPublished, statusScheduled, statusUnlisted, statusPrivate: mfStatus = "published" + case statusPublishedDeleted, statusDraftDeleted, statusPrivateDeleted, statusUnlistedDeleted, statusScheduledDeleted: + mfStatus = "deleted" + } + switch p.Status { + case statusDraft, statusScheduled, statusPublished: mfVisibility = "public" case statusUnlisted: - mfStatus = "published" mfVisibility = "unlisted" case statusPrivate: - mfStatus = "published" mfVisibility = "private" + case statusPublishedDeleted, statusDraftDeleted, statusPrivateDeleted, statusUnlistedDeleted, statusScheduledDeleted: + mfVisibility = "deleted" } return µformatItem{ Type: []string{"h-entry"},