config

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config loads, defaults and validates tryck.config.yaml.

Precedence is CLI flag > config file > built-in default: Load merges the file over Defaults, then Apply layers CLI overrides on top.

Index

Constants

View Source
const DefaultPath = "tryck.config.yaml"

DefaultPath is the config file looked up when --config is not given.

View Source
const ThemeFile = "theme.yaml"

ThemeFile is a theme folder's settings file.

Variables

This section is empty.

Functions

func ValidVersionName added in v0.4.0

func ValidVersionName(name string) bool

ValidVersionName reports whether name can name a version: one URL segment of letters, digits, '.', '-' and '_'.

Types

type BuildConfig

type BuildConfig struct {
	ContentDir  string `yaml:"contentDir"`
	OutputDir   string `yaml:"outputDir"`
	StaticDir   string `yaml:"staticDir"`
	LayoutsDir  string `yaml:"layoutsDir"`
	PluginsDir  string `yaml:"pluginsDir"`
	CleanOutput bool   `yaml:"cleanOutput"`
	Drafts      bool   `yaml:"drafts"`
	UnsafeHTML  bool   `yaml:"unsafeHTML"`
	LastUpdated bool   `yaml:"lastUpdated"` // read each page's last commit date from git
	Workers     int    `yaml:"workers"`     // 0 = runtime.NumCPU()
}

type Config

type Config struct {
	Site     SiteConfig     `yaml:"site"`
	Build    BuildConfig    `yaml:"build"`
	Defaults DefaultsConfig `yaml:"defaults"`
	Theme    ThemeConfig    `yaml:"theme"`
	Versions VersionsConfig `yaml:"versions"`
	Images   ImagesConfig   `yaml:"images"`
	// Plugins maps a plugin's config name to its raw section. Each plugin
	// decodes its own section.
	Plugins map[string]map[string]any `yaml:"plugins"`

	// Path is the config file that was loaded, or "" if none was found.
	Path string `yaml:"-"`
	// Root is the project root. Relative build directories resolve
	// against it. It is the directory holding the config file.
	Root string `yaml:"-"`
}

Config is the fully loaded site configuration.

func Defaults

func Defaults() *Config

Defaults returns the built-in configuration.

func Load

func Load(path string, required bool) (*Config, []diag.Diagnostic)

Load reads the config file at path and merges it over Defaults.

A missing file is fine unless required is set (the user passed --config explicitly). The returned Config is always usable; callers must check the diagnostics for errors.

func (*Config) Apply

func (c *Config) Apply(o Overrides)

Apply layers CLI overrides on top of the loaded config.

func (*Config) ContentVersions added in v0.4.0

func (c *Config) ContentVersions() []Version

ContentVersions lists the site's content trees, the current one first. An unversioned site has one, with an empty name.

func (*Config) Dir

func (c *Config) Dir(p string) string

Dir resolves a configured directory against the project root.

func (*Config) LayoutDirs

func (c *Config) LayoutDirs() []string

LayoutDirs lists the layout directories, lowest priority first: the theme's layouts/, then the site's layoutsDir.

func (*Config) PluginDirs added in v0.3.0

func (c *Config) PluginDirs() []string

PluginDirs lists the script plugin directories, lowest priority first: the theme's plugins/, then the site's pluginsDir.

func (*Config) StaticDirs

func (c *Config) StaticDirs() []string

StaticDirs lists the static directories, lowest priority first: the theme's static/, then the site's staticDir.

func (*Config) ThemeDir

func (c *Config) ThemeDir() string

ThemeDir is the theme folder, or "" when no theme is set.

func (*Config) Validate

func (c *Config) Validate() []diag.Diagnostic

Validate checks values that decode fine but make no sense.

func (*Config) WorkerCount

func (c *Config) WorkerCount() int

WorkerCount resolves build.workers, where 0 means one per CPU.

type DefaultsConfig

type DefaultsConfig struct {
	Layout     string `yaml:"layout"`
	TOC        bool   `yaml:"toc"`
	TOCDepth   [2]int `yaml:"tocDepth"` // min and max heading level
	DateFormat string `yaml:"dateFormat"`
	// HeadingAnchors adds a "#" link to every heading below h1.
	HeadingAnchors bool `yaml:"headingAnchors"`
	// ImageAttributes sets width, height and loading="lazy" on Markdown
	// images.
	ImageAttributes bool `yaml:"imageAttributes"`
}

type ImagesConfig added in v0.7.0

type ImagesConfig struct {
	Resize  bool   `yaml:"resize"`  // write smaller copies and a srcset
	Widths  []int  `yaml:"widths"`  // widths of the copies, in pixels
	Quality int    `yaml:"quality"` // JPEG quality, 1-100
	Sizes   string `yaml:"sizes"`   // the sizes attribute
}

ImagesConfig controls resized copies of Markdown images.

type NavLink struct {
	Title string `yaml:"title"`
	URL   string `yaml:"url"`
}

NavLink is a header link.

type Overrides

type Overrides struct {
	OutputDir *string
	BaseURL   *string
	Drafts    *bool
	Workers   *int
}

Overrides holds values from CLI flags. Nil fields are not set.

type SiteConfig

type SiteConfig struct {
	Title       string `yaml:"title"`
	Description string `yaml:"description"`
	BaseURL     string `yaml:"baseUrl"`
	Language    string `yaml:"language"`
}

type ThemeConfig

type ThemeConfig struct {
	Path        string         `yaml:"path"`        // theme folder with layouts/, static/ and theme.yaml
	Accent      string         `yaml:"accent"`      // CSS color for links, active nav and tabs
	AccentDark  string         `yaml:"accentDark"`  // accent in dark mode; default: accent mixed with white
	ColorScheme string         `yaml:"colorScheme"` // auto (with a toggle), light or dark
	Nav         []NavLink      `yaml:"nav"`         // header links
	Footer      string         `yaml:"footer"`      // inline Markdown
	EditURL     string         `yaml:"editUrl"`     // prefix for "Edit this page" links; the file's path from the project root follows
	CSS         []string       `yaml:"css"`         // extra stylesheets, linked after the theme's
	Params      map[string]any `yaml:"params"`      // free-form values for custom themes
}

ThemeConfig selects an optional theme folder and sets the options of the built-in theme. A theme folder's theme.yaml supplies defaults for every key except path; the site config wins.

type Version added in v0.4.0

type Version struct {
	Name    string // "" for an unversioned site
	Dir     string // the content directory
	Prefix  string // URL prefix: "/" for the current version, "/<name>/" for older ones
	Current bool
}

Version is a content tree of the site and where it is served.

type VersionConfig added in v0.4.0

type VersionConfig struct {
	Name string `yaml:"name"`
	Dir  string `yaml:"dir"` // default: versions/<name>
}

VersionConfig is one older version: a snapshot of the content served under /<name>/.

type VersionsConfig added in v0.4.0

type VersionsConfig struct {
	Current string          `yaml:"current"`
	Older   []VersionConfig `yaml:"older"`
}

VersionsConfig names the current version (contentDir) and lists older versions, newest first. Without older versions the site is unversioned.

Jump to

Keyboard shortcuts

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