diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-07-01 10:37:38 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-07-01 15:38:32 +0200 |
commit | 11ecea610617035745e620278a309d98091f527c (patch) | |
tree | 5678f3a089542b80316f3ee1ebdb7bc3aa9197fe /config | |
parent | da98724bc8bd28532222fb379af7a3782e2a9480 (diff) |
Make build.writeStats a struct
So you can do
```toml
[build.writeStats]
tags = true
classes = true
ids = false
```
Fixes #11191
Diffstat (limited to 'config')
-rw-r--r-- | config/commonConfig.go | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/config/commonConfig.go b/config/commonConfig.go index 09f81c1ba..037499465 100644 --- a/config/commonConfig.go +++ b/config/commonConfig.go @@ -82,7 +82,7 @@ type LoadConfigResult struct { var defaultBuild = BuildConfig{ UseResourceCacheWhen: "fallback", - WriteStats: false, + WriteStats: WriteStats{}, CacheBusters: []CacheBuster{ { @@ -111,7 +111,8 @@ type BuildConfig struct { // When enabled, will collect and write a hugo_stats.json with some build // related aggregated data (e.g. CSS class names). - WriteStats bool + // Note that this was a bool <= v0.115.0. + WriteStats WriteStats // Can be used to toggle off writing of the IntelliSense /assets/jsconfig.js // file. @@ -121,6 +122,17 @@ type BuildConfig struct { CacheBusters []CacheBuster } +// WriteStats configures what to write to the hugo_stats.json file. +type WriteStats struct { + Tags bool + Classes bool + IDs bool +} + +func (w WriteStats) Enabled() bool { + return w.Tags || w.Classes || w.IDs +} + func (b BuildConfig) clone() BuildConfig { b.CacheBusters = append([]CacheBuster{}, b.CacheBusters...) return b @@ -171,14 +183,26 @@ func (b *BuildConfig) CompileConfig(logger loggers.Logger) error { func DecodeBuildConfig(cfg Provider) BuildConfig { m := cfg.GetStringMap("build") + b := defaultBuild.clone() if m == nil { return b } + // writeStats was a bool <= v0.115.0. + if writeStats, ok := m["writestats"]; ok { + if bb, ok := writeStats.(bool); ok { + m["writestats"] = WriteStats{ + Tags: bb, + Classes: bb, + IDs: bb, + } + } + } + err := mapstructure.WeakDecode(m, &b) if err != nil { - return defaultBuild + return b } b.UseResourceCacheWhen = strings.ToLower(b.UseResourceCacheWhen) |