Documentation
¶
Index ¶
- Constants
- Variables
- func ErrorHandler(cfg ErrorHandlerConfig, pageHandler keratin.Handler, manager PageManager, ...) keratin.ErrorHandlerFunc
- func ErrorStatus(_ context.Context, err error) int
- func FuncMap(urlGenerator URLGenerator) template.FuncMap
- func HybridPageMiddleware(pageHandler keratin.Handler, logger *slog.Logger, ...) func(keratin.Handler) keratin.Handler
- func IsDecorable(w http.ResponseWriter, r *http.Request) bool
- func NewContext(parent context.Context) (context.Context, context.CancelFunc)
- func PageSkipper(decoratorStrategy PageDecoratorStrategy) middleware.Skipper
- func SelectPageMiddleware(manager PageManager, authorizer PageAuthorizer, skippers ...middleware.Skipper) func(keratin.Handler) keratin.Handler
- func SelectSiteMiddleware(retriever SiteRetriever, skippers ...middleware.Skipper) func(keratin.Handler) keratin.Handler
- type Attr
- type BeforeSaveFunc
- type Context
- func (c *Context) Content() template.HTML
- func (c *Context) DOM() *DOM
- func (c *Context) Debug() bool
- func (c *Context) Error() error
- func (c *Context) Guest() bool
- func (c *Context) HasContent() bool
- func (c *Context) HasError() bool
- func (c *Context) HasPage() bool
- func (c *Context) HasSite() bool
- func (c *Context) HasTemplate() bool
- func (c *Context) Page() *Page
- func (c *Context) Reset()
- func (c *Context) SetContent(content template.HTML)
- func (c *Context) SetDebug(debug bool)
- func (c *Context) SetError(err error)
- func (c *Context) SetGuest(guest bool)
- func (c *Context) SetPage(page *Page)
- func (c *Context) SetSite(site *Site)
- func (c *Context) SetStatus(status int)
- func (c *Context) SetTemplate(template string)
- func (c *Context) Site() *Site
- func (c *Context) Status() int
- func (c *Context) Template() string
- type DOM
- type Decision
- type DefaultPageManager
- func (m *DefaultPageManager) GetByAlias(ctx context.Context, site *Site, alias string) (*Page, error)
- func (m *DefaultPageManager) GetByID(ctx context.Context, id ID) (*Page, error)
- func (m *DefaultPageManager) GetByPattern(ctx context.Context, site *Site, pattern string) (*Page, error)
- func (m *DefaultPageManager) GetByURL(ctx context.Context, site *Site, url string) (*Page, error)
- type DefaultPageSyncer
- type ErrorHandlerConfig
- type ErrorPatternFunc
- type HTTPSiteRetriever
- type HTTPSiteRetrieverConfig
- type Head
- type HeadLink
- type ID
- type IDGeneratorFunc
- type LocalhostSiteStore
- type MemoryPageStore
- func (s *MemoryPageStore) DeleteByID(_ context.Context, ids ...ID) error
- func (s *MemoryPageStore) FindByAlias(_ context.Context, siteID ID, alias string) (*Page, error)
- func (s *MemoryPageStore) FindByID(_ context.Context, id ID) (*Page, error)
- func (s *MemoryPageStore) FindByPattern(_ context.Context, siteID ID, pattern string) (*Page, error)
- func (s *MemoryPageStore) FindByPatterns(_ context.Context, siteID ID, patterns ...string) iter.Seq2[*Page, error]
- func (s *MemoryPageStore) FindByURL(_ context.Context, siteID ID, url string) (*Page, error)
- func (s *MemoryPageStore) GetData() []*Page
- func (s *MemoryPageStore) Save(_ context.Context, pages ...*Page) error
- type Meta
- func (m Meta) Bool(key string) bool
- func (m Meta) BoolSlice(key string) []bool
- func (m Meta) Delete(key string)
- func (m Meta) Duration(key string) time.Duration
- func (m Meta) Float32(key string) float32
- func (m Meta) Float64(key string) float64
- func (m Meta) Get(key string) any
- func (m Meta) GetOK(key string) (any, bool)
- func (m Meta) Has(key string) bool
- func (m Meta) Int(key string) int
- func (m Meta) Int8(key string) int8
- func (m Meta) Int16(key string) int16
- func (m Meta) Int32(key string) int32
- func (m Meta) Int64(key string) int64
- func (m Meta) IntSlice(key string) []int
- func (m Meta) Set(key string, value any)
- func (m Meta) Slice(key string) []any
- func (m Meta) Str(key string) string
- func (m Meta) StrSlice(key string) []string
- func (m Meta) Time(key string) time.Time
- func (m Meta) Uint(key string) uint
- func (m Meta) Uint8(key string) uint8
- func (m Meta) Uint16(key string) uint16
- func (m Meta) Uint32(key string) uint32
- func (m Meta) Uint64(key string) uint64
- type Node
- func CharsetMetaNode(charset string) Node
- func HTTPEquivMetaNode(name, content string) Node
- func HeadLinkNode(link HeadLink) (node Node)
- func MetaNode(attr ...string) Node
- func NameMetaNode(name, content string) Node
- func PropertyMetaNode(property, content string) Node
- func TitleNode(text string) Node
- type Nodes
- type Page
- func (p *Page) AbsURL(args ...any) string
- func (p *Page) Copy() *Page
- func (p *Page) FixURL()
- func (p *Page) IsCMS() bool
- func (p *Page) IsDynamic() bool
- func (p *Page) IsError() bool
- func (p *Page) IsHybrid() bool
- func (p *Page) IsInternal() bool
- func (p *Page) SetAlias(alias string)
- func (p *Page) String() string
- type PageAction
- type PageAuthorizer
- type PageConfig
- type PageCreateHandler
- type PageCreateHandlerConfig
- type PageCreateRequest
- type PageDecoratorStrategy
- type PageHandler
- type PageHandlerConfig
- type PageManager
- type PageStore
- type PageSyncer
- type PageSyncerConfig
- type PageURLGenerator
- func (g *PageURLGenerator) Generate(ctx context.Context, site *Site, arg any, args ...any) (string, error)
- func (g *PageURLGenerator) GenerateByAlias(ctx context.Context, site *Site, alias string, args ...any) (string, error)
- func (g *PageURLGenerator) GenerateByID(ctx context.Context, site *Site, id ID, args ...any) (string, error)
- func (g *PageURLGenerator) GenerateByPage(site *Site, page *Page, args ...any) (string, error)
- func (g *PageURLGenerator) GenerateByPattern(ctx context.Context, site *Site, pattern string, args ...any) (string, error)
- func (g *PageURLGenerator) GenerateByURL(ctx context.Context, site *Site, url string, args ...any) (string, error)
- type PatternArgsFunc
- type Patterns
- type Site
- type SiteRetriever
- type SiteStore
- type Status
- type TemplateVars
- type TemplateVarsFunc
- type Theme
- type URLGenerator
- type Visibility
Constants ¶
View Source
const ( LinkRelAlternate = "alternate" LinkRelAuthor = "author" LinkRelCanonical = "canonical" LinkRelLicense = "license" LinkRelNext = "next" LinkRelPrev = "prev" LinkRelStylesheet = "stylesheet" LinkRelIcon = "icon" )
View Source
const ( ReferrerPolicyNoReferrer = "no-referrer" ReferrerPolicyNoReferrerWhenDowngrade = "no-referrer-when-downgrade" ReferrerPolicyOrigin = "origin" ReferrerPolicyOriginWhenCrossOrigin = "origin-when-cross-origin" ReferrerPolicySameOrigin = "same-origin" ReferrerPolicyStrictOrigin = "strict-origin" ReferrerPolicyUnsafeUrl = "unsafe-url" )
View Source
const ( HeaderXPageDecorable = "X-Page-Decorable" HeaderXPageNotDecorable = "X-Page-Not-Decorable" )
View Source
const ( PageCMS = "_cms" PageAliasPrefix = "_alias_" PageInternalPrefix = "_internal_" PageInternalCreate = PageInternalPrefix + "create" PageErrorPrefix = PageInternalPrefix + "error_" PageErrorForbidden = PageErrorPrefix + "403" PageErrorNotFound = PageErrorPrefix + "404" PageError4xx = PageErrorPrefix + "4xx" PageError5xx = PageErrorPrefix + "5xx" )
View Source
const DefaultCharset = "UTF-8"
Variables ¶
View Source
var ( ErrSiteNotFound = errors.New("site not found") ErrPageNotFound = errors.New("page not found") ErrPageForbidden = errors.New("page forbidden") ErrUniqueViolation = errors.New("unique violation") ErrTemplateEmpty = errors.New("template is empty") )
View Source
var ( DynamicPatternChars = "{" PageCMSPattern = "/{_cms...}" HomeHybridPattern = "/{$}" )
View Source
var ErrorTemplateFS embed.FS
Functions ¶
func ErrorHandler ¶
func ErrorHandler(cfg ErrorHandlerConfig, pageHandler keratin.Handler, manager PageManager, errPattern ErrorPatternFunc) keratin.ErrorHandlerFunc
func ErrorStatus ¶
ErrorStatus returns an error code.
func FuncMap ¶
func FuncMap(urlGenerator URLGenerator) template.FuncMap
func HybridPageMiddleware ¶
func IsDecorable ¶
func IsDecorable(w http.ResponseWriter, r *http.Request) bool
func NewContext ¶
func PageSkipper ¶
func PageSkipper(decoratorStrategy PageDecoratorStrategy) middleware.Skipper
func SelectPageMiddleware ¶
func SelectPageMiddleware(manager PageManager, authorizer PageAuthorizer, skippers ...middleware.Skipper) func(keratin.Handler) keratin.Handler
func SelectSiteMiddleware ¶
func SelectSiteMiddleware(retriever SiteRetriever, skippers ...middleware.Skipper) func(keratin.Handler) keratin.Handler
Types ¶
type BeforeSaveFunc ¶
BeforeSaveFunc called before page save.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func FromContext ¶
func MustContext ¶
func (*Context) HasContent ¶
func (*Context) HasTemplate ¶
func (*Context) SetContent ¶
func (*Context) SetTemplate ¶
type DOM ¶
type DOM struct {
HTML struct {
Attr Attr `envPrefix:"ATTR_" json:"attr,omitempty" yaml:"attr,omitempty"`
} `envPrefix:"HTML_" json:"html,omitempty" yaml:"html,omitempty"`
Head Head `envPrefix:"HEAD_" json:"head,omitempty" yaml:"head,omitempty"`
Body struct {
Attr Attr `envPrefix:"ATTR_" json:"attr,omitempty" yaml:"attr,omitempty"`
} `envPrefix:"BODY_" json:"body,omitempty" yaml:"body,omitempty"`
}
type DefaultPageManager ¶
type DefaultPageManager struct {
// contains filtered or unexported fields
}
func NewPageManager ¶
func NewPageManager(store PageStore) *DefaultPageManager
func (*DefaultPageManager) GetByAlias ¶
func (*DefaultPageManager) GetByPattern ¶
type DefaultPageSyncer ¶
type DefaultPageSyncer struct {
// contains filtered or unexported fields
}
func NewDefaultPageSyncer ¶
func NewDefaultPageSyncer( cfg PageSyncerConfig, store PageStore, patterns Patterns, strategy PageDecoratorStrategy, generator IDGeneratorFunc, ) *DefaultPageSyncer
type ErrorHandlerConfig ¶
type ErrorHandlerConfig struct {
// FallbackTemplate is a template name for fallback error page.
// The fallback template is used when the error page is not found
// by pattern, also the Site and Page variables could not be provided.
FallbackTemplate string
// StatusFunc returns an error code code.
StatusFunc middleware.ErrorStatusFunc
// JSONHandler is a handler for JSON error responses.
JSONHandler http.Handler
// Logger is used for logging.
Logger *slog.Logger
}
func (*ErrorHandlerConfig) SetDefaults ¶
func (cfg *ErrorHandlerConfig) SetDefaults()
type ErrorPatternFunc ¶
func ErrorPattern ¶
func ErrorPattern(authorizer PageAuthorizer, decoratorStrategy PageDecoratorStrategy) ErrorPatternFunc
type HTTPSiteRetriever ¶
type HTTPSiteRetriever struct {
// contains filtered or unexported fields
}
func NewHTTPSiteRetriever ¶
func NewHTTPSiteRetriever(store SiteStore) *HTTPSiteRetriever
func NewHTTPSiteRetrieverWithConfig ¶
func NewHTTPSiteRetrieverWithConfig(store SiteStore, config HTTPSiteRetrieverConfig) *HTTPSiteRetriever
type HTTPSiteRetrieverConfig ¶
type HTTPSiteRetrieverConfig struct {
// CountryFunc determines the country based on the provided
// HTTP request and returns it as a string along with any error.
CountryFunc func(*http.Request) (string, error)
// ErrorFunc handles errors by taking an HTTP request and an error,
// returning a Site instance or an error.
ErrorFunc func(*http.Request, error) (*Site, error)
}
func (*HTTPSiteRetrieverConfig) SetDefaults ¶
func (c *HTTPSiteRetrieverConfig) SetDefaults()
type Head ¶
type HeadLink ¶
type HeadLink struct {
// CrossOrigin Specifies how the element handles cross-origin requests
CrossOrigin string
// Href Specifies the location of the linked document
Href string
// HrefLang Specifies the language of the text in the linked document
HrefLang string
// Media Specifies on what device the linked document will be displayed
Media string
// Rel REQUIRED Specifies the relationship between the current document and the linked document
Rel string
// Sizes Specifies the size of the linked resource. Only for rel="icon"
Sizes string
// Title Defines a preferred or an alternate stylesheet
Title string
// Type Specifies the media type of the linked document
Type string
}
type IDGeneratorFunc ¶
func IDGenerator ¶
func IDGenerator() IDGeneratorFunc
type LocalhostSiteStore ¶
type LocalhostSiteStore struct {
// contains filtered or unexported fields
}
func NewLocalhostSiteStore ¶
func NewLocalhostSiteStore() *LocalhostSiteStore
func (*LocalhostSiteStore) FindPublished ¶
type MemoryPageStore ¶
type MemoryPageStore struct {
// contains filtered or unexported fields
}
func NewMemoryPageStore ¶
func NewMemoryPageStore() *MemoryPageStore
func (*MemoryPageStore) DeleteByID ¶
func (s *MemoryPageStore) DeleteByID(_ context.Context, ids ...ID) error
func (*MemoryPageStore) FindByAlias ¶
func (*MemoryPageStore) FindByPattern ¶
func (*MemoryPageStore) FindByPatterns ¶
func (*MemoryPageStore) GetData ¶
func (s *MemoryPageStore) GetData() []*Page
GetData returns a copy of the data slice for testing purposes. This method provides thread-safe access to the internal data.
type Node ¶
type Node struct {
Tag string `env:"TAG" json:"tag,omitempty" yaml:"tag,omitempty"`
Text string `env:"TEXT" json:"text,omitempty" yaml:"text,omitempty"`
Attr Attr `env:"ATTR" json:"attr,omitempty" yaml:"attr,omitempty"`
}
func CharsetMetaNode ¶
func HTTPEquivMetaNode ¶
func HeadLinkNode ¶
func NameMetaNode ¶
func PropertyMetaNode ¶
type Page ¶
type Page struct {
ID ID `json:"id,omitempty" yaml:"id,omitempty"`
SiteID ID `json:"siteID,omitempty" yaml:"siteID,omitempty"`
Site *Site `json:"site,omitempty" yaml:"site,omitempty"`
ParentID *ID `json:"parentID,omitempty" yaml:"parentID,omitempty"`
Parent *Page `json:"parent,omitempty" yaml:"parent,omitempty"`
Children []*Page `json:"children,omitempty" yaml:"children,omitempty"`
Created time.Time `json:"created,omitzero" yaml:"created,omitempty"`
Updated time.Time `json:"updated,omitzero" yaml:"updated,omitempty"`
Status Status `json:"status,omitempty" yaml:"status,omitempty"`
Visibility Visibility `json:"visibility,omitempty" yaml:"visibility,omitempty"`
Meta Meta `json:"meta,omitempty" yaml:"meta,omitempty"`
DOM DOM `json:"dom,omitempty" yaml:"dom,omitempty"`
Header map[string][]string `json:"header,omitempty" yaml:"header,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Title string `json:"title,omitempty" yaml:"title,omitempty"`
Pattern string `json:"pattern,omitempty" yaml:"pattern,omitempty"`
Alias string `json:"alias,omitempty" yaml:"alias,omitempty"`
Slug string `json:"slug,omitempty" yaml:"slug,omitempty"`
URL string `json:"url,omitempty" yaml:"url,omitempty"`
CustomURL string `json:"customURL,omitempty" yaml:"customURL,omitempty"`
Template string `json:"template,omitempty" yaml:"template,omitempty"`
Position int `json:"position,omitempty" yaml:"position,omitempty"`
Decorate bool `json:"decorate,omitempty" yaml:"decorate,omitempty"`
}
func (*Page) IsInternal ¶
type PageAction ¶
type PageAction int8
const ( ViewDraftPage PageAction = iota + 1 ViewPrivatePage CreatePage )
func (PageAction) String ¶
func (a PageAction) String() string
type PageAuthorizer ¶
type PageAuthorizer interface {
Authorize(ctx context.Context, action PageAction) Decision
}
type PageConfig ¶
type PageConfig struct {
ParentID *ID `json:"parentID,omitempty" yaml:"parentID,omitempty"`
Template *string `json:"template,omitempty" yaml:"template,omitempty"`
Position *int `json:"position,omitempty" yaml:"position,omitempty"`
Decorate *bool `json:"decorate,omitempty" yaml:"decorate,omitempty"`
Status *Status `json:"status,omitempty" yaml:"status,omitempty"`
Visibility *Visibility `json:"visibility,omitempty" yaml:"visibility,omitempty"`
DOM *DOM `json:"dom,omitempty" yaml:"dom,omitempty"`
Meta Meta `json:"meta,omitempty" yaml:"meta,omitempty"`
Header map[string][]string `json:"header,omitempty" yaml:"header,omitempty"`
}
type PageCreateHandler ¶
type PageCreateHandler struct {
// contains filtered or unexported fields
}
func NewPageCreateHandler ¶
func NewPageCreateHandler(store PageStore, authorizer PageAuthorizer) *PageCreateHandler
func NewPageCreateHandlerWithConfig ¶
func NewPageCreateHandlerWithConfig(store PageStore, authorizer PageAuthorizer, cfg PageCreateHandlerConfig) *PageCreateHandler
func (*PageCreateHandler) ServeHTTP ¶
func (h *PageCreateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) error
type PageCreateHandlerConfig ¶
type PageCreateHandlerConfig struct {
GeneratorFunc IDGeneratorFunc
BeforeSaveFunc BeforeSaveFunc
}
func (*PageCreateHandlerConfig) SetDefaults ¶
func (c *PageCreateHandlerConfig) SetDefaults()
type PageCreateRequest ¶
type PageCreateRequest struct {
URL string `json:"url,omitempty" form:"url,omitempty"`
Template string `json:"template,omitempty" form:"template,omitempty"`
Title string `json:"title,omitempty" form:"title,omitempty"`
}
func (*PageCreateRequest) Validate ¶
func (r *PageCreateRequest) Validate() error
type PageDecoratorStrategy ¶
type PageHandler ¶
type PageHandler struct {
// contains filtered or unexported fields
}
PageHandler renders pages using a Theme.
func NewPageHandler ¶
func NewPageHandler(theme Theme) *PageHandler
func NewPageHandlerWithConfig ¶
func NewPageHandlerWithConfig(theme Theme, cfg PageHandlerConfig) *PageHandler
func (*PageHandler) ServeHTTP ¶
func (h *PageHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) error
type PageHandlerConfig ¶
type PageHandlerConfig struct {
// VarsFunc defines a function that generates
// template variables from an HTTP request and context.
VarsFunc TemplateVarsFunc
// Logger is used for logging.
Logger *slog.Logger
}
func (*PageHandlerConfig) SetDefaults ¶
func (c *PageHandlerConfig) SetDefaults()
type PageManager ¶
type PageManager interface {
GetByID(ctx context.Context, id ID) (*Page, error)
GetByURL(ctx context.Context, site *Site, url string) (*Page, error)
GetByPattern(ctx context.Context, site *Site, pattern string) (*Page, error)
GetByAlias(ctx context.Context, site *Site, alias string) (*Page, error)
}
type PageStore ¶
type PageStore interface {
FindByID(ctx context.Context, id ID) (*Page, error)
FindByURL(ctx context.Context, siteID ID, url string) (*Page, error)
FindByPattern(ctx context.Context, siteID ID, pattern string) (*Page, error)
FindByPatterns(ctx context.Context, siteID ID, patterns ...string) iter.Seq2[*Page, error]
FindByAlias(ctx context.Context, siteID ID, alias string) (*Page, error)
Save(ctx context.Context, pages ...*Page) error
}
type PageSyncerConfig ¶
type PageSyncerConfig struct {
DefaultPage *PageConfig `json:"defaultPage,omitempty" yaml:"defaultPage,omitempty"`
DefaultPatterns map[string]*PageConfig `json:"defaultPatterns,omitempty" yaml:"defaultPatterns,omitempty"`
}
func (*PageSyncerConfig) SetDefaults ¶
func (c *PageSyncerConfig) SetDefaults()
type PageURLGenerator ¶
type PageURLGenerator struct {
// contains filtered or unexported fields
}
func NewPageURLGenerator ¶
func NewPageURLGenerator(manager PageManager) *PageURLGenerator
func (*PageURLGenerator) GenerateByAlias ¶
func (*PageURLGenerator) GenerateByID ¶
func (*PageURLGenerator) GenerateByPage ¶
func (*PageURLGenerator) GenerateByPattern ¶
func (*PageURLGenerator) GenerateByURL ¶
type PatternArgsFunc ¶
func PatternArgs ¶
func PatternArgs() PatternArgsFunc
type Site ¶
type Site struct {
ID ID `json:"id,omitempty" yaml:"id,omitempty"`
Created time.Time `json:"created,omitzero" yaml:"created,omitempty"`
Updated time.Time `json:"updated,omitzero" yaml:"updated,omitempty"`
Status Status `json:"status,omitempty" yaml:"status,omitempty"`
Meta Meta `json:"meta,omitempty" yaml:"meta,omitempty"`
DOM DOM `json:"dom,omitempty" yaml:"dom,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Title string `json:"title,omitempty" yaml:"title,omitempty"`
Separator string `json:"separator,omitempty" yaml:"separator,omitempty"`
Locale string `json:"locale,omitempty" yaml:"locale,omitempty"`
Timezone string `json:"timezone,omitempty" yaml:"timezone,omitempty"`
Countries []string `json:"countries,omitempty" yaml:"countries,omitempty"`
Scheme string `json:"scheme,omitempty" yaml:"scheme,omitempty"`
Host string `json:"host,omitempty" yaml:"host,omitempty"`
RelativePath string `json:"relativePath,omitempty" yaml:"relativePath,omitempty"`
IsDefault bool `json:"isDefault,omitempty" yaml:"isDefault,omitempty"`
IsRoot bool `json:"-" yaml:"-"`
// contains filtered or unexported fields
}
func (*Site) IsLocalhost ¶
type SiteRetriever ¶
type TemplateVars ¶
func (TemplateVars) Value ¶
func (c TemplateVars) Value(key any) any
type TemplateVarsFunc ¶
TemplateVarsFunc return a template variables.
type Theme ¶
Theme defines an interface for rendering templates with a specific context and writing the output to an io.Writer.
type URLGenerator ¶
type Visibility ¶
type Visibility int8
const ( Private Visibility = iota Public )
func VisibilityFromString ¶
func VisibilityFromString(s string) Visibility
func (Visibility) String ¶
func (v Visibility) String() string
Source Files
¶
- context.go
- dom.go
- error.go
- error_handler.go
- error_pattern.go
- error_status.go
- funcmap.go
- http.go
- http_middleware.go
- http_skipper.go
- id.go
- meta.go
- page.go
- page_authorizer.go
- page_create_handler.go
- page_decorator_strategy.go
- page_handler.go
- page_manager.go
- page_store.go
- page_syncer.go
- page_urlgenerator.go
- site.go
- site_retriever.go
- site_store.go
- status.go
- visibility.go
Click to show internal directories.
Click to hide internal directories.