Documentation
¶
Overview ¶
Package post defines the content object at the center of the CMS.
Index ¶
Constants ¶
const TypePost = "post"
TypePost is the name of the built-in post type.
Variables ¶
var ErrConflict = errors.New("post: conflicting update")
ErrConflict reports that the post changed after the update was prepared.
var ErrInvalidAuthor = errors.New("post: invalid author")
ErrInvalidAuthor reports that a post carries no author.
var ErrInvalidOrder = errors.New("post: invalid order")
ErrInvalidOrder reports that a sort direction is not one the CMS sorts in.
var ErrInvalidOrderBy = errors.New("post: invalid orderby")
ErrInvalidOrderBy reports that a sort column is not one the CMS sorts by.
var ErrInvalidStatus = errors.New("post: invalid status")
ErrInvalidStatus reports that a status value is not one the CMS stores.
var ErrInvalidTransition = errors.New("post: invalid status transition")
ErrInvalidTransition reports that a status change is not allowed.
var ErrInvalidType = errors.New("post: invalid type")
ErrInvalidType reports that a post type is not registered.
var ErrNotFound = errors.New("post: not found")
ErrNotFound reports that no post exists for the requested ID.
var ErrRevisionNotFound = errors.New("post: revision not found")
ErrRevisionNotFound reports that no revision exists for the requested ID.
var ErrSlugTaken = errors.New("post: slug taken")
ErrSlugTaken reports that a post type already holds the requested slug.
Functions ¶
Types ¶
type Filter ¶
type Filter struct {
Type string
Status Status
Search string
OrderBy OrderBy
Order Order
Page int
PerPage int
}
Filter narrows a post listing.
type Order ¶
type Order string
Order names a sort direction.
The directions a listing can be sorted in.
func ParseOrder ¶
ParseOrder returns the direction named by raw, or ErrInvalidOrder.
type OrderBy ¶
type OrderBy string
OrderBy names a column a listing can be sorted by.
The columns a listing can be sorted by.
func ParseOrderBy ¶
ParseOrderBy returns the column named by raw, or ErrInvalidOrderBy.
type Post ¶
type Post struct {
ID uuid.UUID
Type string
Slug string
Title string
Content string
Excerpt string
Status Status
AuthorID uuid.UUID
PublishedAt *time.Time
CreatedAt time.Time
UpdatedAt time.Time
}
Post is a content object holding Gutenberg-serialized block HTML.
func (*Post) Restore ¶
Restore returns a trashed post to draft, or reports ErrInvalidTransition.
func (*Post) Transition ¶
Transition moves the post to the given status, stamping PublishedAt on the first publication and returning ErrInvalidTransition when disallowed.
type Revision ¶
type Revision struct {
ID uuid.UUID
PostID uuid.UUID
Kind RevisionKind
AuthorID uuid.UUID
Title string
Content string
Excerpt string
CreatedAt time.Time
}
Revision is a snapshot of a post's editable content.
func NewRevision ¶
NewRevision returns a snapshot of the post's editable content, credited to the given author.
type RevisionKind ¶
type RevisionKind string
RevisionKind distinguishes an update snapshot from a per-author autosave.
const ( RevisionKindRevision RevisionKind = "revision" RevisionKindAutosave RevisionKind = "autosave" )
The kinds of revision a post carries.
type Status ¶
type Status string
Status is the publication state of a post.
const ( StatusDraft Status = "draft" StatusPending Status = "pending" StatusPrivate Status = "private" StatusScheduled Status = "scheduled" StatusPublished Status = "published" StatusTrash Status = "trash" )
The statuses a post may hold. Scheduled is stored but unreachable until a publish worker exists.
func ParseStatus ¶
ParseStatus returns the Status named by value, or ErrInvalidStatus.
type Store ¶
type Store interface {
Create(ctx context.Context, p Post) (Post, error)
ByID(ctx context.Context, id uuid.UUID) (Post, error)
PublishedBySlug(ctx context.Context, postType, slug string) (Post, error)
List(ctx context.Context, f Filter) ([]Post, int, error)
Update(ctx context.Context, p Post, expectedUpdatedAt time.Time, snapshot *Revision, revisionCap int) (Post, error)
Trash(ctx context.Context, id uuid.UUID, updatedAt time.Time) (Post, error)
Restore(ctx context.Context, id uuid.UUID, updatedAt time.Time) (Post, error)
Delete(ctx context.Context, id uuid.UUID) error
Counts(ctx context.Context, postType string) (map[Status]int, error)
Revisions(ctx context.Context, postID uuid.UUID) ([]Revision, error)
RevisionByID(ctx context.Context, postID, revisionID uuid.UUID) (Revision, error)
DeleteRevision(ctx context.Context, postID, revisionID uuid.UUID) error
SaveAutosave(ctx context.Context, autosave Revision) (Revision, error)
Autosave(ctx context.Context, postID, authorID uuid.UUID) (Revision, error)
DeleteAutosave(ctx context.Context, postID, authorID uuid.UUID) error
}
Store persists posts and their revisions.
type Type ¶
type Type struct {
Name string
Label string
Hierarchical bool
Revisions bool
// RevisionCap bounds the revisions kept per post. Zero keeps every revision.
RevisionCap int
}
Type describes a kind of content the CMS stores.
func TypeByName ¶
TypeByName returns the registered type of the given name.