Skip to content

Commit

Permalink
Create a struct with all of Hugo's config options
Browse files Browse the repository at this point in the history
Primary motivation is documentation, but it will also hopefully simplify the code.
  • Loading branch information
bep committed Jan 4, 2023
1 parent e402d91 commit d4f846d
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 7 deletions.
167 changes: 167 additions & 0 deletions config/allconfig/allconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// 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.
// 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 allconfig

import (
"github.com/gohugoio/hugo/cache/filecache"
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/config/privacy"
"github.com/gohugoio/hugo/config/security"
"github.com/gohugoio/hugo/config/services"
"github.com/gohugoio/hugo/markup/markup_config"
"github.com/gohugoio/hugo/minifiers"
"github.com/gohugoio/hugo/modules"
"github.com/gohugoio/hugo/related"
"github.com/gohugoio/hugo/resources/images"
)

/*
ConfigRootKeysSet = map[string]bool{
"build": true,
"caches": true,
"cascade": true,
"frontmatter": true,
"languages": true,
"imaging": true,
"markup": true,
"mediatypes": true,
"menus": true,
"minify": true,
"module": true,
"outputformats": true,
"params": true,
"permalinks": true,
"related": true,
"sitemap": true,
"privacy": true,
"security": true,
"taxonomies": true,
}
*/

// Config holds all configuration options in Hugo.
// TODO(bep) make sure that the keys gets the sensible casing in JSON etc.
type Config struct {
// The build configuration section contains global build-related configuration options.
Build config.Build

// The caches configuration section contains global cache-related configuration options.
Caches map[string]filecache.Config

// The cascade configuration section contains global the top level front matter cascade configuration options.
Cascade []CascadeEntryConfig

// Front matter configuration.
Frontmatter FrontmatterConfig

// Image processing configuration.
Imaging images.ImagingConfig

// Language configuration.
Languages map[string]LanguageConfig

// Markup configuration.
Markup markup_config.Config

// Media type configuration.
MediaTypes map[string]MediaTypeConfig

// Menu configuration.
Menus []MenuConfig

// Minification configuration.
Minify minifiers.MinifyConfig

// Module configuration.
Module modules.Config

// Output format configuration.
Outputformats map[string]OutputFormatConfig

// Params configuration.
Params maps.Params

// Permalink configuration.
Permalinks map[string]string

// Privacy configuration.
Privacy privacy.Config

// Related content configuration.
Related related.Config

// Security configuration.
Security security.Config

// Services configuration.
Services services.Config

// Sitemap configuration.
Sitemap config.Sitemap

// Taxonomy configuration.
Taxonomies map[string]string
}

// TODO(bep) move these.
type CascadeEntryConfig struct {
// A Glob pattern matching the content path below /content.
// Expects Unix-styled slashes. Note that this is the virtual path, so it starts at the mount root.
// The matching supports double-asterisks so you can match for patterns like /blog/*/** to match anything from the third level and
Path string

// A Glob pattern matching the Page’s Kind(s), e.g. “{home,section}”.
Kind string

// A Glob pattern matching the Page’s language, e.g. “{en,sv}”.
Lang string

// A Glob pattern matching the build environment, e.g. “{production,development}”
Environment string
}

type OutputFormatConfig struct {
BaseName string
IsPlainText bool
MediaType string
Protocol string
}

type FrontmatterConfig struct {
Date []string
ExpiryDate []string
LastMod []string
PublishDate []string
}

type LanguageConfig struct {
LanguageDirection string
Title string
Weight int
Params maps.Params
}

type MediaTypeConfig struct {
Suffixes []string
}

type MenuConfig struct {
Identifier string
Name string
Pre string
URL string
Weight int
}
12 changes: 6 additions & 6 deletions minifiers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/tdewolff/minify/v2/xml"
)

var defaultTdewolffConfig = tdewolffConfig{
var defaultTdewolffConfig = TdewolffConfig{
HTML: html.Minifier{
KeepDocumentTags: true,
KeepConditionalComments: true,
Expand All @@ -52,7 +52,7 @@ var defaultTdewolffConfig = tdewolffConfig{
},
}

type tdewolffConfig struct {
type TdewolffConfig struct {
HTML html.Minifier
CSS css.Minifier
JS js.Minifier
Expand All @@ -61,7 +61,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

Expand All @@ -72,14 +72,14 @@ 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(cfg config.Provider) (conf MinifyConfig, err error) {
conf = defaultConfig

// May be set by CLI.
Expand Down
2 changes: 1 addition & 1 deletion minifiers/minifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func New(mediaTypes media.Types, outputFormats output.Formats, cfg config.Provid

// getMinifier returns the appropriate minify.MinifierFunc for the MIME
// type suffix s, given the config c.
func getMinifier(c minifyConfig, s string) minify.Minifier {
func getMinifier(c MinifyConfig, s string) minify.Minifier {
switch {
case s == "css" && !c.DisableCSS:
return &c.Tdewolff.CSS
Expand Down

0 comments on commit d4f846d

Please sign in to comment.