Skip to content

Commit dbae00f

Browse files
Fix: send null feature_image to Ghost when field is cleared in front-matter
Previously FeatureImage used omitempty so removing it from the markdown produced no JSON field — Ghost ignored the update and kept the old image. Change to *string without omitempty: nil pointer marshals to JSON null, which Ghost interprets as clear-the-field. Also removes the upsert.go guard that was zeroing FeatureImage on updates, since that guard existed only to prevent the omitempty-era empty-string from accidentally nuking the image.
1 parent c45056b commit dbae00f

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

cmd/ghostpost/publish.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ func publishCmd() *cobra.Command {
6969
}
7070
}
7171

72+
// featureImagePtr: nil sends JSON null (clears Ghost field); pointer sends the URL.
73+
var featureImagePtr *string
74+
if meta.FeatureImage != "" {
75+
featureImagePtr = &meta.FeatureImage
76+
}
77+
7278
var html bytes.Buffer
7379
if err := goldmark.Convert(md, &html); err != nil {
7480
return err
@@ -121,7 +127,7 @@ func publishCmd() *cobra.Command {
121127
Slug: meta.Slug,
122128
Status: defaultStatus(meta.Status),
123129
HTML: html.String(),
124-
FeatureImage: meta.FeatureImage,
130+
FeatureImage: featureImagePtr,
125131
Tags: api.WrapTags(meta.Tags),
126132
CustomExcerpt: meta.CustomExcerpt,
127133
PublishedAt: meta.PublishedAt,

internal/api/post.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type Post struct {
1212
Slug string `json:"slug,omitempty"`
1313
Status string `json:"status,omitempty"`
1414
HTML string `json:"html"`
15-
FeatureImage string `json:"feature_image,omitempty"`
15+
FeatureImage *string `json:"feature_image"`
1616
Tags []tagRef `json:"tags,omitempty"`
1717
CustomExcerpt string `json:"custom_excerpt,omitempty"`
1818
PublishedAt string `json:"published_at,omitempty"`

internal/api/upsert.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ func Upsert(c *Client, post Post, id string) (string, error) {
3030
post.ID = id
3131
post.UpdatedAt = current.UpdatedAt // required lock
3232
post.Tags = nil // leave unchanged
33-
post.FeatureImage = "" // leave unchanged
3433

3534
if err := c.Put(ctx, "posts/"+id+"/?source=html", postReq{Posts: []Post{post}}, &res); err != nil {
3635
return "", err

0 commit comments

Comments
 (0)