posttype

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidPostTypeName is returned when post type name validation fails
	ErrInvalidPostTypeName = errors.New("post type name is required and must be between 1 and 200 characters")
	// ErrInvalidPostTypeSlug is returned when post type slug validation fails
	ErrInvalidPostTypeSlug = errors.New("post type slug must be between 1 and 200 characters and contain only lowercase letters, numbers, hyphens, and underscores")
	// ErrInvalidSupports is returned when supports validation fails
	ErrInvalidSupports = errors.New("supports must contain at least one valid feature")
	// ErrDuplicatePostType is returned when attempting to register a duplicate post type
	ErrDuplicatePostType = errors.New("post type with this slug already exists")
	// ErrPostTypeNotFound is returned when a post type is not found
	ErrPostTypeNotFound = errors.New("post type not found")
)
View Source
var SupportedFeatures = []string{
	"title",
	"content",
	"tags",
	"featured_image",
	"excerpt",
}

SupportedFeatures returns the list of valid feature names

Functions

func GetSupportedFeatures

func GetSupportedFeatures() []string

GetSupportedFeatures returns a copy of the supported features list

func Validate

func Validate(pt PostType) error

Validate validates the entire PostType struct

func ValidateName

func ValidateName(name string) error

ValidateName validates the post type name field

func ValidateSlug

func ValidateSlug(slug string) error

ValidateSlug validates the post type slug field

func ValidateSupports

func ValidateSupports(supports []string) error

ValidateSupports validates the supports array

Types

type PostType

type PostType struct {
	Name         string                    `json:"name" toml:"name"`
	Slug         string                    `json:"slug" toml:"slug"`
	Description  string                    `json:"description,omitempty" toml:"description,omitempty"`
	Supports     []string                  `json:"supports" toml:"supports"`
	Fields       []customfield.FieldSchema `json:"fields,omitempty" toml:"fields,omitempty"`
	SystemFields []customfield.FieldSchema `json:"systemFields,omitempty" toml:"system_fields,omitempty"`
}

PostType represents a custom post type configuration

func GetDefaultPostTypes

func GetDefaultPostTypes() []PostType

GetDefaultPostTypes returns the default post types

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service manages post type registration and lookup

func NewService

func NewService() *Service

NewService creates a new post type service initialized with default post types

func (*Service) GetAll

func (s *Service) GetAll() []PostType

GetAll returns all registered post types

func (*Service) GetAllBySupports

func (s *Service) GetAllBySupports(feature string) []PostType

GetAllBySupports returns all post types that support the given feature

func (*Service) GetBySlug

func (s *Service) GetBySlug(slug string) (PostType, error)

GetBySlug retrieves a post type by its slug

func (*Service) GetFieldsByPostType

func (s *Service) GetFieldsByPostType(slug string) ([]customfield.FieldSchema, error)

GetFieldsByPostType returns the custom field schemas for a given post type slug

func (*Service) GetSystemFieldsByPostType

func (s *Service) GetSystemFieldsByPostType(slug string) ([]customfield.FieldSchema, error)

GetSystemFieldsByPostType returns the system field schemas for a given post type slug

func (*Service) GetUserFields

func (s *Service) GetUserFields() []customfield.FieldSchema

GetUserFields returns the custom user field schemas

func (*Service) GetUserSystemFieldSlugs

func (s *Service) GetUserSystemFieldSlugs() []string

GetUserSystemFieldSlugs returns only the slugs of system user fields

func (*Service) GetUserSystemFields

func (s *Service) GetUserSystemFields() []customfield.FieldSchema

GetUserSystemFields returns the system user field schemas

func (*Service) IsSupported

func (s *Service) IsSupported(pt PostType, feature string) bool

IsSupported checks if a post type supports a specific feature

func (*Service) LoadConfigFromFile

func (s *Service) LoadConfigFromFile(path string) error

LoadConfigFromFile loads post types from a TOML configuration file If the file doesn't exist, it uses default post types (no error returned)

func (*Service) Register

func (s *Service) Register(pt PostType) error

Register registers a new post type. A non-default slug is validated in full and stored; a slug matching a built-in type (post/page/media/comment) instead EXTENDS that built-in — its Fields and SystemFields are merged in (by slug), preserving the built-in's Name/Description/Supports/identity. Only the fields are validated on the extension path, because an extension entry legitimately omits name/supports (it is not defining a new type).

type UserFields

type UserFields struct {
	Fields       []customfield.FieldSchema `json:"fields,omitempty" toml:"fields,omitempty"`
	SystemFields []customfield.FieldSchema `json:"systemFields,omitempty" toml:"system_fields,omitempty"`
}

UserFields holds global custom and system fields for user profiles

func (UserFields) Validate

func (uf UserFields) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL