Add all config to docshelper.json

Also consolidate so the mediaTypes and outputFormats are listed once only.

Fixes #11328
This commit is contained in:
Bjørn Erik Pedersen 2023-08-07 10:52:52 +02:00
parent d4a6c16c17
commit 851bf3515e
15 changed files with 1023 additions and 770 deletions

View file

@ -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"
)
@ -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
}

View file

@ -53,6 +53,7 @@ type decodeWeight struct {
decode func(decodeWeight, decodeConfig) error
getCompiler func(c *Config) configCompiler
weight int
internalOrDeprecated bool // Hide it from the docs.
}
var allDecoderSetups = map[string]decodeWeight{
@ -340,6 +341,7 @@ var allDecoderSetups = map[string]decodeWeight{
p.c.Author = maps.CleanConfigStringMap(p.p.GetStringMap(d.key))
return nil
},
internalOrDeprecated: true,
},
"social": {
key: "social",
@ -347,6 +349,7 @@ var allDecoderSetups = map[string]decodeWeight{
p.c.Social = maps.CleanConfigStringMapString(p.p.GetStringMapString(d.key))
return nil
},
internalOrDeprecated: true,
},
"uglyurls": {
key: "uglyurls",
@ -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,
},
}

View file

@ -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.
@ -11,10 +11,11 @@
// 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"
)
@ -22,8 +23,11 @@ import (
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{
@ -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)

View file

@ -1,26 +0,0 @@
// Copyright 2021 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.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package security
import (
"github.com/gohugoio/hugo/docshelper"
)
func init() {
docsProvider := func() docshelper.DocProvider {
return docshelper.DocProvider{"config": DefaultConfig.ToSecurityMap()}
}
docshelper.AddDocProviderFunc(docsProvider)
}

View file

@ -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

View file

@ -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:**
@ -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.

File diff suppressed because it is too large Load diff

View file

@ -2,13 +2,18 @@
<div class="w-100 ph4 pb5 pb6-ns pt1 mt4 pt3-ns">
<div class="flex-l">
<div class="order-2 w-100 w-20-l ph5-m ph0-l mb4 sticky">
<aside class="fixed-lTK mw5-l right-0 f6 bl-l b--moon-gray pv4 pv0-ns ph4-l nested-list-reset nested-links nested-copy-line-height">
<aside
class="fixed-lTK mw5-l right-0 f6 bl-l b--moon-gray pv4 pv0-ns ph4-l nested-list-reset nested-links nested-copy-line-height">
<p class="b">What's on this Page</p>
<ul>
<li><a href="#last-updated">Last Updated</a></li>
<li><a href="#least-recently-updated">Least Recently Updated</a></li>
<li>
<a href="#least-recently-updated">Least Recently Updated</a>
</li>
<li><a href="#todos">Pages marked with TODO</a></li>
<li><a href="#dependencies">Project dependencies (Hugo Modules)</a></li>
<li>
<a href="#dependencies">Project dependencies (Hugo Modules)</a>
</li>
</ul>
</aside>
</div>
@ -31,6 +36,7 @@
<h2 id="todos">Pages marked with TODO</h2>
{{ partial "maintenance-pages-table.html" (.Scratch.Get "todos") }}
<h2 id="dependencies">Dependencies</h2>
<table class="collapse ba br2 b--black-10 pv2 ph3">
<thead>
@ -47,21 +53,25 @@
{{ range $index, $element := hugo.Deps }}
<tr class="striped--light-gray">
<th class="pv2 ph3">{{ add $index 1 }}</th>
<td class="pv2 ph3">{{ with $element.Owner }}{{.Path }}{{ end }}</td>
<td class="pv2 ph3">
{{ with $element.Owner }}{{ .Path }}{{ end }}
</td>
<td class="pv2 ph3">
{{ $element.Path }}
{{ with $element.Replace }}
=> {{ .Path }}
=>
{{ .Path }}
{{ end }}
</td>
<td class="pv2 ph3">{{ $element.Version }}</td>
<td class="pv2 ph3">{{ with $element.Time }}{{ . }}{{ end }}</td>
<td class="pv2 ph3">
{{ with $element.Time }}{{ . }}{{ end }}
</td>
<td class="pv2 ph3">{{ $element.Vendor }}</td>
</tr>
{{ end }}
</tbody>
</table>
</div>
</div>
</div>

View file

@ -12,6 +12,7 @@ Renders syntax-highlighted configuration data in JSON, TOML, and YAML formats.
{{- /* Initialize. */}}
{{- $config := "" }}
{{- $dataKey := "" }}
{{- $copy := true }}
{{- $file := "" }}
{{- $fm := false }}
@ -19,6 +20,7 @@ Renders syntax-highlighted configuration data in JSON, TOML, and YAML formats.
{{- /* Get parameters. */}}
{{- $config = .Get "config" }}
{{- $dataKey = .Get "dataKey" }}
{{- $file = .Get "file" }}
{{- if in (slice "false" false 0) (.Get "copy") }}
{{- $copy = false }}
@ -43,14 +45,18 @@ Renders syntax-highlighted configuration data in JSON, TOML, and YAML formats.
{{- /* Render. */}}
{{- $code := "" }}
{{- with $config }}
{{- if $config }}
{{- $file = $file | default "hugo" }}
{{- $sections := (split . ".") }}
{{- $sections := (split $config ".") }}
{{- $configSection := index $.Site.Data.docs.config $sections }}
{{- $code = dict $sections $configSection }}
{{- if $skipHeader }}
{{- $code = $configSection }}
{{- end }}
{{- else if $dataKey }}
{{- $file = $file | default $dataKey }}
{{- $sections := (split $dataKey ".") }}
{{- $code = index $.Site.Data.docs $sections }}
{{- else }}
{{- $code = $.Inner }}
{{- end }}
@ -62,7 +68,9 @@ Renders syntax-highlighted configuration data in JSON, TOML, and YAML formats.
</div>
{{- end }}
{{- range $langs }}
<button data-toggle-tab="{{ . }}" class="tab-button {{ cond (eq . "yaml") "active" "" }} ba san-serif f6 dib lh-solid ph2 pv2">
<button
data-toggle-tab="{{ . }}"
class="tab-button {{ cond (eq . "yaml") "active" "" }} ba san-serif f6 dib lh-solid ph2 pv2">
{{ . }}
</button>
&nbsp;
@ -70,7 +78,9 @@ Renders syntax-highlighted configuration data in JSON, TOML, and YAML formats.
</div>
<div class="tab-content">
{{- range $langs }}
<div data-pane="{{ . }}" class="code-copy-content nt3 tab-pane {{ cond (eq . "yaml") "active" "" }}">
<div
data-pane="{{ . }}"
class="code-copy-content nt3 tab-pane {{ cond (eq . "yaml") "active" "" }}">
{{- $hCode := $code | transform.Remarshal . }}
{{- if and $fm (in (slice "toml" "yaml") .) }}
{{- $hCode = printf "%s\n%s\n%s" $placeHolder $hCode $placeHolder }}
@ -79,7 +89,11 @@ Renders syntax-highlighted configuration data in JSON, TOML, and YAML formats.
{{ highlight $hCode . "" | replaceRE $placeHolder (index $delimiters .) | safeHTML }}
</div>
{{- if $copy }}
<button class="needs-js copy copy-toggle bg-accent-color-dark f6 absolute top-0 right-0 lh-solid hover-bg-primary-color-dark bn white ph3 pv2" title="Copy this code to your clipboard." data-clipboard-action="copy" aria-label="copy button"></button>
<button
class="needs-js copy copy-toggle bg-accent-color-dark f6 absolute top-0 right-0 lh-solid hover-bg-primary-color-dark bn white ph3 pv2"
title="Copy this code to your clipboard."
data-clipboard-action="copy"
aria-label="copy button"></button>
{{- /* Functionality located within filesaver.js The copy here is located in the css with .copy class so it can be replaced with JS on success */}}
{{- end }}
{{- end }}

View file

@ -3,19 +3,30 @@
{{ $list := (index (index .Site.Data.docs $package) $listname) }}
{{ $fields := after 2 .Params }}
<table class="table table-bordered">
<tr>
{{ range $fields }}
<th>{{ . }}</th>
{{ $s := . }}
{{ if eq $s "_key" }}
{{ $s = "Type" }}
{{ end }}
<th>{{ $s }}</th>
{{ end }}
</tr>
{{ range $list }}
{{ range $k1, $v1 := $list }}
<tr>
{{ range $k, $v := . }}
{{ $.Scratch.Set $k $v }}
{{ range $k2, $v2 := . }}
{{ $.Scratch.Set $k2 $v2 }}
{{ end }}
{{ range $fields }}
<td>{{ $.Scratch.Get . }}</td>
{{ $s := "" }}
{{ if eq . "_key" }}
{{ $s = $k1 }}
{{ else }}
{{ $s = $.Scratch.Get . }}
{{ end }}
<td>{{ $s }}</td>
{{ end }}
</tr>
{{ end }}

View file

@ -15,9 +15,11 @@
// is of limited interest for the general Hugo user.
package docshelper
import "fmt"
type (
DocProviderFunc = func() DocProvider
DocProvider map[string]map[string]any
DocProvider map[string]any
)
var docProviderFuncs []DocProviderFunc
@ -32,20 +34,14 @@ func GetDocProvider() DocProvider {
for _, fn := range docProviderFuncs {
p := fn()
for k, v := range p {
if prev, found := provider[k]; !found {
provider[k] = v
} else {
merge(prev, v)
if _, found := provider[k]; found {
// We use to merge config, but not anymore.
// These constructs will eventually go away, so just make it simple.
panic(fmt.Sprintf("Duplicate doc provider key: %q", k))
}
provider[k] = v
}
}
return provider
}
// Shallow merge
func merge(dst, src map[string]any) {
for k, v := range src {
dst[k] = v
}
}

View file

@ -16,12 +16,10 @@ package markup_config
import (
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/docshelper"
"github.com/gohugoio/hugo/markup/asciidocext/asciidocext_config"
"github.com/gohugoio/hugo/markup/goldmark/goldmark_config"
"github.com/gohugoio/hugo/markup/highlight"
"github.com/gohugoio/hugo/markup/tableofcontents"
"github.com/gohugoio/hugo/parser"
"github.com/mitchellh/mapstructure"
)
@ -108,10 +106,3 @@ var Default = Config{
Goldmark: goldmark_config.Default,
AsciidocExt: asciidocext_config.Default,
}
func init() {
docsProvider := func() docshelper.DocProvider {
return docshelper.DocProvider{"config": map[string]any{"markup": parser.LowerCaseCamelJSONMarshaller{Value: Default}}}
}
docshelper.AddDocProviderFunc(docsProvider)
}

View file

@ -1,13 +0,0 @@
package media
import (
"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 {
return docshelper.DocProvider{"media": map[string]any{"types": DefaultTypes}}
}
docshelper.AddDocProviderFunc(docsProvider)
}

View file

@ -15,8 +15,6 @@ package minifiers
import (
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/docshelper"
"github.com/gohugoio/hugo/parser"
"github.com/spf13/cast"
"github.com/mitchellh/mapstructure"
@ -113,10 +111,3 @@ func DecodeConfig(v any) (conf MinifyConfig, err error) {
return
}
func init() {
docsProvider := func() docshelper.DocProvider {
return docshelper.DocProvider{"config": map[string]any{"minify": parser.LowerCaseCamelJSONMarshaller{Value: defaultConfig}}}
}
docshelper.AddDocProviderFunc(docsProvider)
}

View file

@ -14,7 +14,6 @@ func init() {
docsProvider := func() docshelper.DocProvider {
return docshelper.DocProvider{
"output": map[string]any{
"formats": DefaultFormats,
"layouts": createLayoutExamples(),
},
}