Documentation
¶
Index ¶
- Variables
- func GetAcceptedLanguages(r *http.Request) []string
- func Merge(maps ...template.FuncMap) template.FuncMap
- type Analytics
- type CMS
- func (cms *CMS) LastUpdate() string
- func (cms *CMS) Render(args map[string]string, page *Content, position string, content []Content) template.HTML
- func (cms *CMS) Render404(w http.ResponseWriter, r *http.Request, path string)
- func (cms *CMS) RenderElement(w http.ResponseWriter, r *http.Request, page *Content, position string, ...) ([]byte, error)
- func (cms *CMS) RenderPage(w http.ResponseWriter, r *http.Request, path string, args map[string]string, ...)
- func (cms *CMS) Serve(w http.ResponseWriter, r *http.Request)
- func (cms *CMS) SetHandler(name string, handler Handler)
- func (cms *CMS) Update()
- type Cache
- type Content
- type Copy
- type Experiment
- type Handler
- type Options
- type Route
- type Sitemap
- type Subroute
Constants ¶
This section is empty.
Variables ¶
var ( ErrMatcherBrackets = "matching route '%s' must end with a closing bracket" ErrMatcherEmpty = "matching route '%s' must not be empty" ErrMatcherVariable = "matching route '%s' must have a variable name (name:expression)" ErrParsingMatcher = "error parsing matching route '%s': %v" )
Functions ¶
func GetAcceptedLanguages ¶ added in v1.0.0
GetAcceptedLanguages returns the accepted languages for the given request.
Types ¶
type Analytics ¶
type Analytics struct {
Tags map[string]string `json:"tags,omitempty"`
Experiment Experiment `json:"experiment,omitempty"`
}
Analytics is the analytics metadata for the Content.
type CMS ¶
type CMS struct {
// contains filtered or unexported fields
}
CMS manages pages and content.
func (*CMS) LastUpdate ¶
LastUpdate returns the time the website data has last been updated.
func (*CMS) Render ¶
func (cms *CMS) Render(args map[string]string, page *Content, position string, content []Content) template.HTML
Render renders and returns the content for the given page.
func (*CMS) Render404 ¶
Render404 renders the 404 page for the given path and language if it exists. The language will fall back to en if not found or empty.
func (*CMS) RenderElement ¶ added in v1.0.0
func (cms *CMS) RenderElement(w http.ResponseWriter, r *http.Request, page *Content, position string, element *Content) ([]byte, error)
RenderElement renders the given element and returns the content.
func (*CMS) RenderPage ¶
func (cms *CMS) RenderPage(w http.ResponseWriter, r *http.Request, path string, args map[string]string, page *Content)
RenderPage renders the given page and returns it to the client. If no content is present, a default head and body section are served.
func (*CMS) Serve ¶
func (cms *CMS) Serve(w http.ResponseWriter, r *http.Request)
Serve matches the path and renders the page for the given request. If no page is found, it will redirect to the 404-page.
func (*CMS) SetHandler ¶
SetHandler sets the handler function for the given name.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache caches an HTML template directory.
func NewCache ¶
NewCache creates a new template cache for the given directory and function map. Disable is used to disable the cache for testing.
func (*Cache) Execute ¶
func (cache *Cache) Execute(w http.ResponseWriter, name string, data any)
Execute executes the template for the given name. It logs errors and returns an error code if something goes wrong.
type Content ¶
type Content struct {
DisableCache bool `json:"disable_cache,omitempty"`
Path map[string]string `json:"path,omitempty"`
Sitemap Sitemap `json:"sitemap"`
Header map[string]string `json:"header,omitempty"`
Handler string `json:"handler,omitempty"`
Analytics Analytics `json:"analytics"`
Ref string `json:"ref,omitempty"`
Tpl string `json:"tpl,omitempty"`
Data map[string]any `json:"data,omitempty"`
Copy Copy `json:"copy,omitempty"`
Content map[string][]Content `json:"content,omitempty"`
// File is the path for the current content file.
File string `json:"-"`
// Request is the HTTP request.
Request *http.Request `json:"-"`
// Language is extracted and set from Path automatically.
Language string `json:"-"`
// CanonicalLink is set automatically using the configured hostname and Path.
CanonicalLink string `json:"-"`
// Experiments is a list of A/B experiments extracted from the content (name -> variants).
Experiments map[string][]string `json:"-"`
// SelectedExperiments is a list of selected A/B experiments from the Experiments list.
SelectedExperiments map[string]string `json:"-"`
// SelectedPageExperiment is an experiment from the page experiments list, redirecting if the visitor is on the wrong page.
SelectedPageExperiment string `json:"-"`
// Position is the element position path in JSON.
Position string `json:"-"`
}
Content is a page or element for the CMS.
type Experiment ¶
Experiment is an A/B testing experiment.
type Options ¶
type Options struct {
Ctx context.Context
BaseDir string
HotReload bool
NotFound map[string]string
FuncMap template.FuncMap
Source source.Provider
Sitemap *sitemap.Sitemap
}
Options is the CMS configuration.
type Route ¶ added in v0.11.0
type Route struct {
// contains filtered or unexported fields
}
Route matches raw or matching routes including regular expressions.