Adds ListPosts(ctx, ListPostsParams) to the content.Content capability so
wasm plugins can list posts with bodies — the per-plugin Postgres role
denies direct public.blog_posts reads (42501) and GetPost only fetches a
single post's metadata. Extends PostInfo with Body, AuthorName, AuthorSlug
and PublishedAt (additive; existing get_post golden unchanged). Wires all
layers: interface, ABI PostInfo/ContentListPosts{Request,Response} messages
(buf breaking clean), guest stub, and a deterministic content_list_posts
golden replayed by the cms host parity test.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
69 lines
2.3 KiB
Go
69 lines
2.3 KiB
Go
package content
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// AuthorProfile is a simplified author representation for plugins.
|
|
type AuthorProfile struct {
|
|
ID uuid.UUID
|
|
Name string
|
|
Slug string
|
|
Bio string
|
|
AvatarURL string
|
|
Website string
|
|
SocialLinks map[string]string
|
|
}
|
|
|
|
// PageInfo is a simplified page representation for plugins.
|
|
type PageInfo struct {
|
|
ID uuid.UUID
|
|
Slug string
|
|
Title string
|
|
}
|
|
|
|
// PostInfo is a simplified post representation for plugins. It carries enough
|
|
// for both a blog index (title/slug/excerpt/author/date/featured image) and a
|
|
// post detail view (Body — the rendered HTML). Body is populated by GetPost and
|
|
// by ListPosts when ListPostsParams.IncludeBody is set; it is empty otherwise.
|
|
type PostInfo struct {
|
|
ID uuid.UUID
|
|
Slug string
|
|
Title string
|
|
Excerpt string
|
|
Body string // rendered HTML; populated by GetPost / ListPosts(IncludeBody)
|
|
FeaturedImageURL string
|
|
AuthorID uuid.UUID
|
|
AuthorName string
|
|
AuthorSlug string
|
|
PublishedAt time.Time
|
|
}
|
|
|
|
// ListPostsParams filters and shapes a ListPosts query. The zero value lists
|
|
// published posts from the start with no category filter, excerpts included and
|
|
// bodies omitted (the cheap blog-index shape).
|
|
type ListPostsParams struct {
|
|
Limit int // 0 = host default
|
|
Offset int // pagination offset
|
|
Category string // optional category slug filter ("" = all)
|
|
PublishedOnly bool // reserved: plugins only ever see published posts
|
|
IncludeBody bool // render each post's body to HTML (expensive)
|
|
IncludeExcerpt bool // include the post excerpt
|
|
}
|
|
|
|
// Content provides content access for plugins.
|
|
// The CMS implements this interface and wires it into CoreServices.
|
|
type Content interface {
|
|
GetAuthorProfile(ctx context.Context, id uuid.UUID) (*AuthorProfile, error)
|
|
GetPage(ctx context.Context, slug string) (*PageInfo, error)
|
|
GetPost(ctx context.Context, slug string) (*PostInfo, error)
|
|
ListPosts(ctx context.Context, params ListPostsParams) ([]PostInfo, error)
|
|
Slugify(text string) string
|
|
BlockNoteToHTML(ctx context.Context, doc map[string]any) string
|
|
GenerateExcerpt(html string, maxLen int) string
|
|
StripHTML(s string) string
|
|
}
|