Skip to content

Commit

Permalink
Add all config to docshelper.json
Browse files Browse the repository at this point in the history
Also consolidate so the mediaTypes and outputFormats are listed once only.

Fixes #11328
  • Loading branch information
bep committed Aug 7, 2023
1 parent d4a6c16 commit 851bf35
Show file tree
Hide file tree
Showing 15 changed files with 784 additions and 531 deletions.
10 changes: 10 additions & 0 deletions commands/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
"github.com/gohugoio/hugo/docshelper"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/hugolib"
"github.com/gohugoio/hugo/parser"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)
Expand Down Expand Up @@ -197,6 +199,14 @@ url: %s
enc := json.NewEncoder(f)
enc.SetIndent("", " ")

configProvider := func() docshelper.DocProvider {
conf := hugolib.DefaultConfig()
conf.CacheDir = "" // The default value does not make sense in the docs.
defaultConfig := parser.LowerCaseCamelJSONMarshaller{Value: conf}
return docshelper.DocProvider{"config": defaultConfig}
}

docshelper.AddDocProviderFunc(configProvider)
if err := enc.Encode(docshelper.GetDocProvider()); err != nil {
return err
}
Expand Down
13 changes: 9 additions & 4 deletions config/allconfig/alldecoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ type decodeConfig struct {
}

type decodeWeight struct {
key string
decode func(decodeWeight, decodeConfig) error
getCompiler func(c *Config) configCompiler
weight int
key string
decode func(decodeWeight, decodeConfig) error
getCompiler func(c *Config) configCompiler
weight int
internalOrDeprecated bool // Hide it from the docs.
}

var allDecoderSetups = map[string]decodeWeight{
Expand Down Expand Up @@ -340,13 +341,15 @@ var allDecoderSetups = map[string]decodeWeight{
p.c.Author = maps.CleanConfigStringMap(p.p.GetStringMap(d.key))
return nil
},
internalOrDeprecated: true,
},
"social": {
key: "social",
decode: func(d decodeWeight, p decodeConfig) error {
p.c.Social = maps.CleanConfigStringMapString(p.p.GetStringMapString(d.key))
return nil
},
internalOrDeprecated: true,
},
"uglyurls": {
key: "uglyurls",
Expand All @@ -362,12 +365,14 @@ var allDecoderSetups = map[string]decodeWeight{
}
return nil
},
internalOrDeprecated: true,
},
"internal": {
key: "internal",
decode: func(d decodeWeight, p decodeConfig) error {
return mapstructure.WeakDecode(p.p.GetStringMap(d.key), &p.c.Internal)
},
internalOrDeprecated: true,
},
}

Expand Down
14 changes: 9 additions & 5 deletions config/docshelper.go → config/allconfig/docshelper.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The Hugo Authors. All rights reserved.
// Copyright 2023 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -11,19 +11,23 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package config
package allconfig

import (
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/docshelper"
)

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

cfg := New()
for _, configRoot := range ConfigRootKeys {
cfg := config.New()
for configRoot, v := range allDecoderSetups {
if v.internalOrDeprecated {
continue
}
cfg.Set(configRoot, make(maps.Params))
}
lang := maps.Params{
Expand All @@ -38,7 +42,7 @@ func init() {
configHelpers := map[string]any{
"mergeStrategy": cfg.Get(""),
}
return docshelper.DocProvider{"config": configHelpers}
return docshelper.DocProvider{"config_helpers": configHelpers}
}

docshelper.AddDocProviderFunc(docsProvider)
Expand Down
26 changes: 0 additions & 26 deletions config/security/docshelper.go

This file was deleted.

2 changes: 1 addition & 1 deletion docs/content/en/getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ deep

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.

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

## All configuration settings

Expand Down
4 changes: 2 additions & 2 deletions docs/content/en/templates/output-formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ A [media type] (also known as _MIME type_ and _content type_) is a two-part iden

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

{{< datatable "media" "types" "type" "suffixes" >}}
{{< datatable "config" "mediaTypes" "_key" "suffixes" >}}

**Note:**

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

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

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

- 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`.
- The `MediaType` must match the `Type` of an already defined media type.
Expand Down
Loading

0 comments on commit 851bf35

Please sign in to comment.