pages

package module
v0.0.0-...-c8de795 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 28 Imported by: 0

README

Pages

Go Reference Go Report Card codecov License

A comprehensive Go package for content management that provides multi-site support, and flexible page routing.

Features

  • 🌐 Multi-Site Support - Manage multiple websites with different domains, locales, and countries
  • 📝 Flexible Page Types - CMS pages, hybrid routing with dynamic patterns, and internal system pages
  • 🧪 Comprehensive Testing - Extensive test coverage with mock implementations

Installation

go get github.com/gowool/pages

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

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_"
	PageErrorUnauthorized = PageErrorPrefix + "401"
	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")
	ErrPageUnauthorized = errors.New("page unauthorized")
	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

func ErrorStatus(_ context.Context, err error) int

ErrorStatus returns an error code.

func FuncMap

func FuncMap(urlGenerator URLGenerator) template.FuncMap

func HybridPageMiddleware

func HybridPageMiddleware(pageHandler keratin.Handler, logger *slog.Logger, skippers ...middleware.Skipper) func(keratin.Handler) keratin.Handler

func IsDecorable

func IsDecorable(w http.ResponseWriter, r *http.Request) bool

func NewContext

func NewContext(parent context.Context) (context.Context, context.CancelFunc)

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 Attr

type Attr map[string]string

func NewAttr

func NewAttr(attr ...string) (a Attr)

func (*Attr) Add

func (attr *Attr) Add(key, value string)

func (*Attr) Copy

func (attr *Attr) Copy() Attr

func (*Attr) HTML

func (attr *Attr) HTML() template.HTMLAttr

func (*Attr) String

func (attr *Attr) String() string

func (*Attr) With

func (attr *Attr) With(other Attr) Attr

type BeforeSaveFunc

type BeforeSaveFunc func(context.Context, *Page) error

BeforeSaveFunc called before page save.

type Context

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

func FromContext

func FromContext(ctx context.Context) *Context

func MustContext

func MustContext(ctx context.Context) *Context

func (*Context) Content

func (c *Context) Content() template.HTML

func (*Context) DOM

func (c *Context) DOM() *DOM

func (*Context) Debug

func (c *Context) Debug() bool

func (*Context) Error

func (c *Context) Error() error

func (*Context) Guest

func (c *Context) Guest() bool

func (*Context) HasContent

func (c *Context) HasContent() bool

func (*Context) HasError

func (c *Context) HasError() bool

func (*Context) HasPage

func (c *Context) HasPage() bool

func (*Context) HasSite

func (c *Context) HasSite() bool

func (*Context) HasTemplate

func (c *Context) HasTemplate() bool

func (*Context) Page

func (c *Context) Page() *Page

func (*Context) Reset

func (c *Context) Reset()

func (*Context) SetContent

func (c *Context) SetContent(content template.HTML)

func (*Context) SetDebug

func (c *Context) SetDebug(debug bool)

func (*Context) SetError

func (c *Context) SetError(err error)

func (*Context) SetGuest

func (c *Context) SetGuest(guest bool)

func (*Context) SetPage

func (c *Context) SetPage(page *Page)

func (*Context) SetSite

func (c *Context) SetSite(site *Site)

func (*Context) SetStatus

func (c *Context) SetStatus(status int)

func (*Context) SetTemplate

func (c *Context) SetTemplate(template string)

func (*Context) Site

func (c *Context) Site() *Site

func (*Context) Status

func (c *Context) Status() int

func (*Context) Template

func (c *Context) Template() string

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"`
}

func (DOM) Copy

func (dom DOM) Copy() (newDOM DOM)

func (DOM) With

func (dom DOM) With(other DOM) (newDOM DOM)

type Decision

type Decision int8
const (
	Deny Decision = iota
	Allow
)

func (Decision) String

func (d Decision) String() string

type DefaultPageManager

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

func NewPageManager

func NewPageManager(store PageStore) *DefaultPageManager

func (*DefaultPageManager) GetByAlias

func (m *DefaultPageManager) GetByAlias(ctx context.Context, site *Site, alias string) (*Page, error)

func (*DefaultPageManager) GetByID

func (m *DefaultPageManager) GetByID(ctx context.Context, id ID) (*Page, error)

func (*DefaultPageManager) GetByPattern

func (m *DefaultPageManager) GetByPattern(ctx context.Context, site *Site, pattern string) (*Page, error)

func (*DefaultPageManager) GetByURL

func (m *DefaultPageManager) GetByURL(ctx context.Context, site *Site, url string) (*Page, error)

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

func (*DefaultPageSyncer) Sync

func (s *DefaultPageSyncer) Sync(ctx context.Context, site *Site) error

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

type ErrorPatternFunc func(r *http.Request, status int, err error) string

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

func (*HTTPSiteRetriever) Retrieve

func (s *HTTPSiteRetriever) Retrieve(r *http.Request) (*Site, string, error)

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 struct {
	Attr  Attr  `envPrefix:"ATTR_" json:"attr,omitempty" yaml:"attr,omitempty"`
	Nodes Nodes `envPrefix:"NODE_" json:"nodes,omitempty" yaml:"nodes,omitempty"`
}

func (*Head) Add

func (head *Head) Add(nodes ...Node)

func (*Head) Copy

func (head *Head) Copy() Head

func (*Head) With

func (head *Head) With(other Head) (newHead Head)
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 ID

type ID string

func (ID) IsZero

func (id ID) IsZero() bool

func (ID) String

func (id ID) String() string

type IDGeneratorFunc

type IDGeneratorFunc func(ctx context.Context) (ID, error)

func IDGenerator

func IDGenerator() IDGeneratorFunc

type LocalhostSiteStore

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

func NewLocalhostSiteStore

func NewLocalhostSiteStore() *LocalhostSiteStore

func (*LocalhostSiteStore) FindPublished

func (s *LocalhostSiteStore) FindPublished(context.Context) iter.Seq2[*Site, error]

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 (s *MemoryPageStore) FindByAlias(_ context.Context, siteID ID, alias string) (*Page, error)

func (*MemoryPageStore) FindByID

func (s *MemoryPageStore) FindByID(_ context.Context, id ID) (*Page, error)

func (*MemoryPageStore) FindByPattern

func (s *MemoryPageStore) FindByPattern(_ context.Context, siteID ID, pattern string) (*Page, error)

func (*MemoryPageStore) FindByPatterns

func (s *MemoryPageStore) FindByPatterns(_ context.Context, siteID ID, patterns ...string) iter.Seq2[*Page, error]

func (*MemoryPageStore) FindByURL

func (s *MemoryPageStore) FindByURL(_ context.Context, siteID ID, url string) (*Page, error)

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.

func (*MemoryPageStore) Save

func (s *MemoryPageStore) Save(_ context.Context, pages ...*Page) error

type Meta

type Meta map[string]any

func NewMeta

func NewMeta(m map[string]any) Meta

func (Meta) Bool

func (m Meta) Bool(key string) bool

func (Meta) BoolSlice

func (m Meta) BoolSlice(key string) []bool

func (Meta) Delete

func (m Meta) Delete(key string)

func (Meta) Duration

func (m Meta) Duration(key string) time.Duration

func (Meta) Float32

func (m Meta) Float32(key string) float32

func (Meta) Float64

func (m Meta) Float64(key string) float64

func (Meta) Get

func (m Meta) Get(key string) any

func (Meta) GetOK

func (m Meta) GetOK(key string) (any, bool)

func (Meta) Has

func (m Meta) Has(key string) bool

func (Meta) Int

func (m Meta) Int(key string) int

func (Meta) Int8

func (m Meta) Int8(key string) int8

func (Meta) Int16

func (m Meta) Int16(key string) int16

func (Meta) Int32

func (m Meta) Int32(key string) int32

func (Meta) Int64

func (m Meta) Int64(key string) int64

func (Meta) IntSlice

func (m Meta) IntSlice(key string) []int

func (Meta) Set

func (m Meta) Set(key string, value any)

func (Meta) Slice

func (m Meta) Slice(key string) []any

func (Meta) Str

func (m Meta) Str(key string) string

func (Meta) StrSlice

func (m Meta) StrSlice(key string) []string

func (Meta) Time

func (m Meta) Time(key string) time.Time

func (Meta) Uint

func (m Meta) Uint(key string) uint

func (Meta) Uint8

func (m Meta) Uint8(key string) uint8

func (Meta) Uint16

func (m Meta) Uint16(key string) uint16

func (Meta) Uint32

func (m Meta) Uint32(key string) uint32

func (Meta) Uint64

func (m Meta) Uint64(key string) uint64

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 CharsetMetaNode(charset string) Node

func HTTPEquivMetaNode

func HTTPEquivMetaNode(name, content string) Node

func HeadLinkNode

func HeadLinkNode(link HeadLink) (node Node)

func MetaNode

func MetaNode(attr ...string) Node

func NameMetaNode

func NameMetaNode(name, content string) Node

func PropertyMetaNode

func PropertyMetaNode(property, content string) Node

func TitleNode

func TitleNode(text string) Node

func (Node) Copy

func (n Node) Copy() Node

func (Node) HTML

func (n Node) HTML() template.HTML

func (Node) String

func (n Node) String() string

type Nodes

type Nodes []Node

func (Nodes) Copy

func (nodes Nodes) Copy() Nodes

func (Nodes) HTML

func (nodes Nodes) HTML() template.HTML

func (Nodes) String

func (nodes Nodes) String() string

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 NewPage

func NewPage() *Page

func (*Page) AbsURL

func (p *Page) AbsURL(args ...any) string

func (*Page) Copy

func (p *Page) Copy() *Page

func (*Page) FixURL

func (p *Page) FixURL()

func (*Page) IsCMS

func (p *Page) IsCMS() bool

func (*Page) IsDynamic

func (p *Page) IsDynamic() bool

func (*Page) IsError

func (p *Page) IsError() bool

func (*Page) IsHybrid

func (p *Page) IsHybrid() bool

func (*Page) IsInternal

func (p *Page) IsInternal() bool

func (*Page) SetAlias

func (p *Page) SetAlias(alias string)

func (*Page) String

func (p *Page) String() string

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 PageDecoratorStrategy interface {
	IsPatternDecorable(ctx context.Context, pattern string) bool
	IsURIDecorable(ctx context.Context, uri string) bool
}

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 PageSyncer

type PageSyncer interface {
	Sync(ctx context.Context, site *Site) 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) Generate

func (g *PageURLGenerator) Generate(ctx context.Context, site *Site, arg any, args ...any) (string, error)

func (*PageURLGenerator) GenerateByAlias

func (g *PageURLGenerator) GenerateByAlias(ctx context.Context, site *Site, alias string, args ...any) (string, error)

func (*PageURLGenerator) GenerateByID

func (g *PageURLGenerator) GenerateByID(ctx context.Context, site *Site, id ID, args ...any) (string, error)

func (*PageURLGenerator) GenerateByPage

func (g *PageURLGenerator) GenerateByPage(site *Site, page *Page, args ...any) (string, error)

func (*PageURLGenerator) GenerateByPattern

func (g *PageURLGenerator) GenerateByPattern(ctx context.Context, site *Site, pattern string, args ...any) (string, error)

func (*PageURLGenerator) GenerateByURL

func (g *PageURLGenerator) GenerateByURL(ctx context.Context, site *Site, url string, args ...any) (string, error)

type PatternArgsFunc

type PatternArgsFunc func(*http.Request) []any

func PatternArgs

func PatternArgs() PatternArgsFunc

type Patterns

type Patterns interface {
	Patterns() iter.Seq[string]
}

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 NewSite

func NewSite() *Site

func (*Site) Copy

func (s *Site) Copy() *Site

func (*Site) Home

func (s *Site) Home() string

func (*Site) IsLocalhost

func (s *Site) IsLocalhost() bool

func (*Site) Location

func (s *Site) Location() *time.Location

func (*Site) Origin

func (s *Site) Origin() string

func (*Site) String

func (s *Site) String() string

func (*Site) Tag

func (s *Site) Tag() language.Tag

func (*Site) URL

func (s *Site) URL() string

type SiteRetriever

type SiteRetriever interface {
	Retrieve(r *http.Request) (*Site, string, error)
}

type SiteStore

type SiteStore interface {
	FindPublished(ctx context.Context) iter.Seq2[*Site, error]
}

type Status

type Status int8
const (
	Draft Status = iota
	Published
)

func StatusFromString

func StatusFromString(s string) Status

func (Status) String

func (s Status) String() string

type TemplateVars

type TemplateVars struct {
	*Context
	Request *http.Request
	Ctx     context.Context
}

func (TemplateVars) Value

func (c TemplateVars) Value(key any) any

type TemplateVarsFunc

type TemplateVarsFunc func(*http.Request, *Context) any

TemplateVarsFunc return a template variables.

type Theme

type Theme interface {
	Render(ctx context.Context, template string, data any) ([]byte, error)
}

Theme defines an interface for rendering templates with a specific context and writing the output to an io.Writer.

type URLGenerator

type URLGenerator interface {
	Generate(ctx context.Context, site *Site, arg any, args ...any) (string, error)
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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