Create a struct with all of Hugo's config options

Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes #10896
Closes #10620
This commit is contained in:
Bjørn Erik Pedersen
2023-01-04 18:24:36 +01:00
parent 6aededf6b4
commit 241b21b0fd
337 changed files with 13377 additions and 14898 deletions

View File

@@ -15,7 +15,6 @@ package minifiers
import (
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/docshelper"
"github.com/gohugoio/hugo/parser"
"github.com/spf13/cast"
@@ -29,7 +28,7 @@ import (
"github.com/tdewolff/minify/v2/xml"
)
var defaultTdewolffConfig = tdewolffConfig{
var defaultTdewolffConfig = TdewolffConfig{
HTML: html.Minifier{
KeepDocumentTags: true,
KeepConditionalComments: true,
@@ -52,7 +51,7 @@ var defaultTdewolffConfig = tdewolffConfig{
},
}
type tdewolffConfig struct {
type TdewolffConfig struct {
HTML html.Minifier
CSS css.Minifier
JS js.Minifier
@@ -61,7 +60,7 @@ type tdewolffConfig struct {
XML xml.Minifier
}
type minifyConfig struct {
type MinifyConfig struct {
// Whether to minify the published output (the HTML written to /public).
MinifyOutput bool
@@ -72,30 +71,20 @@ type minifyConfig struct {
DisableSVG bool
DisableXML bool
Tdewolff tdewolffConfig
Tdewolff TdewolffConfig
}
var defaultConfig = minifyConfig{
var defaultConfig = MinifyConfig{
Tdewolff: defaultTdewolffConfig,
}
func decodeConfig(cfg config.Provider) (conf minifyConfig, err error) {
func DecodeConfig(v any) (conf MinifyConfig, err error) {
conf = defaultConfig
// May be set by CLI.
conf.MinifyOutput = cfg.GetBool("minifyOutput")
v := cfg.Get("minify")
if v == nil {
return
}
// Legacy.
if b, ok := v.(bool); ok {
conf.MinifyOutput = b
return
}
m := maps.ToStringMap(v)
// Handle upstream renames.