Skip to content

Commit 851bf35

Browse files
committed
Add all config to docshelper.json
Also consolidate so the mediaTypes and outputFormats are listed once only. Fixes gohugoio#11328
1 parent d4a6c16 commit 851bf35

File tree

15 files changed

+784
-531
lines changed

15 files changed

+784
-531
lines changed

commands/gen.go

+10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
"github.com/gohugoio/hugo/docshelper"
3131
"github.com/gohugoio/hugo/helpers"
3232
"github.com/gohugoio/hugo/hugofs"
33+
"github.com/gohugoio/hugo/hugolib"
34+
"github.com/gohugoio/hugo/parser"
3335
"github.com/spf13/cobra"
3436
"github.com/spf13/cobra/doc"
3537
)
@@ -197,6 +199,14 @@ url: %s
197199
enc := json.NewEncoder(f)
198200
enc.SetIndent("", " ")
199201

202+
configProvider := func() docshelper.DocProvider {
203+
conf := hugolib.DefaultConfig()
204+
conf.CacheDir = "" // The default value does not make sense in the docs.
205+
defaultConfig := parser.LowerCaseCamelJSONMarshaller{Value: conf}
206+
return docshelper.DocProvider{"config": defaultConfig}
207+
}
208+
209+
docshelper.AddDocProviderFunc(configProvider)
200210
if err := enc.Encode(docshelper.GetDocProvider()); err != nil {
201211
return err
202212
}

config/allconfig/alldecoders.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ type decodeConfig struct {
4949
}
5050

5151
type decodeWeight struct {
52-
key string
53-
decode func(decodeWeight, decodeConfig) error
54-
getCompiler func(c *Config) configCompiler
55-
weight int
52+
key string
53+
decode func(decodeWeight, decodeConfig) error
54+
getCompiler func(c *Config) configCompiler
55+
weight int
56+
internalOrDeprecated bool // Hide it from the docs.
5657
}
5758

5859
var allDecoderSetups = map[string]decodeWeight{
@@ -340,13 +341,15 @@ var allDecoderSetups = map[string]decodeWeight{
340341
p.c.Author = maps.CleanConfigStringMap(p.p.GetStringMap(d.key))
341342
return nil
342343
},
344+
internalOrDeprecated: true,
343345
},
344346
"social": {
345347
key: "social",
346348
decode: func(d decodeWeight, p decodeConfig) error {
347349
p.c.Social = maps.CleanConfigStringMapString(p.p.GetStringMapString(d.key))
348350
return nil
349351
},
352+
internalOrDeprecated: true,
350353
},
351354
"uglyurls": {
352355
key: "uglyurls",
@@ -362,12 +365,14 @@ var allDecoderSetups = map[string]decodeWeight{
362365
}
363366
return nil
364367
},
368+
internalOrDeprecated: true,
365369
},
366370
"internal": {
367371
key: "internal",
368372
decode: func(d decodeWeight, p decodeConfig) error {
369373
return mapstructure.WeakDecode(p.p.GetStringMap(d.key), &p.c.Internal)
370374
},
375+
internalOrDeprecated: true,
371376
},
372377
}
373378

config/docshelper.go config/allconfig/docshelper.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2021 The Hugo Authors. All rights reserved.
1+
// Copyright 2023 The Hugo Authors. All rights reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -11,19 +11,23 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14-
package config
14+
package allconfig
1515

1616
import (
1717
"github.com/gohugoio/hugo/common/maps"
18+
"github.com/gohugoio/hugo/config"
1819
"github.com/gohugoio/hugo/docshelper"
1920
)
2021

2122
// This is is just some helpers used to create some JSON used in the Hugo docs.
2223
func init() {
2324
docsProvider := func() docshelper.DocProvider {
2425

25-
cfg := New()
26-
for _, configRoot := range ConfigRootKeys {
26+
cfg := config.New()
27+
for configRoot, v := range allDecoderSetups {
28+
if v.internalOrDeprecated {
29+
continue
30+
}
2731
cfg.Set(configRoot, make(maps.Params))
2832
}
2933
lang := maps.Params{
@@ -38,7 +42,7 @@ func init() {
3842
configHelpers := map[string]any{
3943
"mergeStrategy": cfg.Get(""),
4044
}
41-
return docshelper.DocProvider{"config": configHelpers}
45+
return docshelper.DocProvider{"config_helpers": configHelpers}
4246
}
4347

4448
docshelper.AddDocProviderFunc(docsProvider)

config/security/docshelper.go

-26
This file was deleted.

docs/content/en/getting-started/configuration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ deep
112112

113113
Note that you don't need to be so verbose as in the default setup below; a `_merge` value higher up will be inherited if not set.
114114

115-
{{< code-toggle config="mergeStrategy" skipHeader=true />}}
115+
{{< code-toggle file="hugo" dataKey="config_helpers.mergeStrategy" skipHeader=true />}}
116116

117117
## All configuration settings
118118

docs/content/en/templates/output-formats.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ A [media type] (also known as _MIME type_ and _content type_) is a two-part iden
2020

2121
This is the full set of built-in media types in Hugo:
2222

23-
{{< datatable "media" "types" "type" "suffixes" >}}
23+
{{< datatable "config" "mediaTypes" "_key" "suffixes" >}}
2424

2525
**Note:**
2626

@@ -61,7 +61,7 @@ Given a media type and some additional configuration, you get an **Output Format
6161

6262
This is the full set of Hugo's built-in output formats:
6363

64-
{{< datatable "output" "formats" "name" "mediaType" "path" "baseName" "rel" "protocol" "isPlainText" "isHTML" "noUgly" "permalinkable" >}}
64+
{{< datatable "config" "outputFormats" "name" "mediaType" "path" "baseName" "rel" "protocol" "isPlainText" "isHTML" "noUgly" "permalinkable" >}}
6565

6666
- A page can be output in as many output formats as you want, and you can have an infinite amount of output formats defined **as long as they resolve to a unique path on the file system**. In the above table, the best example of this is `AMP` vs. `HTML`. `AMP` has the value `amp` for `Path` so it doesn't overwrite the `HTML` version; e.g. we can now have both `/index.html` and `/amp/index.html`.
6767
- The `MediaType` must match the `Type` of an already defined media type.

0 commit comments

Comments
 (0)