config

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: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Recognized configuration file names.
	BaseName      string = "onyx"
	YamlLongName  string = BaseName + ".yaml"
	YamlShortName string = BaseName + ".yml"
	JsonName      string = BaseName + ".json"
	// Defaults for file reading/writing, etc
	DefFilePerm fs.FileMode = 0644
	DefDirPerm  fs.FileMode = 0755
	DefDateFmt  string      = "2006-01-02"
)

Variables

Names contains all recognized project configuration file names.

Functions

This section is empty.

Types

type Env

type Env struct {
	Options Options
	Args    map[string]any
}

Env is a struct that contains the parsed arguments that were passed to the program, an instance of Options derived from the project's configuration file, and has methods to check state.

func NewEnv

func NewEnv() *Env

NewEnv returns a new instance of Env.

func (*Env) BaseFilter

func (e *Env) BaseFilter(path string, d fs.DirEntry) error

BaseFilter is a Filter that will allow files that appear to be base templates.

func (*Env) Domain

func (e *Env) Domain() string

Domain returns the domain value in the env's options, or a default (/) value.

func (*Env) FileFilter

func (e *Env) FileFilter(path string, d fs.DirEntry) error

FileFilter is a Filter that will return any file.

func (*Env) Filter

func (e *Env) Filter(dir string, f FilterType) <-chan WalkEvent

Filter will return a channel and send any files in the given directory that match the given filter through the channel. An error will be returned if the directory cannot be accessed.

func (*Env) Get

func (e *Env) Get(key string) any

Get returns the value of key within Env as any.

func (*Env) GetBool

func (e *Env) GetBool(key string) bool

GetString returns the value of key within Env as bool.

func (*Env) GetInt

func (e *Env) GetInt(key string) int

GetInt returns the value of key within Env as int.

func (*Env) GetString

func (e *Env) GetString(key string) string

GetString returns the value of key within Env as string.

func (*Env) IsAllowedBase

func (e *Env) IsAllowedBase(path string) bool

IsAllowedBase will return true when the given path leads to file that matches the naming convention of a base template. [base.tmpl | base_*.tmpl]

func (*Env) IsAllowedRoute

func (e *Env) IsAllowedRoute(path string) bool

IsAllowedRoute will return true when the given path leads to a recognized file type.

func (*Env) IsIgnored

func (e *Env) IsIgnored(path string) bool

IsIgnored will return true when the given path is ignored.

func (*Env) List

func (e *Env) List() string

Returns the name of the template used to render taxonomies.

func (*Env) Out

func (e *Env) Out(link string) string

Out will return a write path for the given link that is relative the project's output directory.

func (*Env) Output

func (e *Env) Output() string

Output returns a path to the output directory of the project.

func (*Env) Root

func (e *Env) Root() string

Root returns a path to the root of the project.

func (*Env) RouteFilter

func (e *Env) RouteFilter(path string, d fs.DirEntry) error

RouteFilter is a Filter that will allow files of a recognized file type.

func (*Env) Routes

func (e *Env) Routes() string

Routes returns a path to the routes directory of the project.

func (*Env) Scan

func (e *Env) Scan() (*Manifest, error)

Scan will scan the project and return a Manifest that details the location and types of files in the project.

func (*Env) Single

func (e *Env) Single() string

Returns the name of the template used to render terms.

func (*Env) Static

func (e *Env) Static() string

Static returns a path to the static directory of the project.

func (*Env) Templates

func (e *Env) Templates() string

Templates returns a path to the templates directory of the project.

func (*Env) Verbose

func (e *Env) Verbose() bool

Verbose will return true if the project is running in verbose mode.

type FilterType

type FilterType func(path string, d fs.DirEntry) error

Filter is a function that returns an error when the given path and/or fs.DirEntry do not meet the requirements of the filter.

type Ignore

type Ignore struct {
	Prefix string `json:"prefix"`
	Suffix string `json:"suffix"`
}

Ignore provides an obvious way to ignore files based on a prefix or suffix.

type Manifest

type Manifest struct {
	// Paths to files that will become routes.
	Routes []string
	// Paths to files that are static, and will not be transformed.
	Static []string
	// Path to any additional base templates.
	BaseAlt []string
	// Path to the base template.
	Base string
}

Manifest is an overview of the files available in a project.

type Markdown

type Markdown struct {
	Unsafe bool `json:"unsafe"`
}

Controls markdown conversion behavior.

type Options

type Options struct {
	// Domain is used to prefix all output paths.
	Domain string `json:"domain"`
	// Output controls the location that the resulting files are placed.
	Output string `json:"output"`
	// Verbose determines how much information is logged.
	Verbose    bool `json:"verbose"`
	Taxonomies `json:"taxonomies"`
	Markdown   `json:"markdown"`
	Ignore     `json:"ignore"`
}

Options describes all of the values that might be found in a project's configuration file.

func Setup

func Setup(dir string) (Options, error)

Setup will return an instance of Options from a recognized configuration file in the given directory, or a default Options instance if a file is not found. An error is returned if a file is found but cannot be read or unmarshalled.

type Taxonomies

type Taxonomies struct {
	List   string     `json:"list"`
	Single string     `json:"single"`
	Sets   []Taxonomy `json:"sets"`
}

Taxonomies provides a way to identify a piece of metadata as a taxonomy.

type Taxonomy

type Taxonomy struct {
	Name string `json:"name"`
	Alt  string `json:"alt"`
}

Taxonomy provides a way to define which frontmatter fields are taxonomies.

type WalkEvent

type WalkEvent struct {
	Path string
	Err  error
}

WalkEvent is a struct that contains a string path and an error.

Jump to

Keyboard shortcuts

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