package config
import "github.com/gohugoio/hugo/config"
Index ¶
- Variables
- func FromFileToMap(fs afero.Fs, filename string) (map[string]any, error)
- func GetMemoryLimit() uint64
- func GetNumWorkerMultiplier() int
- func GetStringSlicePreserveString(cfg Provider, key string) []string
- func IsValidConfigFilename(filename string) bool
- func RenameKeys(m map[string]any)
- func SetEnvVars(oldVars *[]string, keyValues ...string)
- func SplitEnvVar(v string) (string, string)
- type AllProvider
- type BaseConfig
- type BuildConfig
- func DecodeBuildConfig(cfg Provider) BuildConfig
- func (b *BuildConfig) CompileConfig(logger loggers.Logger) error
- func (s BuildConfig) MatchCacheBuster(logger loggers.Logger, p string) (func(string) bool, error)
- func (b BuildConfig) UseResourceCache(err error) bool
- type BuildStats
- type CacheBuster
- type CommonDirs
- type ConfigNamespace
- func DecodeNamespace[S, C any](configSource any, buildConfig func(any) (C, any, error)) (*ConfigNamespace[S, C], error)
- func (ns *ConfigNamespace[S, C]) MarshalJSON() ([]byte, error)
- func (ns *ConfigNamespace[S, C]) Signature() S
- type ContentTypesProvider
- type Headers
- type LoadConfigResult
- type PageConfig
- type Pagination
- type Provider
- func FromConfigString(config, configType string) (Provider, error)
- func FromFile(fs afero.Fs, filename string) (Provider, error)
- func FromTOMLConfigString(config string) Provider
- func LoadConfigFromDir(sourceFs afero.Fs, configDir, environment string) (Provider, []string, error)
- func New() Provider
- func NewFrom(params maps.Params) Provider
- type Redirect
- type Server
- func DecodeServer(cfg Provider) (Server, error)
- func (s *Server) CompileConfig(logger loggers.Logger) error
- func (s *Server) MatchHeaders(pattern string) []types.KeyValueStr
- func (s *Server) MatchRedirect(pattern string, header http.Header) Redirect
- type SitemapConfig
Variables ¶
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"} )
Functions ¶
func FromFileToMap ¶
FromFileToMap is the same as FromFile, but it returns the config values as a simple map.
func GetMemoryLimit ¶
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 ¶
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 ¶
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 ¶
IsValidConfigFilename returns whether filename is one of the supported config formats in Hugo.
func RenameKeys ¶
RenameKeys renames config keys in m recursively according to a global Hugo alias definition.
func SetEnvVars ¶
SetEnvVars sets vars on the form key=value in the oldVars slice.
func SplitEnvVar ¶
Types ¶
type AllProvider ¶
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, opts ...identity.ManagerOption) 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 ¶
type BuildConfig ¶
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 ¶
func DecodeBuildConfig(cfg Provider) BuildConfig
func (*BuildConfig) CompileConfig ¶
func (b *BuildConfig) CompileConfig(logger loggers.Logger) error
func (BuildConfig) MatchCacheBuster ¶
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 ¶
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 ContentTypesProvider ¶
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 ¶
type LoadConfigResult ¶
type LoadConfigResult struct { Cfg Provider ConfigFiles []string BaseConfig BaseConfig }
type PageConfig ¶
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 ¶
func (c *PageConfig) CompileConfig(loggers.Logger) error
type Pagination ¶
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 ¶
FromConfigString creates a config from the given YAML, JSON or TOML config. This is useful in tests.
func FromFile ¶
FromFile loads the configuration from the given filename.
func FromTOMLConfigString ¶
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 ¶
NewFrom creates a Provider backed by params.
type Redirect ¶
type Redirect struct { // From is the Glob pattern to match. // One of From or FromRe must be set. From string // FromRe is the regexp to match. // This regexp can contain group matches (e.g. $1) that can be used in the To field. // One of From or FromRe must be set. FromRe string // To is the target URL. To string // Headers to match for the redirect. // This maps the HTTP header name to a Glob pattern with values to match. // If the map is empty, the redirect will always be triggered. FromHeaders map[string]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 ¶
type Server ¶
type Server struct { Headers []Headers Redirects []Redirect // contains filtered or unexported fields }
Config for the dev server.
func DecodeServer ¶
func (*Server) CompileConfig ¶
func (*Server) MatchHeaders ¶
func (s *Server) MatchHeaders(pattern string) []types.KeyValueStr
func (*Server) MatchRedirect ¶
type SitemapConfig ¶
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 ¶
func DecodeSitemap(prototype SitemapConfig, input map[string]any) (SitemapConfig, error)
Source Files ¶
commonConfig.go configLoader.go configProvider.go defaultConfigProvider.go env.go namespace.go
Directories ¶
Path | Synopsis |
---|---|
config/allconfig | Package allconfig contains the full configuration for Hugo. |
config/privacy | |
config/security | |
config/services | |
config/testconfig | This package should only be used for testing. |
- Version
- v0.144.2 (latest)
- Published
- Feb 19, 2025
- Platform
- linux/amd64
- Imports
- 29 packages
- Last checked
- 13 hours ago –
Tools for package owners.