config

package
v0.139.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: Apache-2.0 Imports: 28 Imported by: 410

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 added in v0.54.0

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 GetMemoryLimit added in v0.123.0

func GetMemoryLimit() uint64

GetMemoryLimit returns the upper memory limit in bytes for Hugo's in-memory caches. Note that this does not represent "all of the memory" that Hugo will use, so it needs to be set to a lower number than the available system memory. It will read from the HUGO_MEMORYLIMIT (in Gigabytes) environment variable. If that is not set, it will set aside a quarter of the total system memory.

func GetNumWorkerMultiplier added in v0.55.0

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 added in v0.42.1

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 added in v0.54.0

func IsValidConfigFilename(filename string) bool

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

func RenameKeys added in v0.54.0

func RenameKeys(m map[string]any)

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

func SetEnvVars added in v0.56.0

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

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

func SplitEnvVar added in v0.56.0

func SplitEnvVar(v string) (string, string)

Types

type AllProvider added in v0.112.0

type AllProvider interface {
	Language() *langs.Language
	Languages() langs.Languages
	LanguagesDefaultFirst() langs.Languages
	LanguagePrefix() string
	BaseURL() urls.BaseURL
	BaseURLLiveReload() urls.BaseURL
	PathParser() *paths.PathParser
	Environment() string
	IsMultihost() bool
	IsMultilingual() bool
	NoBuildLock() bool
	BaseConfig() BaseConfig
	Dirs() CommonDirs
	Quiet() bool
	DirsBase() CommonDirs
	ContentTypes() ContentTypesProvider
	GetConfigSection(string) any
	GetConfig() any
	CanonifyURLs() bool
	DisablePathToLower() bool
	RemovePathAccents() bool
	IsUglyURLs(section string) bool
	DefaultContentLanguage() string
	DefaultContentLanguageInSubdir() bool
	IsLangDisabled(string) bool
	SummaryLength() int
	Pagination() Pagination
	BuildExpired() bool
	BuildFuture() bool
	BuildDrafts() bool
	Running() bool
	Watching() bool
	NewIdentityManager(name string) identity.Manager
	FastRenderMode() 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
	IgnoredLogs() map[string]bool
	WorkingDir() string
	EnableEmoji() bool
}

AllProvider is a sub set of all config settings.

type BaseConfig added in v0.112.0

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

type BuildConfig added in v0.112.0

type BuildConfig struct {
	// When to use the resource file cache.
	// One of never, fallback, always. Default is fallback
	UseResourceCacheWhen string

	// 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 added in v0.112.0

func DecodeBuildConfig(cfg Provider) BuildConfig

func (*BuildConfig) CompileConfig added in v0.112.0

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

func (BuildConfig) MatchCacheBuster added in v0.112.0

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 added in v0.112.0

func (b BuildConfig) UseResourceCache(err error) bool

type BuildStats added in v0.115.1

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 added in v0.115.1

func (w BuildStats) Enabled() bool

type CacheBuster added in v0.112.0

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 added in v0.112.0

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

type CommonDirs added in v0.112.0

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 added in v0.112.0

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 added in v0.112.0

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

func (*ConfigNamespace[S, C]) MarshalJSON added in v0.112.0

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

MarshalJSON marshals the source structure.

func (*ConfigNamespace[S, C]) Signature added in v0.112.0

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 ContentTypesProvider added in v0.126.0

type ContentTypesProvider interface {
	IsContentSuffix(suffix string) bool
	IsContentFile(filename string) bool
	IsIndexContentFile(filename string) bool
	IsHTMLSuffix(suffix string) bool
}

We cannot import the media package as that would create a circular dependency. This interface defineds a sub set of what media.ContentTypes provides.

type Headers added in v0.67.0

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

type LoadConfigResult added in v0.112.0

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

type PageConfig added in v0.133.0

type PageConfig struct {
	// Sort order for Page.Next and Page.Prev. Default "desc" (the default page sort order in Hugo).
	NextPrevSortOrder string

	// Sort order for Page.NextInSection and Page.PrevInSection. Default "desc".
	NextPrevInSectionSortOrder string
}

PageConfig configures the behavior of pages.

func (*PageConfig) CompileConfig added in v0.133.0

func (c *PageConfig) CompileConfig(loggers.Logger) error

type Pagination added in v0.128.0

type Pagination struct {
	//  Default number of elements per pager in pagination.
	PagerSize int

	// The path element used during pagination.
	Path string

	// Whether to disable generation of alias for the first pagination page.
	DisableAliases bool
}

Pagination configures the pagination behavior.

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 added in v0.42.1

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 added in v0.54.0

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

FromFile loads the configuration from the given filename.

func FromTOMLConfigString added in v0.112.0

func FromTOMLConfigString(config string) Provider

func LoadConfigFromDir added in v0.84.0

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

func New added in v0.84.0

func New() Provider

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

func NewFrom added in v0.84.0

func NewFrom(params maps.Params) Provider

NewFrom creates a Provider backed by params.

type Redirect added in v0.72.0

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 added in v0.72.0

func (r Redirect) IsZero() bool

type Server added in v0.67.0

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

Config for the dev server.

func DecodeServer added in v0.67.0

func DecodeServer(cfg Provider) (Server, error)

func (*Server) CompileConfig added in v0.112.0

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

func (*Server) MatchHeaders added in v0.72.0

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

func (*Server) MatchRedirect added in v0.72.0

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

type SitemapConfig added in v0.112.0

type SitemapConfig struct {
	// The page change frequency.
	ChangeFreq string
	// The priority of the page.
	Priority float64
	// The sitemap filename.
	Filename string
	// Whether to disable page inclusion.
	Disable bool
}

SitemapConfig configures the sitemap to be generated.

func DecodeSitemap added in v0.55.0

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