config

package
v0.0.0-...-42d6f5d Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// See issue #8979 for context.
	// Hugo has always used config.toml etc. as the default config file name.
	// But hugo.toml is a more descriptive name, but we need to check for both.
	DefaultConfigNames = []string{"hugo", "config"}

	DefaultConfigNamesSet = make(map[string]bool)

	ValidConfigFileExtensions = []string{"toml", "yaml", "yml", "json"}
)
View Source
var (

	// ConfigRootKeysSet contains all of the config map root keys.
	ConfigRootKeysSet = map[string]bool{
		"build":         true,
		"caches":        true,
		"cascade":       true,
		"frontmatter":   true,
		"languages":     true,
		"imaging":       true,
		"markup":        true,
		"mediatypes":    true,
		"menus":         true,
		"minify":        true,
		"module":        true,
		"outputformats": true,
		"params":        true,
		"permalinks":    true,
		"related":       true,
		"sitemap":       true,
		"privacy":       true,
		"security":      true,
		"taxonomies":    true,
	}

	// ConfigRootKeys is a sorted version of ConfigRootKeysSet.
	ConfigRootKeys []string
)

Functions

func FromFileToMap

func FromFileToMap(fs afero.Fs, filename string) (map[string]any, error)

FromFileToMap is the same as FromFile, but it returns the config values as a simple map.

func GetNumWorkerMultiplier

func GetNumWorkerMultiplier() int

GetNumWorkerMultiplier returns the base value used to calculate the number of workers to use for Hugo's parallel execution. It returns the value in HUGO_NUMWORKERMULTIPLIER OS env variable if set to a positive integer, else the number of logical CPUs.

func GetStringSlicePreserveString

func GetStringSlicePreserveString(cfg Provider, key string) []string

GetStringSlicePreserveString returns a string slice from the given config and key. It differs from the GetStringSlice method in that if the config value is a string, we do not attempt to split it into fields.

func IsValidConfigFilename

func IsValidConfigFilename(filename string) bool

IsValidConfigFilename returns whether filename is one of the supported config formats in Hugo.

func RenameKeys

func RenameKeys(m map[string]any)

RenameKeys renames config keys in m recursively according to a global Hugo alias definition.

func SetEnvVars

func SetEnvVars(oldVars *[]string, keyValues ...string)

SetEnvVars sets vars on the form key=value in the oldVars slice.

func SplitEnvVar

func SplitEnvVar(v string) (string, string)

Types

type AllProvider

type AllProvider interface {
	Language() *langs.Language
	Languages() langs.Languages
	LanguagesDefaultFirst() langs.Languages
	LanguagePrefix() string
	BaseURL() urls.BaseURL
	BaseURLLiveReload() urls.BaseURL
	Environment() string
	IsMultihost() bool
	IsMultiLingual() bool
	NoBuildLock() bool
	BaseConfig() BaseConfig
	Dirs() CommonDirs
	Quiet() bool
	DirsBase() CommonDirs
	GetConfigSection(string) any
	GetConfig() any
	CanonifyURLs() bool
	DisablePathToLower() bool
	RemovePathAccents() bool
	IsUglyURLs(section string) bool
	DefaultContentLanguage() string
	DefaultContentLanguageInSubdir() bool
	IsLangDisabled(string) bool
	SummaryLength() int
	Paginate() int
	PaginatePath() string
	BuildExpired() bool
	BuildFuture() bool
	BuildDrafts() bool
	Running() bool
	PrintUnusedTemplates() bool
	EnableMissingTranslationPlaceholders() bool
	TemplateMetrics() bool
	TemplateMetricsHints() bool
	PrintI18nWarnings() bool
	CreateTitle(s string) string
	IgnoreFile(s string) bool
	NewContentEditor() string
	Timeout() time.Duration
	StaticDirs() []string
	IgnoredErrors() map[string]bool
	WorkingDir() string
}

AllProvider is a sub set of all config settings.

type BaseConfig

type BaseConfig struct {
	WorkingDir string
	CacheDir   string
	ThemesDir  string
	PublishDir string
}

type BuildConfig

type BuildConfig struct {
	UseResourceCacheWhen string // never, fallback, always. Default is fallback

	// When enabled, will collect and write a hugo_stats.json with some build
	// related aggregated data (e.g. CSS class names).
	// Note that this was a bool <= v0.115.0.
	BuildStats BuildStats

	// Can be used to toggle off writing of the IntelliSense /assets/jsconfig.js
	// file.
	NoJSConfigInAssets bool

	// Can used to control how the resource cache gets evicted on rebuilds.
	CacheBusters []CacheBuster
}

BuildConfig holds some build related configuration.

func DecodeBuildConfig

func DecodeBuildConfig(cfg Provider) BuildConfig

func (*BuildConfig) CompileConfig

func (b *BuildConfig) CompileConfig(logger loggers.Logger) error

func (BuildConfig) MatchCacheBuster

func (s BuildConfig) MatchCacheBuster(logger loggers.Logger, p string) (func(string) bool, error)

MatchCacheBuster returns the cache buster for the given path p, nil if none.

func (BuildConfig) UseResourceCache

func (b BuildConfig) UseResourceCache(err error) bool

type BuildStats

type BuildStats struct {
	Enable         bool
	DisableTags    bool
	DisableClasses bool
	DisableIDs     bool
}

BuildStats configures if and what to write to the hugo_stats.json file.

func (BuildStats) Enabled

func (w BuildStats) Enabled() bool

type CacheBuster

type CacheBuster struct {
	// Trigger for files matching this regexp.
	Source string

	// Cache bust targets matching this regexp.
	// This regexp can contain group matches (e.g. $1) from the source regexp.
	Target string
	// contains filtered or unexported fields
}

CacheBuster configures cache busting for assets.

func (*CacheBuster) CompileConfig

func (c *CacheBuster) CompileConfig(logger loggers.Logger) error

type CommonDirs

type CommonDirs struct {
	// The directory where Hugo will look for themes.
	ThemesDir string

	// Where to put the generated files.
	PublishDir string

	// The directory to put the generated resources files. This directory should in most situations be considered temporary
	// and not be committed to version control. But there may be cached content in here that you want to keep,
	// e.g. resources/_gen/images for performance reasons or CSS built from SASS when your CI server doesn't have the full setup.
	ResourceDir string

	// The project root directory.
	WorkingDir string

	// The root directory for all cache files.
	CacheDir string

	// The content source directory.
	// Deprecated: Use module mounts.
	ContentDir string
	// Deprecated: Use module mounts.
	// The data source directory.
	DataDir string
	// Deprecated: Use module mounts.
	// The layout source directory.
	LayoutDir string
	// Deprecated: Use module mounts.
	// The i18n source directory.
	I18nDir string
	// Deprecated: Use module mounts.
	// The archetypes source directory.
	ArcheTypeDir string
	// Deprecated: Use module mounts.
	// The assets source directory.
	AssetDir string
}

type ConfigNamespace

type ConfigNamespace[S, C any] struct {
	// SourceStructure represents the source configuration with any defaults applied.
	// This is used for documentation and printing of the configuration setup to the user.
	SourceStructure any

	// SourceHash is a hash of the source configuration before any defaults gets applied.
	SourceHash string

	// Config is the final configuration as used by Hugo.
	Config C
}

ConfigNamespace holds a Hugo configuration namespace. The construct looks a little odd, but it's built to make the configuration elements both self-documenting and contained in a common structure.

func DecodeNamespace

func DecodeNamespace[S, C any](configSource any, buildConfig func(any) (C, any, error)) (*ConfigNamespace[S, C], error)

func (*ConfigNamespace[S, C]) MarshalJSON

func (ns *ConfigNamespace[S, C]) MarshalJSON() ([]byte, error)

MarshalJSON marshals the source structure.

func (*ConfigNamespace[S, C]) Signature

func (ns *ConfigNamespace[S, C]) Signature() S

Signature returns the signature of the source structure. Note that this is for documentation purposes only and SourceStructure may not always be cast to S (it's usually just a map).

type Headers

type Headers struct {
	For    string
	Values map[string]any
}

type LoadConfigResult

type LoadConfigResult struct {
	Cfg         Provider
	ConfigFiles []string
	BaseConfig  BaseConfig
}

type Provider

type Provider interface {
	GetString(key string) string
	GetInt(key string) int
	GetBool(key string) bool
	GetParams(key string) maps.Params
	GetStringMap(key string) map[string]any
	GetStringMapString(key string) map[string]string
	GetStringSlice(key string) []string
	Get(key string) any
	Set(key string, value any)
	Keys() []string
	Merge(key string, value any)
	SetDefaults(params maps.Params)
	SetDefaultMergeStrategy()
	WalkParams(walkFn func(params ...maps.KeyParams) bool)
	IsSet(key string) bool
}

Provider provides the configuration settings for Hugo.

func FromConfigString

func FromConfigString(config, configType string) (Provider, error)

FromConfigString creates a config from the given YAML, JSON or TOML config. This is useful in tests.

func FromFile

func FromFile(fs afero.Fs, filename string) (Provider, error)

FromFile loads the configuration from the given filename.

func FromTOMLConfigString

func FromTOMLConfigString(config string) Provider

func LoadConfigFromDir

func LoadConfigFromDir(sourceFs afero.Fs, configDir, environment string) (Provider, []string, error)

func New

func New() Provider

New creates a Provider backed by an empty maps.Params.

func NewFrom

func NewFrom(params maps.Params) Provider

NewFrom creates a Provider backed by params.

type Redirect

type Redirect struct {
	From string
	To   string

	// HTTP status code to use for the redirect.
	// A status code of 200 will trigger a URL rewrite.
	Status int

	// Forcode redirect, even if original request path exists.
	Force bool
}

func (Redirect) IsZero

func (r Redirect) IsZero() bool

type Server

type Server struct {
	Headers   []Headers
	Redirects []Redirect
	// contains filtered or unexported fields
}

Config for the dev server.

func DecodeServer

func DecodeServer(cfg Provider) (Server, error)

func (*Server) CompileConfig

func (s *Server) CompileConfig(logger loggers.Logger) error

func (*Server) MatchHeaders

func (s *Server) MatchHeaders(pattern string) []types.KeyValueStr

func (*Server) MatchRedirect

func (s *Server) MatchRedirect(pattern string) Redirect

type SitemapConfig

type SitemapConfig struct {
	// The page change frequency.
	ChangeFreq string
	// The priority of the page.
	Priority float64
	// The sitemap filename.
	Filename string
}

SitemapConfig configures the sitemap to be generated.

func DecodeSitemap

func DecodeSitemap(prototype SitemapConfig, input map[string]any) (SitemapConfig, error)

Directories

Path Synopsis
Package allconfig contains the full configuration for Hugo.
Package allconfig contains the full configuration for Hugo.
This package should only be used for testing.
This package should only be used for testing.

Jump to

Keyboard shortcuts

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