Omit empty First value and only set on New with items>0

Supports fixing writefreely/writefreely#1698
This commit is contained in:
Matt Baer
2026-07-18 12:09:59 -04:00
parent 52f92a2d92
commit f286ddb713
+6 -2
View File
@@ -30,7 +30,7 @@ type (
type OrderedCollection struct {
BaseObject
TotalItems int `json:"totalItems"`
First string `json:"first"`
First string `json:"first,omitempty"`
Last string `json:"last,omitempty"`
}
@@ -43,9 +43,13 @@ func NewOrderedCollection(accountRoot, collType string, items int) *OrderedColle
ID: accountRoot + "/" + collType,
Type: "OrderedCollection",
},
First: accountRoot + "/" + collType + "?page=1",
TotalItems: items,
}
if items > 0 {
// Next page should only be indicated if there are potentially items on it. NOTE: with no knowledge of items-
// per-page, this still may need to be altered by the func caller.
oc.First = accountRoot + "/" + collType + "?page=1"
}
return &oc
}