Documentation ¶
Index ¶
- Constants
- func Dir() func(path string) string
- func Domain(e *config.Env) func(path string) string
- func Helpers(e *config.Env) template.FuncMap
- func Map() func(values ...interface{}) (map[string]interface{}, error)
- func Named() any
- func Partial(e *config.Env) func(path string, data any) template.HTML
- func Syntax() func(lang, text string) template.HTML
- func TrimSpace() func(text string) string
- func Write(w Writable, output string, mem *memfs.FS, env *config.Env) error
- type Build
- type Context
- type ExTemplate
- func (e *ExTemplate) DefinedTemplates() string
- func (e *ExTemplate) Execute(data any) (string, error)
- func (e *ExTemplate) Name() string
- func (e *ExTemplate) Parse(text string) error
- func (e *ExTemplate) ParseFiles(path string) error
- func (e *ExTemplate) ParseRequests(r *Route, env *config.Env) error
- type Group
- type Groups
- type Injectable
- type Route
- type RouteEvent
- type Taxonomies
- type Taxonomy
- type Term
- type Writable
Constants ¶
const SOCKET = `` /* 276-byte string literal not displayed */
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Build ¶
Build is a struct that represents a Build command.
type Context ¶
type Context struct { Groups Taxonomies Routes []Route }
Context is a collection of data shared by templates.
type ExTemplate ¶
type ExTemplate struct {
// contains filtered or unexported fields
}
ExTemplate is a wrapper around an internal template.Template that provides additional functions to make rendering Route instances easier.
func NewTemplate ¶
NewTemplate returns a new instance of *ExTemplate with all helper functions attached.
func (*ExTemplate) DefinedTemplates ¶
func (e *ExTemplate) DefinedTemplates() string
DefinedTemplates returns a string describing all of the templates parsed on the ExTemplate instance.
func (*ExTemplate) Execute ¶
func (e *ExTemplate) Execute(data any) (string, error)
Execute will execute the ExTemplate with the given data and return the result as a string.
func (*ExTemplate) Name ¶
func (e *ExTemplate) Name() string
Name returns the name of the ExTemplate.
func (*ExTemplate) Parse ¶
func (e *ExTemplate) Parse(text string) error
Parse will parse the given text into the ExTemplate. Error is nil unless the template cannot be parsed.
func (*ExTemplate) ParseFiles ¶
func (e *ExTemplate) ParseFiles(path string) error
ParseFiles will parse the file at the given path. Error is nil unless the template cannot be parsed.
func (*ExTemplate) ParseRequests ¶
func (e *ExTemplate) ParseRequests(r *Route, env *config.Env) error
ParseRequests will parse any additional templates requested by the given Route's .Template key.
type Group ¶
type Group struct { // Name is the name of the group, ie. "Posts" Name string // Members are instances of Injectable derived from routes that have been added to // the group. Members []Injectable }
type Groups ¶
type Groups []Group
type Injectable ¶
type Injectable struct { // Body is the fully rendered HTML body from the document that this Injectable // was originally derived from. It is used in a template as "{{ .Body }}". Body template.HTML // Taxonomies is an iterable of Taxonomy instances, and can be used to create lists // within templates as "{{ range .Taxonomies.Tags }}" -- "Tags" just being an example // taxonomy name. Taxonomies []Taxonomy // Date is a time.Time instance derived from the route's frontmatter. The property // is preserved as a time.Time so that .Format is available within a template. Date time.Time // Link is an automatically generated property that points to wherever the resource // is located in the final build. It is prefixed with the project's domain and used // in a template as "{{ .Link }}" Link string // Data contains any values that do not fulfill a known property which is handled in a // special manner, but should still be made available within the template. These values // will still be accessible from the top level after the .Flatten method is used on // the Injectable instance. // // The AddData method should be used to add items to the Data property to ensure that // all keys are title-cased. Data map[string]any }
Injectable contains values from a route that should be made available in a template. In this state, it may not be suitable to be injected into a template, but the .Flatten method can reduce the amount of prop drilling required to access properties within the .Data property and should be called before the template is executed.
func (*Injectable) AddData ¶
func (i *Injectable) AddData(key string, value any)
func (Injectable) Flatten ¶
func (i Injectable) Flatten() map[string]any
Flatten converts the Injectable to a map[string]any, reducing the amount of prop drilling required to access values within the .Data property.
type Route ¶
type Route struct { Raw string Path string Ext string Template string Group string Out string Link string Date time.Time Body template.HTML Head map[string]any Taxonomies []Taxonomy }
Route represents a file that is being processed as part of a project.
func (*Route) Injectable ¶
func (r *Route) Injectable(env *config.Env) Injectable
Injectable returns a map[string]any that contains the data from the calling Route that should be exposed to a template.
type RouteEvent ¶
Event is a struct passed through channels that may contain a route.
type Taxonomies ¶
type Taxonomies []Taxonomy
Taxonomies is a collection of Taxonomy instances that exposes helper functions to templates.
func (Taxonomies) Name ¶
func (t Taxonomies) Name(name string) Taxonomy
Name returns the named taxonomy from the Taxonomies instance.
type Taxonomy ¶
type Taxonomy struct { // Name is the name (ie 'tags' or 'categories') of the taxonomy. Name string // Out is the path that the taxonomy will be written to. Out string // Link is a URL that leads to the taxonomy. Link string // Terms is a collection of terms associated with the taxonomy. Terms []Term }
Taxonomy is a collection of related terms.
type Term ¶
type Term struct { // Name is the name (ie 'travel' or 'development') of the term. Name string // Out is the path that the term will be written to. Out string // Link is a URL that leads to the term. Link string // Routes is a collection of data derived from the routes that the term is assigned to. Routes []map[string]any }
Term is a unique taxonomical value.