feat(signpost): content descriptor fields for dates, parents, authors, media and outline
- pact.ContentDescriptor gains Kind and Tools with the ContentKind and ContentTool constants - pact.ContentRecord gains PublishedAt, Parents, Authors and TopHeading; pact.ContentLocale gains Images, Videos and Headings, with the value types ContentRef, ContentPerson, ContentImage, ContentVideo and ContentHeading; every field is optional - TestContentDescriptorFields proves signpost hands them through and that a type setting none of them describes as before - the runnable content example, the pact and signpost READMEs and the menu item types page document the fields
This commit is contained in:
@@ -21,14 +21,52 @@ import (
|
||||
// The functions read through cabana.TxFromContext(ctx) when ctx carries a
|
||||
// write transaction, so code running inside a save (a form extension's Save,
|
||||
// for example) sees the values the save has just written.
|
||||
//
|
||||
// Kind and Tools are optional facts about the type as a whole: what kind of
|
||||
// thing a record is (one of the ContentKind constants, "" when the type does
|
||||
// not say) and which MCP tools change its records, keyed by operation (the
|
||||
// ContentTool constants), so a consumer can point at a fixing tool without
|
||||
// importing the content plugin.
|
||||
type ContentDescriptor struct {
|
||||
Controller string
|
||||
Model string
|
||||
Records func(ctx context.Context, in ContentList) (ContentPage, error) `json:"-"`
|
||||
Describe func(ctx context.Context, in ContentDescribe) (*ContentRecord, error) `json:"-"`
|
||||
Match func(ctx context.Context, in ContentMatch) (*ContentMatchResult, error) `json:"-"`
|
||||
// Kind is what a record of the type is, one of the ContentKind constants;
|
||||
// "" when the type does not say.
|
||||
Kind string
|
||||
// Tools maps an operation (a ContentTool constant) to the full name of
|
||||
// the MCP tool that performs it on a record, such as "acme_update_page";
|
||||
// nil when the type names none.
|
||||
Tools map[string]string
|
||||
}
|
||||
|
||||
// The kinds a ContentDescriptor.Kind names.
|
||||
const (
|
||||
// ContentKindArticle is a dated piece with authors, such as a post.
|
||||
ContentKindArticle = "article"
|
||||
// ContentKindCollection is a record that lists other records, such as a
|
||||
// category or a tag.
|
||||
ContentKindCollection = "collection"
|
||||
// ContentKindProfile is a record about a person or an organisation.
|
||||
ContentKindProfile = "profile"
|
||||
// ContentKindPage is a standalone page.
|
||||
ContentKindPage = "page"
|
||||
)
|
||||
|
||||
// The operations a ContentDescriptor.Tools map is keyed by.
|
||||
const (
|
||||
// ContentToolEdit names the tool that edits a record's fields and body.
|
||||
ContentToolEdit = "edit"
|
||||
// ContentToolHeadings names the tool that changes the headings of a
|
||||
// record's body.
|
||||
ContentToolHeadings = "headings"
|
||||
// ContentToolImageAlt names the tool that sets the alternative text of
|
||||
// the images in a record's body.
|
||||
ContentToolImageAlt = "image_alt"
|
||||
)
|
||||
|
||||
// ContentList is what ContentDescriptor.Records receives. Pattern is the URL
|
||||
// pattern already layered by the registry (the host's override, else the
|
||||
// type's default). After is the ID of the last record of the previous page,
|
||||
@@ -60,17 +98,32 @@ type ContentDescribe struct {
|
||||
// ContentRecord describes one record. ID is its primary key as text,
|
||||
// Published whether visitors can see it, LastMod its last change (nil when
|
||||
// unknown). Locales lists the record per locale in the site's locale order.
|
||||
// The remaining fields are optional; a nil slice and an empty one mean the
|
||||
// same: the type has nothing to say.
|
||||
type ContentRecord struct {
|
||||
ID string
|
||||
Published bool
|
||||
LastMod *time.Time
|
||||
Locales []ContentLocale
|
||||
// PublishedAt is the record's first publication, nil when unknown or
|
||||
// never published.
|
||||
PublishedAt *time.Time
|
||||
// Parents lists the records this one sits under, in order of preference:
|
||||
// the first is the default primary parent.
|
||||
Parents []ContentRef
|
||||
// Authors lists the people who wrote the record, in byline order.
|
||||
Authors []ContentPerson
|
||||
// TopHeading is the highest heading level the record's body may use: 2
|
||||
// when the page renders the title as its only level-1 heading, 0 when the
|
||||
// type sets no rule.
|
||||
TopHeading int
|
||||
}
|
||||
|
||||
// ContentLocale is a record in one locale. URL is its public path, "" when
|
||||
// the locale or the host has no public page for it. Title, Description and
|
||||
// Image (a URL) are the record's own defaults for page metadata; Words is the
|
||||
// body's word count, nil when the type has no body.
|
||||
// body's word count, nil when the type has no body. Images, Videos and
|
||||
// Headings are optional; a nil slice and an empty one mean the same.
|
||||
type ContentLocale struct {
|
||||
Locale string
|
||||
URL string
|
||||
@@ -78,6 +131,52 @@ type ContentLocale struct {
|
||||
Description string
|
||||
Image string
|
||||
Words *int
|
||||
// Images lists the record's images in this locale (the featured image
|
||||
// first, then the body's in document order).
|
||||
Images []ContentImage
|
||||
// Videos lists the videos the body embeds, in document order.
|
||||
Videos []ContentVideo
|
||||
// Headings is the body's heading outline in document order.
|
||||
Headings []ContentHeading
|
||||
}
|
||||
|
||||
// ContentRef points at another record: Type is a menu item type key and ID
|
||||
// the record's ID within it.
|
||||
type ContentRef struct {
|
||||
Type string
|
||||
ID string
|
||||
}
|
||||
|
||||
// ContentPerson is a person named on a record. Ref points at the person's
|
||||
// own record; its Type is "" when the person has none.
|
||||
type ContentPerson struct {
|
||||
Name string
|
||||
Ref ContentRef
|
||||
}
|
||||
|
||||
// ContentImage is an image a record shows. URL is its address and Alt its
|
||||
// alternative text; Decorative marks an image that carries no content, whose
|
||||
// empty Alt is intended. Width and Height are in pixels, 0 when unknown.
|
||||
type ContentImage struct {
|
||||
URL string
|
||||
Alt string
|
||||
Decorative bool
|
||||
Width int
|
||||
Height int
|
||||
}
|
||||
|
||||
// ContentVideo is a video a record embeds: Provider names the host (such as
|
||||
// "youtube") and ID the video there.
|
||||
type ContentVideo struct {
|
||||
Provider string
|
||||
ID string
|
||||
}
|
||||
|
||||
// ContentHeading is one heading of a record's body: Level 1 to 6 and its
|
||||
// text.
|
||||
type ContentHeading struct {
|
||||
Level int
|
||||
Text string
|
||||
}
|
||||
|
||||
// ContentMatch is what ContentDescriptor.Match receives: a public path (no
|
||||
|
||||
Reference in New Issue
Block a user