diff --git a/micropub.go b/micropub.go index 4b11834..64b2349 100644 --- a/micropub.go +++ b/micropub.go @@ -465,7 +465,6 @@ func (s *micropubImplementation) updatePostPropertiesFromMf(p *post, properties // Ignore the following properties delete(properties, "url") - delete(properties, "post-status") delete(properties, "photo") delete(properties, "photo-alt") @@ -492,6 +491,12 @@ func (s *micropubImplementation) updatePostPropertiesFromMf(p *post, properties delete(properties, "mp-channel") p.Visibility = postVisibility(defaultIfEmpty(getFirstStringFromArray(properties["visibility"]), string(p.Visibility))) delete(properties, "visibility") + if newStatusString := getFirstStringFromArray(properties["post-status"]); newStatusString != "" { + if newStatus := postStatus(newStatusString); newStatus == statusPublished || newStatus == statusDraft { + p.Status = newStatus + } + } + delete(properties, "post-status") for key, value := range properties { p.Parameters[s.mapToParameterName(key)] = cast.ToStringSlice(value) diff --git a/micropub_test.go b/micropub_test.go index d162a3e..b050751 100644 --- a/micropub_test.go +++ b/micropub_test.go @@ -279,7 +279,7 @@ func Test_micropubUpdate(t *testing.T) { "category": {"test"}, "random": {"def"}, "content": {"New test"}, - "post-status": {"published-deleted"}, + "post-status": {"draft"}, "visibility": {"unlisted"}, }, }, @@ -292,11 +292,40 @@ func Test_micropubUpdate(t *testing.T) { assert.Equal(t, []string{"test"}, p.Parameters["tags"]) assert.Equal(t, []string{"def"}, p.Parameters["random"]) assert.Equal(t, "New test", p.Content) - assert.Equal(t, statusPublished, p.Status) + assert.Equal(t, statusDraft, p.Status) assert.Nil(t, p.Parameters["post-status"]) assert.Equal(t, visibilityUnlisted, p.Visibility) }) + t.Run("Replace wrong status", func(t *testing.T) { + postPath := "/replace2" + + err := app.createPost(&post{ + Path: postPath, + Content: "", + Status: statusPublished, + Visibility: visibilityPublic, + Parameters: map[string][]string{}, + }) + require.NoError(t, err) + + _, err = app.getMicropubImplementation().Update(µpub.Request{ + URL: app.cfg.Server.PublicAddress + postPath, + Updates: micropub.RequestUpdate{ + Replace: map[string][]any{ + "post-status": {"published-deleted"}, + }, + }, + }) + require.NoError(t, err) + + p, err := app.getPost(postPath) + require.NoError(t, err) + + assert.Equal(t, statusPublished, p.Status) + assert.Nil(t, p.Parameters["post-status"]) + }) + t.Run("Add", func(t *testing.T) { postPath := "/add1"