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 5, 2023
1 parent e402d91 commit 06a02ce
Show file tree
Hide file tree
Showing 12 changed files with 466 additions and 244 deletions.
170 changes: 170 additions & 0 deletions config/allconfig/allconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
// 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 contains the full configuration for Hugo.
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) root options.
}

// 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
}
5 changes: 5 additions & 0 deletions foo/foo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package foo

func Foo() []string {
return []string{"foo", "bar"}
}
6 changes: 4 additions & 2 deletions hugolib/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ import (
"github.com/gohugoio/hugo/common/htime"
"github.com/gohugoio/hugo/common/hugio"
"github.com/gohugoio/hugo/common/types"
"github.com/gohugoio/hugo/media/mediaconfig"
"github.com/gohugoio/hugo/modules"
"github.com/gohugoio/hugo/output/outputconfig"
"golang.org/x/text/unicode/norm"

"github.com/gohugoio/hugo/common/paths"
Expand Down Expand Up @@ -450,12 +452,12 @@ But this also means that your site configuration may not do what you expect. If
}
}

siteMediaTypesConfig, err = media.DecodeTypes(mediaTypesConfig...)
siteMediaTypesConfig, err = mediaconfig.DecodeTypes(mediaTypesConfig...)
if err != nil {
return nil, err
}

siteOutputFormatsConfig, err = output.DecodeFormats(siteMediaTypesConfig, outputFormatsConfig...)
siteOutputFormatsConfig, err = outputconfig.DecodeFormats(siteMediaTypesConfig, outputFormatsConfig...)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 06a02ce

Please sign in to comment.