build

package
v0.0.0-...-299fa76 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const SOCKET = `` /* 276-byte string literal not displayed */

Variables

This section is empty.

Functions

func Dir

func Dir() func(path string) string

Dir returns a function that can return the parent directory of a path.

func Domain

func Domain(e *config.Env) func(path string) string

Domain prefixes the path with the domain set in the project's configuration file.

func Helpers

func Helpers(e *config.Env) template.FuncMap

Helpers returns a template.FuncMap containing all included functions.

func Map

func Map() func(values ...interface{}) (map[string]interface{}, error)

func Named

func Named() any

Named returns the named taxonomy from a slice of taxonomies.

func Partial

func Partial(e *config.Env) func(path string, data any) template.HTML

Partial returns a function that can render a partial in a template.

func Syntax

func Syntax() func(lang, text string) template.HTML

func TrimSpace

func TrimSpace() func(text string) string

func Write

func Write(w Writable, output string, mem *memfs.FS, env *config.Env) error

Write will commit the Writable to the given instance of memfs.FS, or if that is null, it will write to disk. The Writable.To path is appended to the given output.

Types

type Build

type Build struct {
	*memfs.FS
	*Context
}

Build is a struct that represents a Build command.

func (*Build) Execute

func (rt *Build) Execute(env *config.Env) error

Execute will start the command.

func (*Build) Name

func (b *Build) Name() string

Name will return the name of the command.

func (*Build) Parse

func (b *Build) Parse(args []string) (map[string]any, error)

Parse will use the internal flag.FlagSet to parse the given arguments.

type Context

type Context struct {
	Groups
	Taxonomies
	Routes []Route
}

Context is a collection of data shared by templates.

func NewContext

func NewContext() *Context

New creates a new context.

func (*Context) AddRoute

func (c *Context) AddRoute(r Route, env *config.Env)

Add will add the given route to the context.

func (*Context) Eject

func (c *Context) Eject(extra map[string]any) map[string]any

Eject will return a map[string]any that contains the values of the context. If the Extra parameter is not nil, any values within the map are included in the return value, nested under a "Data" key.

func (*Context) Sort

func (c *Context) Sort()

Sort will sort the groups within the context and assemble all taxonomy values. The context should always be sorted before it is used to render.

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

func NewTemplate(name string, manifest *config.Manifest, env *config.Env) (*ExTemplate, error)

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
}

func NewGroup

func NewGroup(name string) *Group

type Groups

type Groups []Group

func (Groups) Find

func (g Groups) Find(name string) Group

Find returns the named group from the Groups instance.

func (Groups) Members

func (g Groups) Members(name string) []map[string]any

Members returns the flattened members of the named group from the Groups instance.

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 NewRoute

func NewRoute(name string, c *Context, manifest *config.Manifest, env *config.Env) (Route, error)

NewRoute creates and initializes a new Route from the file at the given path.

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.

func (*Route) Render

func (r *Route) Render(context *Context, manifest *config.Manifest, env *config.Env) (Writable, error)

type RouteEvent

type RouteEvent struct {
	Route
	Err error
}

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.

func (*Taxonomy) Render

func (t *Taxonomy) Render(context *Context, manifest *config.Manifest, env *config.Env) ([]Writable, error)

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.

type Writable

type Writable struct {
	// A path to the final destination of the data.
	From, To string
	// The data to be written.
	Data string
}

Writable represents a piece of data that is ready to be written to a filesystem.

func NewWritable

func NewWritable(from string, env *config.Env) (Writable, error)

NewWritable returns a Writable from the file at the given path.

Jump to

Keyboard shortcuts

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