build

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package build provides verless' core build functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx Context) []error

Run executes the build using the provided build context.

The current build implementation runs the following steps to build the static site:

  1. Read all Markdown files and send them through a channel.
  2. Spawn n workers reading from the channel, where n = `parallelism`.
  3. Build the pages concurrently: 3.1. Read the file as a []byte 3.2. Parse the file and convert it to a model.Page. 3.3. Register the page in the builder's site model. 3.4. Let each plugin process the page.
  4. Get the finished site model with all pages from the builder.
  5. Render that site model as HTML.
  6. Let each plugin finish its work, e.g. by writing a file.

For further info on one of these steps, see its implementation.

If any error occurs it is returned as a slice of errors as there can be several errors from the concurrent goroutines at the same time. If any error occurs all goroutines are stopped as soon as possible.

Types

type Builder

type Builder interface {
	// RegisterPage must be safe for concurrent usage.
	RegisterPage(page model.Page) error
	Dispatch() (model.Site, error)
}

Builder represents a model builder that maintains a Site instance and registers all parsed pages in that instance.

type Context

type Context struct {
	Path    string
	Parser  Parser
	Builder Builder
	Writer  Writer
	Plugins []Plugin
	Types   map[string]*model.Type
}

Context provides all components required for running a build.

type Parser

type Parser interface {
	// ParsePage must be safe for concurrent usage.
	ParsePage(src []byte) (model.Page, error)
}

Parser represents a parser that processes Markdown files and converts them into a model instance.

type Plugin

type Plugin interface {
	// ProcessPage will be invoked after parsing the page.
	// Must be safe for concurrent usage.
	ProcessPage(page *model.Page) error
	// PreWrite will be invoked before writing the site.
	PreWrite(site *model.Site) error
	// PostWrite will be invoked after writing the site.
	PostWrite() error
}

Plugin represents a built-in verless plugin.

type Writer

type Writer interface {
	Write(site model.Site) error
}

Writer represents a model writer that renders the site model as HTML using the corresponding templates.

Jump to

Keyboard shortcuts

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