From 11ecea610617035745e620278a309d98091f527c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sat, 1 Jul 2023 10:37:38 +0200 Subject: Make build.writeStats a struct So you can do ```toml [build.writeStats] tags = true classes = true ids = false ``` Fixes #11191 --- config/commonConfig.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'config') 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) -- cgit v1.2.3